TECHIES WORLD

For Techs.... Techniques.... Technologies....

AWSLinuxMysqlPHP

How to install Nginx, MySQL, PHP (LEMP) in Ubuntu

This article explains the detailed steps to configure Nginx, MySQL and PHP in Ubuntu server.

Step1: Login to the server via SSH as root.

Step2: Install Nginx.

#apt-get install nginx

Step3: Install MySQL.

#apt-get install mysql-server

Step4: Complete the initial configurations of MySQL.

#mysql_secure_installation

Step5: Install PHP with required modules.

#apt-get install php php-fpm php-mysql

Please note that here we are installing the PHP with minimal modules only more modules might be required according to the environments.

Step6: Create the Nginx virtualhost configuration file.

#vi /etc/nginx/sites-available/domain

Where domain need to be replaced with the name of the domain.

Step7: Update the following lines and save.

server {
    listen 80;
    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;
    server_name domain;

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

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }

    location ~ /\.ht {
            deny all;
    }
}

Where domain need to be replaced with the name of the domain.

Step8: Restart Nginx service.

#systemctl restart nginx

Step9: Restart PHP-FPM service.

#systemctl restart php-fpm

Step10: Put the web pages to the document root and the site can be accessible on browser through domain name.

That's all…