Nginx,PHP5-FPM,MySQL on Ubuntu 11.04 LTS+ (LEMP Server)

Make sure you are logged in as root user. If not, append sudo before every command.

-Run apt-get update before proceeding. This is important for not getting any error in below process.

  • Installing MySQL 5

apt-get install mysql-server mysql-client

-Press ‘Y’ on prompt during installation

MySql Password Prompt

-Enter desired password for MySQL “root” user

  • Installing Nginx

apt-get install nginx

-Press ‘Y’ on prompt during installtion

/etc/init.d/nginx start or service nginx start

Now type your server’s IP address or hostname into to a browser and you should see following page -

welcome to nginx

The default document root on Ubuntu 12.04 is /usr/share/nginx/www

apt-get install php5-fpm

  • Configuring Nginx

vi /etc/nginx/sites-available/default

and make changes to your file according to below piece of code.

Do Not Copy Paste This Code To Your File


server {

        listen   80; ## listen for ipv4; this line is default and implied
        listen   [::]:80 default ipv6only=on; ## listen for ipv6

        root /usr/share/nginx/www;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                deny all;

        # Only for nginx-naxsi : process denied requests
        #location /RequestDenied {
                # For example, return an error code
                #return 418;

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/www;

        # pass the PHP scripts to FastCGI server listening on
        location ~ .php$ {
                fastcgi_index index.php;
                include fastcgi_params;

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        location ~ /.ht {
                deny all;


Save the file.

Reload Nginx – /etc/init.d/nginx reload or service nginx reload

Now create a file info.php

vi /usr/share/nginx/www/info.php

and write following code

            <?php       phpinfo();             ?>

Save the file.

Run the file in browser (e.g.

Should look like below image -


You wont see mysql in the above file. Continue to next step .

  • Getting MySql support in PHP

apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Now reload and restart php5-fpm,nginx -

/etc/init.d/php5-fpm reload

/etc/init.d/php5-fpm restart

/etc/init.d/nginx restart

Now reopen info.php in your browser and search for mysql.

In some cases mysql wont appear, just restart nginx and php5-fpm once again.

Now, you have the speed of Nginx Webserver……..!

Further reading – Install phpMyAdmin and Magento .