Install nginx with PHP-FPM and mysql server 5.5

→ Are you a new visitor? Please visit the page guidance for new visitors ←

Install nginx with PHP-FPM and mysql server 5.5

In my earlier tutorials I showed you how to install PHP-FPM with fastcgi and apache web server on ubuntu or debian operating system. This time I thought of doing a tutorial in a similar manner, but a different web server, with Nginx. As all of you know, Nginx is one of the fastest and scalable web server used on the internet at the moment. Look at Cloudflare’s network how well scaled and big it is, all by using nginx. So yeah, lets just get straight to the point and show you how to install Nginx with PHP-FPM step by step.

Preparing repositories

With PHP-FPM you need to install some repositories, first for PHP extensions and then also for PHP-FPM. I currently use the Doteb repository for Debian and Ubuntu, I’m going to use them this time also, so add the below lines to your /etc/apt/sources.list

Don’t forget the Doteb key for using this repository:

Next don’t forget to update the package list, it is necessary on Debian / Ubuntu:

Install Mysql server 5.5

Mysql server 5.5 is currently the one I’m recommending the most, has been giving good results with my current server configurations. To install mysql server 5.5 run the below command:

You will be asked to enter a root password twice, once completed, you should have mysql server up and running.

Install PHP, PHP extensions and FPM

This is actually what we are interested in, to install PHP and the PHP extensions, run the below commands:

Once we finished to install PHP and all the PHP extensions needed, we can start installing PHP-FPM

Once we’ve completed this step, we proceed with installing the Nginx web server.

Install nginx with php-fpm on Ubuntu / Debian server

I did wrote another article before about how to install nginx web server, so you can either read that article which contains virtual host configuration and more detail explanation, or proceed further with this tutorial:

At this point you should have nginx installed, if you load your IP in your browser, you should see a similar page:

nignx default index

nignx default index

Heads up! Just in case you installed apache web server before or was installed by default, either remove the apache package or stop the service for nginx to use port 80, else you will have port conflict.

Configuring PHP-FPM

This is actually the hard part, I thought of getting the vhost set from scratch, but I saw that nginx by default provide us with one example that’s almost similar to what we need. Anyway, I’ve highlighted the parts you specifically need to make sure are there, the rest are normal Nginx vhost configuration.

Also first you will need to change php-fpm to listen on a TCP ip and port, as I’ve said in my other articles, that’s my default setup, although some of you will use a unix socket instead of this to avoid using too many tcp sockets, but I’ve not yet seen an issue with my setup and have been using it for some time now.

Anyway, open the file:

and edit the part with:

instead of the unix socket. Next will be the Nginx vhost configuration, a default template is below and important parts are highlighted:

If you create a phpinfo() you should see:

PHP Logo 

PHP Version 5.4.20-1~dotdeb.1

 

System Linux debian 3.2.0-4-686-pae #1 SMP Debian 3.2.51-1 i686
Build Date Sep 21 2013 22:37:00
Server API FPM/FastCGI
Virtual Directory Support disabled
Configuration File (php.ini) Path /etc/php5/fpm
Loaded Configuration File /etc/php5/fpm/php.ini
Scan this dir for additional .ini files /etc/php5/fpm/conf.d
Additional .ini files parsed /etc/php5/fpm/conf.d/10-pdo.ini, /etc/php5/fpm/conf.d/20-curl.ini, /etc/php5/fpm/conf.d/20-gd.ini, /etc/php5/fpm/conf.d/20-imagick.ini, /etc/php5/fpm/conf.d/20-imap.ini, /etc/php5/fpm/conf.d/20-intl.ini, /etc/php5/fpm/conf.d/20-mcrypt.ini, /etc/php5/fpm/conf.d/20-memcache.ini, /etc/php5/fpm/conf.d/20-mysql.ini, /etc/php5/fpm/conf.d/20-mysqli.ini, /etc/php5/fpm/conf.d/20-pdo_mysql.ini, /etc/php5/fpm/conf.d/20-pdo_sqlite.ini, /etc/php5/fpm/conf.d/20-pspell.ini, /etc/php5/fpm/conf.d/20-recode.ini, /etc/php5/fpm/conf.d/20-snmp.ini, /etc/php5/fpm/conf.d/20-sqlite3.ini, /etc/php5/fpm/conf.d/20-tidy.ini, /etc/php5/fpm/conf.d/20-xmlrpc.ini, /etc/php5/fpm/conf.d/20-xsl.ini, /etc/php5/fpm/conf.d/ming.ini, /etc/php5/fpm/conf.d/ps.ini
PHP API 20100412

That’s it for now, comment below if you spotted an error and will see you again in our next tutorial.

 

Request an article ←