LEMP Stack is a software stack used for web development. It consists of four key software packages: Linux, Nginx, MySQL/MariaDB, and PHP where:
- Linux is an open-source operating system known for stability, security, and flexibility. It serves as the foundation for the LEMP Stack.
- Nginx is known for efficiently managing multiple concurrent connections in web serving.
- MySQL/MariaDB is the database management system used to store and manage website data.
- PHP functions as a server-side scripting language designed for the creation of dynamic web content. It has powerful tools for generating HTML pages, handling forms, interacting with databases, and performing various server-side tasks.
In short, the LEMP Stack offers a robust software stack for web development due to its high performance. Its open-source nature makes it a popular choice among web developers.
This article aims to provide a detailed guide on installing and setting up the LEMP Stack on the Ubuntu 22.04 operating system.
How to Install LEMP Stack on Ubuntu 22.04?
You can set up the LEMP Stack on the Ubuntu 22.04 operating system by following the steps given below.
Step 1: Update System Repository
Update your system repository to retrieve the latest updates about available software packages:
sudo apt update |
---|
Make sure that your Ubuntu packages are up to date.
How to Install Nginx on Ubuntu 22.04?
The below instructions can be performed to install and set up the Nginx on your system.
Step 1: Install Nginx
To install the Nginx package, a high-performance web server, using the APT package manager on your Ubuntu 22.04 system:
sudo apt install nginx -y |
---|
You can examine the output on your terminal window that the package has been installed on your machine.
Step 2: Check Nginx Status
To ensure that Nginx has been successfully installed and is actively running, check its current status using the command:
sudo systemctl status nginx |
---|
If you see the Active status of the Nginx in your terminal, it indicates that the Nginx is functioning actively.
Step 3: Testing Nginx
The command nginx -t, tests the Nginx configuration files for errors without making changes, ensuring the settings are correct before restarting the Nginx service:
sudo nginx -t |
---|
You can also verify the Nginx using the localhost in your web browsers. If you see Welcome to nginx on your web page, it means the package is installed successfully on your Ubuntu 22.04 system:
localhost |
---|
Using the above steps, you have successfully set up the Nginx package on your Ubuntu 22.04.
How to Install MySQL/MariaDB on Ubuntu 22.04?
Setting up MySQL/MariaDB on Ubuntu 22.04 is so simple. Just follow the steps provided below to install the complete package.
Step 1: Install MySQL/MariaDB
To install the MariaDB package on your system, execute the command from your Ubuntu terminal:
sudo apt install mariadb-client mariadb-server -y |
---|
Once you have finished with the installation process, you can configure it and utilize its functionalities.
Step 2: Start MariaDB
Run the systemctl command to start the MariaDB service on your Ubuntu machine:
sudo systemctl start mariadb |
---|
The blank output shows that MariaDB is started without any errors.
Step 3: Enable MariaDB
Use the Enable option with the command to ensure MariaDB starts automatically upon system boot:
sudo systemctl enable mariadb |
---|
Step 4: Check MariaDB’s Status
Verify that MariaDB is actively running without encountering any errors:
sudo systemctl status mariadb |
---|
The Active status displayed on your terminal screen indicates the successful start of the MariaDB database server on your local machine.
Step 5: Install MySQL Secure
To enhance your data security, use the command to configure settings like setting a root password and removing anonymous users. During the MariaDB configuration process, carefully read the instructions to provide appropriate responses:
sudo mysql_secure_installation |
---|
The message Thanks for using MariaDB indicates that the process has finished, and your MariaDB installation is now configured with the security settings.
How to Install PHP on Ubuntu 22.04?
Follow the provided instructions to install PHP on your Ubuntu 22.04 system.
Step 1: Install PHP
Install PHP along with its related libraries and dependencies on your Ubuntu 22.04 to enable a wide range of functionalities:
sudo apt install -y php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath |
---|
The command output confirms the successful installation of the PHP package on your system.
Step 2: Confirm PHP
The command php –version is utilized in the terminal to display the installed PHP version:
php --version |
---|
The currently installed PHP version, like PHP 8.1.2, will be shown on your Ubuntu screen.
Step 3: Check PHP Status
To check if PHP is working correctly, you can check its status using the command:
systemctl status php*-fpm.service |
---|
If the command output displays Active on your screen, it shows that the PHP-FPM service is currently running.
How to Configure PHP on localhost?
In the following few steps, you can configure the PHP on your Localhost.
Step 1: Configure PHP on Localhost
Access the default configuration file using a text editor, such as Nano. This will enable you to edit the configuration settings specifically related to PHP for your local web server setup:
sudo nano /etc/nginx/sites-enabled/default |
---|
Inside the default configuration file, make sure to uncomment the lines of codes:
location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.1-fpm.sock; } |
---|
Step 2: Reload Nginx
Reload the Nginx service to apply the changes made in the Nginx configuration:
sudo systemctl reload nginx |
---|
Step 3: Test PHP
To test the PHP, you need to create a file containing PHP information and save it as ‘index.php’ in a specific location:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/index.php |
---|
Finally, enter localhost into a web browser, followed by /index.php, to access the file and display detailed information about your server’s PHP configuration:
localhost/index.php |
---|
The index.php file is working properly, providing detailed information about the PHP configuration on your Ubuntu 22.04 system.
Conclusion
You can set up the LEMP Stack on your Ubuntu machine through simple commands. LEMP Stack involves installing and configuring Nginx, MariaDB/MySQL, and PHP. By following the aforementioned steps, you have successfully installed and configured each element of the LEMP Stack on Ubuntu 22.04.