Installing NGINX, PHP, and MySQL on Ubuntu 10.04 LTS using php-cgi

Nginx (pronounced Engine-X) is a fast & lightweight HTTP and HTTPS web server (it can also act as a reverse proxy, and perform load balancing).

(Note: this is a updated version of a similar how to located here, but this article is using php-cgi package instead of php-fpm, and using only default Ubuntu repository’s).

Its small memory footprint requirements make it great for systems with small amounts of memory, such as low end cloud servers. Nginx is great for serving static files to users, and is cable of handling more than 10,000 simultaneous connections, but it lacks the embedded module support for PHP as Apache does.

Thankfully you can use the php5-cgi package to add PHP support to Nginx, and end up with a PHP enabled web server running on a low footprint setup. Nginx essentially offloads processing of .php files to the PHP fast cgi package, which in turn passes the interpreted script information back to Nginx, to return back to the end user.

The how to article below describes installing the usual components for the LAMP stack (Linux, Apache, MySQL, and PHP), however the Apache part is exchanged for Nginx.

Make sure the apt sources are up to date before installing:

$ sudo apt-get update

MySQL Configuration

Install MySQL:

$ sudo apt-get install -y mysql-server mysql-client

You will be asked to enter a “root” password for the MySQL server. Generate a strong password, type it in, and keep note of it for future reference.

PHP Configuration

To use PHP with Nginx, you require the PHP5-CGI package. Install PHP with php5-cgi and any other modules that you may require: