Reputation: 1365
I am trying to set up Laravel 5.6 + PHP 7.2 (with Instantclient 12.2 and oracle OCI) + Nginx on Ubuntu 18.2. Also, I have installed "yajra/laravel-oci8": "^5.6" for Laravel. To make sure I have instantclient installed correctly, I also tried sqlplus to make sure I can establish connection with the oracle server.
So, I should have everything configured properly and the oracle connector works fine when I serve the page with "php artisan serve --host=192.168.56.12 --port=8000" command.
The test code is as follows:
public function testorcl(){
if (function_exists('oci_connect') == false){
return "oci driver not available";
}
}
At same time, I have Nginx enabled on the default port 80. Both web server are serving the same Laravel code base.
Strangely, Nginx can not find the oci_connect()!!
Then, I check phpinfo() page on both servers.
I found out that the oci8 module is not mounted on Nginx server. But, the "php artisan serve" shows oci8 is mounted. The oci8 module mounted should display something like the following image.
Not only the oci8 module part is different, the environment variables lists are also different. Nginx gives only 4 environment variables shown below while php artisan provides a long list of variables (which is too long to be displayed here in a single page).
So, I think it's the Nginx that causes the problem. Here is my Nginx configuration.
server {
listen 80;
listen [::]:80 ipv6only=on;
# Log files for Debugging
access_log /var/log/nginx/laravel-access.log;
error_log /var/log/nginx/laravel-error.log;
# Webroot Directory for Laravel project
root /home/ub18/test/public;
index index.php index.html index.htm;
# Your Domain Name
#server_name example.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# PHP-FPM Configuration Nginx
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}
# deny access to . files, for security
#
location ~ /\. {
log_not_found off;
deny all;
}
}
The questions are: 1. How to make my OCI work? What did I miss out? 2. How I can make sure Nginx can load the correct environment variables just like "php artisan serve"?
Any suggestions are welcomed, thanks.
Upvotes: 0
Views: 592
Reputation: 408
Seemingly OCI was installed with root user privileges. Installing the OCI with root privilege leaves the oci.so and 20-oci.ini files with the read permissions which the nginx user or group do not have access.
You need to update the file read permission of the OCI's .so file and .ini file that nginx can read those files and load when it processes a request.
It is assumed that your PHP-FPM is running with nginx user, too.
You can check if nginx user can run artisan commands using below command
sudo -u nginx php artisan migrate:status
Check if the OCI module was loaded successfully while running with nginx user.
sudo -u nginx php -m | grep oci
# should output oci<version>
Upvotes: 0