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.
Related
I'm honestly just getting quite frustrated. I feel like I keep fiddling with my nginx conf, and I'll get it working, until I restart my PC or docker. All of the docker functionality seems to be working fine, I can build and docker-compose up without problem, but it seems like every time I restart my computer or docker I have to fiddle with my nginx conf again until it works. I'm using wordpress, and currently have wordpress installed to a subdirectory wp and my wp-content in a different subdirectory at content.
My nginx configuration looks like this:
server {
listen 80;
root /var/www;
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri $uri/index.php /index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
and it was working yesterday while I was working, but after restarting the PC overnight, and trying to work on the site today, I'm getting the standard php-fpm issue FastCGI sent in stderr: "Primary script unknown". I'm just curious if anybody has a solution, or knows why I'm having this issue. I understand that the "Primary script unknown" error usually means that my SCRIPT_FILENAME param is bad, but it was working yesterday, and as far as I can tell should always point to /var/www/index.php, which is where my wordpress index file is.
Should I basically just hardcode $document_root/index.php ?
EDIT: I literally just rebuilt my docker containers with docker-compose build and everything is working as intended. So I guess this question is more associated with docker than nginx/php, but I would still love some guidance. Would there be some reason my docker containers are ephemeral and need rebuilding on boot everytime?
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
I have just installed nginx and php-fpm according to this
http://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/
I am now visiting a php webpage and the php code is not been rendered
<?php echo 'test' ?>
Your problem is related with nginx configuration not php-fpm itself.
Nginx needs to be configured to let him now what to do with each file type. By default it is throwing files as static (the result is the raw content of the file as you report).
An basic example of nginx routing to set php-fpm as fast-cgi service for *.php files would be:
nginx.conf
server {
....
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm/DOMAINNAME.socket;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
Check this basic example: https://support.rackspace.com/how-to/install-nginx-and-php-fpm-running-on-unix-file-sockets/
If you want more advanced examples:
This nginx.conf for Symfony (app.php is the Symfony2 bootstrap file).
https://gist.github.com/leon/3019026
Lumen use case. https://gist.github.com/psgganesh/8d1790dd0c16ab5a4cde
And if you are interested in a deeper learning:
Nginx documentation for Location: http://nginx.org/en/docs/http/ngx_http_core_module.html#location
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!
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