Install LEMP in ubuntu 20
To install a LEMP stack (Linux, Nginx, MySQL, PHP) on Ubuntu 20.04, follow these steps:
1. Update your server
First, update your package index:
sudo apt update
sudo apt upgrade
2. Install Nginx
Nginx is a high-performance web server. Install it with:
sudo apt install nginx
Start Nginx and enable it to run at startup:
sudo systemctl start nginx
sudo systemctl enable nginx
You can verify that Nginx is installed and running by visiting your server's IP address in a web browser. You should see the Nginx default welcome page.
3. Install MySQL
MySQL is the database management system. Install it with:
sudo apt install mysql-server
After installation, run the security script to secure your MySQL installation:
sudo mysql_secure_installation
This will prompt you to set a root password and make other security-related changes.
4. Install PHP
PHP is the server-side scripting language. Install PHP and some essential modules:
sudo apt install php-fpm php-mysql
PHP-FPM (FastCGI Process Manager) will handle PHP scripts.
5. Configure Nginx to Use PHP Processor
To serve PHP applications, you'll need to configure Nginx. Open the default server block configuration file:
sudo nano /etc/nginx/sites-available/default
Find the location ~ \.php$ {
block and make sure it looks like this:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Save the file and exit the text editor.
Test the configuration:
sudo nginx -t
If the test is successful, restart Nginx to apply the changes:
sudo systemctl restart nginx
6. Test PHP with Nginx
You can create a PHP file to test if Nginx is correctly processing PHP. Create a file named info.php
in the /var/www/html
directory:
sudo nano /var/www/html/info.php
Add the following content:
<?php
phpinfo();
?>
Save and close the file. Now, go to http://your_server_ip/info.php
in your web browser. You should see the PHP information page.
7. (Optional) Install phpMyAdmin
If you want to manage your databases using a web interface, you can install phpMyAdmin:
sudo apt install phpmyadmin
Follow the prompts to configure phpMyAdmin. You may need to adjust Nginx configurations to access phpMyAdmin.
8. Secure your installation
Make sure to remove the info.php
file once you've confirmed that PHP is working, as it can expose sensitive information about your server:
sudo rm /var/www/html/info.php
That's it! You now have a LEMP stack installed on your Ubuntu 20.04 server.
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Copyright 2023-2025 © All rights reserved.