In the earlier post, we learned about how to install PHP installation procedure in Windows, Mac and Linux systems with apache server. In this post, I am going to explain how to install Nginx (Engine X),MySql, PHP (LEMP) server on Ubuntu. Nginx server will suitable for high availability and capable of thousands of requests simultaneously and present days usage of this server is increased as per server statistics. (http://trends.builtwith.com/Web-Server/nginx).

How to install Linux, Nginx, MySql, PHP (LEMP) on Ubuntu by Anil Kumar Panigrahi

How to install Linux, Nginx, MySql, PHP (LEMP) on Ubuntu by Anil Kumar Panigrahi

Installation of Nginx:

Commands:

1
sudo apt-get update
1
sudo apt-get install nginx
1
sudo service nginx start

Installation of MySql:

Commands:

1
sudo apt-get install mysql-server mysql php5-mysql

MySql system tables installation:

1
sudo mysql_install_db

MySql installation secure

1
sudo /usr/bin/mysql_secure_installation

In the next steps sytem prompt for ‘root’ password then provide the root password.

Installation of PHP:

Command:

1
sudo apt-get install php5-fpm

Configuration for PHP

Open a file using below command

1
sudo gedit /etc/php5/fpm/php.ini

Search for cgi.fix_pathinfo=1 replace it with cgi.fix_pathinfo=0

Default port 9000, to change open the file /etc/php5/fpm/pool.d/www.conf
Once change the port then restart PHP

1
sudo service php5-fpm restart

Change the default virtual host file then open the file /etc/nginx/sites-available/default

1
2
3
4
5
6
7
8
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
location ~ .php$ {
  try_files $uri =404;
  fastcgi_pass unix:/var/run/php5-fpm.sock;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
}

From this step we have done the installation.
To effect the above steps then restart the Nginx

1
sudo service nginx restart

Write the simple PHP file

1
2
3
<?php
    echo phpinfo();
?>

Run the PHP file it will display the web server details.

PHP default port : 9000

MySql default port : 3306


3 Comments

How to create virtual hosts in Nginx - Anil Labs · February 19, 2022 at 10:31 am

[…] to create web server i.e. Apache. Now I would like to explain about how to install the web server Nginx and to run the multiple applications in a single system we need to create the virtual hosts. […]

Install Symfony 5 with PHP 7.4 on Ubuntu with Nginx - Anil Labs · July 12, 2022 at 8:01 am

[…] 3: In the previous post I have provided how to install PHP and Nginx, Now go to document […]

Install Xdebug In Ubuntu - Anil Labs · November 1, 2023 at 2:03 pm

[…] features. In this guide, we’ll walk you through the process of installing Xdebug on an Ubuntu 12.04 system. With a series of simple commands, you’ll be equipped to enhance your debugging […]

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *