Skip to content

Instantly share code, notes, and snippets.

@milon
Created May 25, 2016 05:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save milon/7f617377fa5b51a8362eaaf2a0c0be31 to your computer and use it in GitHub Desktop.
Save milon/7f617377fa5b51a8362eaaf2a0c0be31 to your computer and use it in GitHub Desktop.
Installing LEMP Server on Ubuntu 14.04

LEMP Server on Ubuntu 14.04

For detail look here

Install nginx

sudo apt-get install nginx

then get IP address and try it on browser

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

Install mysql

sudo apt-get install mysql-server mysql-client

then create mysql directory structure

sudo mysql_install_db

Install PHP

sudo apt-get install php5-fpm php5-mysql

then configure php processor by editing /etc/php5/fpm/php.ini file with changing the value of cgi pathinfo like this-

cgi.fix_pathinfo=0

then restart php

sudo service php5-fpm php5-cli restart

Configure nginx for using PHP

edit /etc/nginx/sites-available/default file like this-

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

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

    server_name server_domain_name_or_IP;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

then restart nginx

sudo service nginx restart

after that test php by creating a file named /usr/share/nginx/html/index.php and edit it like this-

<?php

phpinfo();

and then show in browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment