FedoraRHEL Based

How To Install LEMP Stack on Fedora 39

Install LEMP Stack on Fedora 39

In this tutorial, we will show you how to install LEMP Stack on Fedora 39. The LEMP Stack is a powerful combination of open-source software that provides a solid foundation for hosting web applications. Consisting of Linux, Nginx, MySQL, and PHP, the LEMP Stack is widely used for its performance, reliability, and flexibility.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the LEMP Stack on a Fedora 39.

Prerequisites

Before diving into the installation process, let’s ensure that you have everything you need:

  • A server running one of the following operating systems: Fedora 39.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • You will need access to the terminal to execute commands. Fedora 39 provides the Terminal application for this purpose. It can be found in your Applications menu.
  • You’ll need an active internet connection to download Nginx, MySQL, PHP, and its dependencies.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install LEMP Stack on Fedora 39

Step 1. Start by updating your system’s package list. Open your terminal and type the following command:

sudo dnf clean all
sudo dnf update

Step 2. Installing Nginx.

Nginx, the ‘E’ in LEMP, is a high-performance HTTP server and reverse proxy. It is renowned for its stability, rich feature set, simple configuration, and low resource consumption. To install Nginx on Fedora 39, open your terminal and type the following command:

sudo dnf install nginx

After the installation, start the Nginx service with the following command:

sudo systemctl start nginx
sudo systemctl enable nginx

The main configuration file for Nginx is located at /etc/nginx/nginx.conf. You can edit this file using a text editor of your choice. After making changes, validate the configuration and restart the Nginx service:

Step 3. Installing MySQL.

MySQL, the ‘M’ in LEMP, is a widely used, open-source relational database management system. It is an essential component for many web applications as it allows them to store and retrieve data. To install MySQL, use the following command:

sudo dnf install mysql-server

After the installation, start the MySQL service with:

sudo systemctl start mysqld
sudo systemctl enable mysqld

To secure your MySQL installation, run the security script that comes with the package:

sudo mysql_secure_installation

This script will guide you through the process of setting a root password and removing insecure default settings.

Step 4. Installing PHP.

PHP, the ‘P’ in LEMP, is a popular open-source scripting language suited for web development. It is embedded into HTML and is particularly suited to server-side web development. To install PHP and its necessary modules, use the following command:

sudo dnf install php php-mysqlnd php-fpm

After the installation, start the PHP-FPM service with:

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

The main configuration file for PHP is located at /etc/php.ini. You can edit this file to suit your needs. After making changes, restart the PHP-FPM service:

sudo systemctl restart php-fpm

Update the Nginx configuration file to process PHP files. Open the file with a text editor:

sudo nano /etc/nginx/conf.d/default.conf

Add the following location block inside the “server” block:

location ~ \.php$ {
    fastcgi_pass unix:/run/php-fpm/www.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

Save and exit the text editor, then reload Nginx to apply the changes:

sudo systemctl reload nginx

Step 5. Configure Firewall.

If Firewalld is not already installed on your Fedora 39 system, you can install it using the following command:

sudo dnf install firewalld

Once installed, you can start the Firewalld service with the following command:

sudo systemctl start firewalld
sudo systemctl enable firewalld

Now that Firewalld is installed and running, you need to configure it to allow traffic to the services in your LEMP stack:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https

After adding the necessary services, you need to reload the Firewalld configuration to apply the changes. You can do this with the following command:

sudo firewall-cmd --reload

You can verify that the services have been added correctly with the following command:

sudo firewall-cmd --list-services

Step 6. Testing the LEMP Stack.

After installing all components of the LEMP Stack, it’s crucial to test whether everything works together. Create a simple PHP file in the web root directory:

echo "<?php phpinfo(); ?>" | sudo tee /usr/share/nginx/html/info.php

Access this file in a web browser by navigating to http://your_server_ip/info.php. If the PHP information page displays, your LEMP Stack is working correctly.

Step 7. Set up HTTPS using Let’s Encrypt.

Certbot is a free, open-source software tool for automatically using Let’s Encrypt certificates on manually administrated websites to enable HTTPS. To install Certbot and the Nginx plugin, use the following commands:

sudo dnf install certbot python3-certbot-nginx

Before you run the certbot command to obtain the certificate, make sure your Nginx configuration file for your website is correctly set with the server_name directive:

server_name example.com www.example.com;

Replace ‘example.com‘ and ‘www.example.com with your domain name. Now, you can run the following command to get the SSL certificate:

sudo certbot --nginx -d example.com -d www.example.com

Let’s Encrypt’s certificates are only valid for ninety days. This is to encourage users to automate their certificate renewal process. The Certbot package we installed takes care of this for us by adding a renew script to /etc/cron.d. This script runs twice a day and will automatically renew any certificate that’s within thirty days of expiration. To test the renewal process, you can do a dry run with certbot:

sudo certbot renew --dry-run

Congratulations! You have successfully installed LEMP. Thanks for using this tutorial for installing the LEMP Stack on your Fedora 39 system. For additional or useful information, we recommend you check the official LEMP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button