Home Top Ad

How To Install Linux, Nginx, MySQL, PHP on Ubuntu 18.04 (LEMP )

Share:









Introduction





The LEMP software stack is a group of software that can be used to serve dynamic web pages and web applications. This is an acronym that describes a Linux operating system, with an Nginx (pronounced like “Engine-X”) web server. The backend data is stored in the MySQL database and the dynamic processing is handled by PHP





This guide demonstrates how to install a LEMP stack on an Ubuntu 18.04 server. The Ubuntu operating system takes care of the first requirement. We will describe how to get the rest of the components up and running.





Prerequisites





Before you complete this tutorial, you should have a regular, non-root user account on your server with sudo privileges. Set up this account by completing our initial server setup guide for Ubuntu 18.04





Once you have your user available, you are ready to begin the steps outlined in this guide.






Step 1 – Installing the Nginx Web Server





sudo apt update && sudo apt upgrade
sudo apt install nginx -y






Step 2 – Installing MySQL to Manage Site Data 





sudo apt install mysql-server -y
sudo mysql_secure_installation
sudo mysql
SELECT user,authentication_string,plugin,host FROM mysql.user;






ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'PASSWORDHERE';






FLUSH PRIVILEGES;






SELECT user,authentication_string,plugin,host FROM mysql.user;






exit





Step 3 – Installing PHP and Configuring Nginx to Use the PHP Processor





sudo apt install php7.2 php7.2-fpm php7.2-cli php7.2-curl php7.2-mysql php7.2-curl php7.2-gd php7.2-mbstring php-pear -y






sudo sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php/7.2/fpm/php.ini






sudo mkdir -p /var/www/html/YOUR DOMAIN HERE
sudo chown -R $USER:$USER /var/www/html/YOUR DOMAIN HERE
sudo chmod -R 755 /var/www/html/YOUR DOMAIN HERE
chown www-data:www-data /var/www/html/YOUR DOMAIN HERE
sudo nano /etc/nginx/sites-available/YOUR DOMAIN HERE.conf





Copy And Paste Below Code





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





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





sudo rm -f /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/YOUR DOMAIN HERE.conf /etc/nginx/sites-enabled/
sudo systemctl restart php7.2-fpm
sudo nginx -s reload
sudo nginx -t





 Create Php INFO





sudo nano /var/www/html/YOUR DOMAIN HERE/info.php





 Copy And Paste Below Code:-





<?php
phpinfo();





With that, you now have a fully-configured and functioning LEMP stack on your Ubuntu 18.04 server.





http://YOUR DOMAIN HERE_or_IP





FOR YOUR PHP INFO






http://YOUR DOMAIN HERE_or_IP/info.php 






If you see a page that looks like this, you’ve set up PHP processing with Nginx successfully.





After verifying that Nginx renders the page correctly, it’s best to remove the file you created as it can actually give unauthorized users some hints about your configuration that may help them try to break in. You can always regenerate this file if you need it later.





For now, remove the file by typing:





sudo rm /var/www/html/YOUR DOMAIN HERE/info.php





 Install Phpmyadmin for LEMP please click HERE





Run mulitiple website in one VPS please click HERE​​​​​​​