Table of Contents
Ubuntu - nginx - Install Nginx with PHP and MySql support
Instruction how to install and configure Nginx, PHP (with PHP-FPM) and MySql server.
Install MySql server
sudo apt install mysql-server
Install Nginx and PHP
Install Nginx and PHP related packages including PHP-FPM (FastCGI Process Manager).
sudo apt install nginx php5-fpm php5-mysql
Configure Nginx
Configure Nginx to pass .php files to FPM.
Add these lines somewhere in the server {} section (or uncomment as they are already in the file):
- /etc/nginx/sites-enabled/default
location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; }
Configure FPM
Fix a security issue by configuring FPM.
More details here: http://wiki.nginx.org/Pitfalls#Passing_Uncontrolled_Requests_to_PHP)
Uncomment and modify this line:
- /etc/php5/fpm/php.ini
;cgi.fix_pathinfo=1
so that it looks like this:
- /etc/php5/fpm/php.ini
cgi.fix_pathinfo=0
Restart FPM
/etc/init.d/php5-fpm restart
Start Nginx
/etc/init.d/nginx start
Create a test PHP file
Create a test PHP file in the Nginx document root, located in /usr/share/nginx/www by default.
echo "<?php phpinfo(); ?>" > /usr/share/nginx/www/info.php
Test
Check if Nginx and FPM are configured correctly by loading this url:
http://{server}/info.php
Replace {server} with the hostname or IP address of your server.
If you see a PHP a list of PHP configurations everything is correctly configured.