How to install Nginx, PHP and MySQL on Ubuntu using apt-get

Nginx (pronounced “engine x”) is a free, open-source, high-performance HTTP server known for its stability, rich feature set, simple configuration, and low resource consumption.

I do this install several times a month for development servers but someone asked me for the quick version the other day. So here it is in a nutshell, how to install Nginx (nginx version: nginx/1.9.x at time of posting), PHP5 (PHP5-FPM version 5.3 at posting), and MySQL support on Ubuntu 13.04 LTS using apt-get.

This PPA is maintained by the Nginx team.

You can get the latest stable version of Nginx from the Nginx PPA on Launchpad.

You will need to have root privileges to perform the following commands.

Nginx should already be started but if not start it

At this point you should be able to access your servers public IP address and see the default “Welcome to Nginx” (or in my case a 404 page) screen.


Nginx default 404 page

Nginx should start at boot time but if not, run

Install MySQL

If like me, you use a separate MySQL server, you don’t need to install mysql-server. If you install mysql-server, you will be asked for a “root” password for MySQL. Make it secure and write it down for later usage.

Install PHP

Then open /etc/php5/fpm/php.ini and add the line cgi.fix_pathinfo = 1 right at the end of the file:

Sample nginx.conf

Sample etc/nginx/conf.d/default.conf

I would honestly RECOMMEND that you go to the Nginx site for configuration information. This setup is on the development server and temp production servers behind firewalls. Just because this works for me doesn’t mean that it will work for you!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.