How to install Linux, nginx, MYSQL, PHP (LEMP) stack on Ubuntu 14.04?

The LEMP software stack is a group of software that can be used to serve dynamic web pages and web applications. The LEMP describes a Linux operating system, with an Nginx web server, backend data is stored in MySQL and dynamic processing is handled by Hypertext preprocessor(PHP).

To install LEMP on Ubuntu  to do following steps:

1.Install the Nginx web server:

In order to display web pages on your web browser, we need to employ Nginx. To install nginx use following code in terminal:

>sudo apt-get update

>sudo apt-get install nginx

once it runs successfully then goto your web browser enter like this:

http://server_domain_name_or_IP

it displays default nginx landing page like this:

Nginx default page

If you see the above page, you have successfully installed Nginx.

2.Install MYSQL to manage site data

Mysql can install easily by typing:

sudo apt-get install mysql-server

The mysql database software is installed but its configuration is not completed.we need to generate mysql directory structure it needs to store its database and information.

you can enter like this:

sudo mysql_install_db

Next need to run security script by typing:

sudo mysql_secure_installation

You will need to enter the MySQL root password that you selected during installation.

Next, it will ask if you want to change that password. If you are happy with your MySQL root password, type “N” for no and hit “ENTER”. Afterwards, you will be prompted to remove some test users and databases. You should just hit “ENTER” through these prompts to remove the unsafe default settings.

Once the script has been run, MySQL is ready to go.

3. Install PHP for Processing

To install php by typing:

sudo apt-get install php5-fpm php5-mysql

Configure the php processor by typing:

sudo nano /etc/php5/fpm/php.ini

in this file cgi.fix_pathinfo=1; set as default,you need to change like this

cgi.fix_pathinfo=0; then save and close the file.

After that you need to restart php by typing:

sudo service php5-fpm restart

4. Configure Nginx to Use our PHP Processor

Open the default Nginx server block configuration file by typing:

sudo nano /etc/nginx/sites-available/default

Currently, with the comments removed, the Nginx default server block file looks like this:

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

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

    server_name localhost;

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

The changes that you need to make are in red in the text below:

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;}
}

To do above changes then save and close the file.

After thar need to restart nginx by typing:

sudo service nginx restart

5. Create a PHP File to Test Configuration:

we need to create new file info.php by typing:

sudo nano /usr/share/nginx/html/info.php

on that file we write following code :

<php

phpinfo();

?>

then save and close the file.

After that info.php file will run in your web browser by typing:

http://ipaddress or server domine name/info.php

exapmle: http://localhost/info.php

once generate display like this:

PHP page info

if you see page like this then php installed successfully.

Conclusion:

To follow above steps to install LEMP stack successfully  on Ubuntu 14.04 server.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s