Install LEMP Stack on Ubuntu
Installing a LEMP stack (Linux, Nginx, MySQL, PHP) on Ubuntu 22.04 is a great way to set up a powerful and flexible web server for your web development projects. This stack is widely used for building dynamic websites and web applications, and it is known for its stability, security, and performance.
Here is a step-by-step guide on how to install and set up a LEMP stack on Ubuntu 22.04:
- Start by updating your package list by running the following command in the terminal:
sudo apt update
- Next, install Nginx by running the following command:
sudo apt install nginx
- Once Nginx is installed, you can start the service and enable it to start automatically at boot time by running the following commands:
sudo systemctl start nginx
sudo systemctl enable nginx
- To test that Nginx is running correctly, you can check its status by running the following command:
sudo systemctl status nginx
- Next, we will install MySQL. Run the following command to install the MySQL server package:
sudo apt install mysql-server
- During the installation process, you will be prompted to set a root password for the MySQL server. Be sure to choose a strong password and remember it, as you will need it later to access the server.
- Once the installation is complete, you can check the status of the MySQL service by running the following command:
sudo systemctl status mysql
- To start the MySQL service and enable it to start automatically at boot time, you can run the following commands:
sudo systemctl start mysql sudo systemctl enable mysql
- Next, we will install PHP. Run the following command to install the PHP and PHP-FPM packages:
sudo apt install php php-fpm
- Once PHP is installed, you can configure Nginx to use it by editing the default server block in the Nginx configuration file:
sudo nano /etc/nginx/sites-available/default
- In the server block, change the
index
line toindex index.php
and add the following lines to the end of the block:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
- Save the changes to the configuration file and test the Nginx configuration for errors by running the following command:
sudo nginx -t
- If there are no errors, reload Nginx to apply the changes:
sudo systemctl reload nginx
And that’s it! You have successfully installed and set up a LEMP stack on Ubuntu 22.04. You can now use this stack to build dynamic websites and web applications. Remember to keep your LEMP stack up to date by regularly running the sudo apt update
and sudo apt upgrade
commands.
In this blog post, I’ve explained how to install and set up a LEMP stack (Linux, Nginx, MySQL, PHP) on Ubuntu 22.04. I hope you found this guide helpful, and if you have any questions or issues, feel free to leave