webserver process permissions problems on vagrant+nginx+php fpm - php

I have a vagrant box with a LEMP (linux, nginx, mariadb, php) stack for developing a webapp and I am currently having some issues configuring nginx and php-fpm. I am using puppet and puPHPet to provision the VM.
It seems that the combo php-fpm and nginx are unable to write files (ie. log files generated, assets published by the framework (yii2) etc).
This project worked just fine using apache instead of nginx, so I would discard a programming issue and I have been following the guidelines for nginx installation and still getting messages such as "The directory is not writable by the Web process" or "Permission denied" like errors.
As recommended I set /etc/php5/fpm/php.ini the option cgi.fix_pathinfo = 0.
nginx/sites-available/site.conf
server {
listen *:80;
server_name site.dev;
client_max_body_size 128M;
root /var/www/frontend/web;
index index.php;
access_log /var/log/nginx/test.access.log;
error_log /var/log/nginx/test.error.log;
location / {
root /var/www/frontend/web;
try_files $uri $uri/ index.php /index.php$is_args$args;
}
location ~ \.php$ {
root /var/www/frontend/web;
index index.html index.htm index.php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param APP_ENV dev;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
}
sendfile off;
}
php-fpm/www.conf
user = www-data
group = www-data
listen-owner = www-data
listen-group = www-data
listen-mode = 0660
I've seen other posts where listen-mode is commented out, I tried both methods and setting mode to 0666 but still no luck.
I tried also setting permissions from the out and the inside of the vagrant to 0777 over the folders that I know that the framework uses to write data but still no luck.
I have a very similar project at work configured just the same that it works but this one doesn't and I can't find the difference (in fact I took config files from this project to set up the new one after the first failed attempt).
ps aux | grep php
root php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data php-fpm: pool www
www-data php-fpm: pool www
Directories in the different projects seem to have the same permissions number yet onw eorks and the other doesn't.
I'm completely clueless! Ideas are very welcomed!

Related

Errors while setting up nginx and php fpm

I'm trying to install 3 websites on a VPS running centos 6, NGINX, PHP-FPM and WordPress. I followed the instructions shared in this article :https://deliciousbrains.com/hosting-wordpress-yourself-setting-up-sites/ and i created the below configuration file in sites-available directory
server {
server_name 7symptoms.com;
access_log /var/www/html/7symptoms/logs/access.log;
error_log /var/www/html/7symptoms/logs/error.log;
root /var/www/html/7symptoms/public/;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
I tested the files using nginx test command and php-fpm is configured correctly. But when i try to access a simple hello world (hi.php) file on my website 7symptoms.com, i get 502 bad gateway or 404 file not found error. What's the problem with the above code?
You created config in "sites-available", now you should link this fie to "sites-enabled":
cd /etc/nginx/sites-enabled/ #please check that in centos this is correct path
ln -s ../sites-available/website_config_file .
Next look into log files and check, does your request are entering the correct website.
Next, if you are using nginx + php-fpm the error "502" means that php-fpm is not running or you wrote wrong path to socket. Please check that file exists: /var/run/php-fpm.sock and (using htop, top or ps) does php-fpm process is working.
Next - if you want to have 3 different websites, it is more secure to use 3 different user, and 3 different php-fpm config (for each website), it means there will be also 3 different unix sockets created.

Creating your first laravel project on web server

ive recently just follwed this guide and "installed" laravel on my lamp server: https://www.digitalocean.com/community/tutorials/how-to-install-laravel-with-an-nginx-web-server-on-ubuntu-14-04
Now when im finished it says at the bottom of their guide
"You now have Laravel completely installed and ready to go. You can
see the default landing page by visiting your server's domain or IP
address in your web browser:
http://server_domain_or_IP"
When i visit my website there is no new landing page and there is no new files in the var/www/html that would act as a landing page except for the standard apache one.
For me this is fine but i still dont know how to create my first project, i want to do this to check my install is finished and i am ready for bed.
Here is how my www directory looks like at the moment:
And here is my nginx config which i believe plays a part in this whole thing:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/laravel/public;
index index.php index.html index.htm;
server_name www.mysite.me;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
The files are in the /var/www/laravel folder rather than the /var/www/html folder which is visible in the screenshot you provided.
From my own experience when this happens, it is due to having multiple 'default server' attributes in multiple nginx config files for different websites so when looking at the server via the IP it is not selecting your new laravel build.
The server needs to restart for some of the settings to take place.
You can try accessing its console and type
To reboot a server from the command line, run:
sudo shutdown -r now
To restart Apache, run:
sudo service apache2 restart

net::ERR_CONNECTION_REFUSED with Nginx and Laravel 5

I have just installed a fresh copy of Laravel 5 into /var/www.
When I browse to the server I get net::ERR_CONNECTION_REFUSED.
My Nginx config (default) is:
server {
listen 80;
root /var/www/public;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Any idea what I'm doing wrong?
I am also confused about sites-enabled and sites-available. Where should default actually go?
I have moved default from sites-available to sites-enabled and I am now getting a 403 with "Access denied".
You probably got net::ERR_CONNECTION_REFUSED because you hadn't told nginx what port to listen on (note the listen 80 line in your config file), so you were trying to a port that wasn't open - hence the connection refused error.
As for sites-available vs sites-enabled, that's a Debian/Ubuntu thing to make sites easier to manage - you can have many sites configured in sites-available, but only run specific ones by adding a link in sites-enabled pointing at the respective config file in sites-available.
As an example, my sites-enabled folder has
lrwxrwxrwx 1 root root 40 Feb 8 07:53 site.net -> /etc/nginx/sites-available/site.net
No copying, just a link to sites-available.
For your 403 error, look in your error log for what precisely is failing. It should be located at /var/log/nginx/error.log - look for error_log in your main conf file to get the exact location.

Vagrant & Nginx - Name Based Virtual Hosts

I believe I have set up an nginx virtual host file correctly, however, I'm not able to navigate to that URL on the host machine. I have a slight feeling that I'm misunderstanding something here.
Here's the situation.
I have a Vagrantfile that does the following:
Installation of Required Packages
Composer Update
Copies an Nginx Virtual Host file over to Nginx
Restarts all relevant services
Heres the vhost file:
server {
listen 80;
server_name vagrant;
root /usr/share/nginx/www;
index index.html index.htm index.php;
location / {
try_files $uri /index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
I can verify that when the virtual host file was called simply vagrant and the server name was set to the following server_name _; that a page was rendered when I visited localhost.
As I'm trying to set up Magento, which doesn't work well with localhost domains, I'm trying to set up a name based virtual host for it under the domain dev.magento.co.uk
If I ssh into the vagrant installation, I can verify that the dev.magento.co.uk file is in the /etc/nginx/site-enabled directory and that it's contents were copied over correctly.
What am I missing?

nginx + php with drupal + codeigniter in separate folders

I have a Slicehost slice for a dev server, with nginx and PHP.
I'm trying to get drupal running on localhost/drupal and a codeigniter app running on localhost/codeigniter.
I can get one or the other to work, but not both -- the rewrite and fastcgi seem to be interfering with one another.
Does anyone know how to have /drupal and /codeigniter both working, with rewrite rules (for SEF URLs), in separate folders in my /var/www?
Cheers.
Ok, you have to create a file (no extension needed) in /etc/nginx/sites-available that represents the name of your folder/domain (ex: drupal, yoursite.com).
Here's a sample file:
server {
server_name yourdomain.com;
root /var/www/yourdomain;
index index.php;
location / {
autoindex on;
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
In the sample above it will actually send url rewrites to $_SERVER['REQUEST_URI']. For more nginx rewrites, you can take a look at http://wiki.nginx.org/HttpRewriteModule for more reference.
Then you want to enable it by creating a symlink of this file in your /etc/nginx/sites-enabled folder
Example: # ln -s /etc/nginx/sites-available/yoursite /etc/nginx/sites-enabled/yoursite
Then restart/reload nginx
# services nginx reload

Categories