You are on page 1of 4

5/15/2014 How to install Nginx, PHP5 / PHP-FPM, MySQL on Ubuntu 13.

04
http://www.nginxtips.com/nginx-php5-php-fpm-mysql-ubuntu-13-04/ 1/4
Tweet
1
NGINX TIPS
Nginx Tutorials, Sysadmin & Web Performance Tips and Tricks
How to install Nginx, PHP5 / PHP-FPM, MySQL on Ubuntu
13.04
28 January 2014, 9:10 pm
On this tutorial we will go through the installation process of Nginx, PHP with PHP-FPM with MySQL
support on Ubuntu 13.04. Nginx is a fast & high perfromance web server, PHP is the most popular
programming language of the web, and MySQL is the most used database server, that combination
makes what we call LEMP stack (Linux, Nginx, MySQL and PHP).
On this how to, we will configure Nginx to handle the PHP dynamic files to PHP-FPM daemon, which
is a fastcgi backend that will process all the PHP information. On Ubuntu 13.04, PHP-FPM binaries
are available by default, so there is no need to install extra repositories into your system.
Pre requisites
Update apt sources
sudo apt-get update
Install MySQL
sudo apt-get install -y mysql-server mysql-client
When asked, enter the root password try to generate a strong password, you will need it later in
order to use phpmyadmin or the mysql shell console. After that, it is a good practice to run
mysql_secure_installation script to secure your MySQL installation:
5/15/2014 How to install Nginx, PHP5 / PHP-FPM, MySQL on Ubuntu 13.04
http://www.nginxtips.com/nginx-php5-php-fpm-mysql-ubuntu-13-04/ 2/4
mysql_secure_installation
Start mysql server
Installing Nginx
Nginx is part of the default Ubuntu 13.04 repositories, so installing Nginx is a simple task:
sudo apt-get install nginx -y
Install PHP FPM and other common PHP modules
sudo apt-get -y install php5-common php5-fpm php5-mysql php5-curl php5-gd php-pear php5-mcrypt php5-memcache php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
Configure Nginx to serve PHP Files using PHP-FPM
sudo nano /etc/nginx/sites-available/default
There will be a section with the heading starting with # pass the PHP scripts to FastCGI, as you see
below:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ .php$ {
# fastcgi_split_path_info ^(.+.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
5/15/2014 How to install Nginx, PHP5 / PHP-FPM, MySQL on Ubuntu 13.04
http://www.nginxtips.com/nginx-php5-php-fpm-mysql-ubuntu-13-04/ 3/4
# fastcgi_pass unix:/var/run/php5-fpm.sock;
# fastcgi_index index.php;
# include fastcgi_params;
#}
Delete all those lines and paste this:
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
# add the following line in for added security.
try_files $uri =403;
}
Save the file and restart php-fpm
sudo /etc/init.d/php5-fpm restart
Then restart Nginx
sudo service nginx restart
Testing your php-nginx installation
Create a .php file with the following content inside and save it in your website folder and name it
phpinfo.php (/usr/share/nginx/html/phpinfo.php in my server):
<?php
phpinfo();
?>
Open your browser and load that php file using http://your.ip.addr.ess/phpinfo.php or
5/15/2014 How to install Nginx, PHP5 / PHP-FPM, MySQL on Ubuntu 13.04
http://www.nginxtips.com/nginx-php5-php-fpm-mysql-ubuntu-13-04/ 4/4
Tweet
1
http://www.yoursite.com/phpinfo.php. At that time you should have a working Nginx, PHP-FPM with
MYSQL support on Ubuntu 13.04.
Related Posts
How to install MariaDB on CentOS 6
How to Install latest Node.js version on Ubuntu 12.04
How to install OpenResty
How to Install Nginx on Ubuntu 12.04 LTS
How to install PHP 5.5 on CentOS 6 / 5
20 popular NodeJS modules for Nginx
POPULARSEARCHTERMS:
how to start php5 on ubuntu
ubuntu php fpm
ubuntu phpfpm
wnmp nginx ubuntu
Filed under Tutorials & How to's | Comment | Permalink
2013 Nginx Tips

You might also like