User Tools

Site Tools


ubuntu:nginx:install_nginx_with_php_and_mysql_support

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
ubuntu:nginx:install_nginx_with_php_and_mysql_support [2019/12/05 00:43] – created peterubuntu:nginx:install_nginx_with_php_and_mysql_support [2020/07/15 09:30] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Ubuntu - nginx - Install Nginx with PHP and MySql support ====== ====== 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 =====
 +
 +<code bash>
 +sudo apt install mysql-server
 +</code>
 +
 +----
 +
 +===== Install Nginx and PHP =====
 +
 +Install Nginx and PHP related packages including PHP-FPM (FastCGI Process Manager).
 +
 +<code bash>
 +sudo apt install nginx php5-fpm php5-mysql
 +</code>
 +
 +----
 +
 +===== 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):
 +
 +<file bash /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;
 +}
 +</file>
 +
 +----
 +
 +===== 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:
 +
 +<file bash /etc/php5/fpm/php.ini>
 + ;cgi.fix_pathinfo=1
 +</file>
 + 
 +so that it looks like this:
 + 
 +<file bash /etc/php5/fpm/php.ini>
 +cgi.fix_pathinfo=0
 +</file>
 +
 +----
 +
 +===== Restart FPM =====
 +
 +<code bash>
 +/etc/init.d/php5-fpm restart
 +</code>
 +
 +----
 +
 +===== Start Nginx =====
 +
 +<code bash>
 +/etc/init.d/nginx start
 +</code>
 +
 +----
 +
 +===== Create a test PHP file =====
 +
 +Create a test PHP file in the Nginx document root, located in /usr/share/nginx/www by default.
 +
 +<code bash>
 +echo "<?php phpinfo(); ?>" > /usr/share/nginx/www/info.php
 +</code>
 +
 +----
 +
 +===== Test =====
 +
 +Check if Nginx and FPM are configured correctly by loading this url:
 +
 +<code>
 +http://{server}/info.php
 +</code>
 +
 +<WRAP info>
 +Replace {server} with the hostname or IP address of your server.
 +</WRAP>
 +
 +
 +If you see a PHP a list of PHP configurations everything is correctly configured.
  
ubuntu/nginx/install_nginx_with_php_and_mysql_support.1575506598.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki