1080*80 ad

Install LEMP (Nginx, MySQL 8, PHP) on Fedora 30/29

Installing a LEMP stack on your Fedora system provides a powerful and flexible platform for hosting dynamic websites and web applications. LEMP stands for Linux, Nginx (pronounced “engine-x”), MySQL or MariaDB, and PHP. This guide will walk you through setting up Nginx, MySQL 8, and PHP on Fedora.

Before starting, it’s good practice to update your system to ensure you have the latest packages. Open your terminal and run the following command:

sudo dnf update -y

Once the update is complete, you are ready to install the LEMP components.

Installing Nginx

Nginx is a high-performance web server. You can install it using the dnf package manager:

sudo dnf install nginx -y

After installation, start the Nginx service and enable it to run automatically at boot time:

sudo systemctl start nginx
sudo systemctl enable nginx

To verify that Nginx is running, check its status:

sudo systemctl status nginx

You should see output indicating the service is active and running. If you have a firewall enabled, you’ll need to allow HTTP and HTTPS traffic:

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

Now, you can open a web browser and navigate to your server’s IP address or domain name. You should see the default Nginx welcome page, confirming that the web server is working correctly.

Installing MySQL 8

MySQL 8 is a popular relational database management system. Install the server package using dnf:

sudo dnf install mysql-server -y

After installation, start the MySQL service and enable it:

sudo systemctl start mysqld
sudo systemctl enable mysqld

Verify the service status:

sudo systemctl status mysqld

The output should show that the mysqld service is active.

To secure your MySQL installation, which is highly recommended, run the security script:

sudo mysqlsecureinstallation

Follow the prompts. You’ll be asked about validating the password component (you can choose to set this up or skip), setting the root password, removing anonymous users, disallowing remote root login, removing the test database, and reloading privilege tables. Answer yes to these security questions to harden your database.

Installing PHP

PHP is the scripting language used to process dynamic content. Install the core PHP package along with necessary extensions for web development and database interaction:

sudo dnf install php php-mysqlnd php-fpm php-cli -y

  • php: The core PHP package.
  • php-mysqlnd: Provides MySQL database support via the improved native driver.
  • php-fpm: (FastCGI Process Manager) This is how Nginx will communicate with PHP.
  • php-cli: Command Line Interface for testing PHP scripts.

After installing PHP and php-fpm, start and enable the php-fpm service:

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

Check its status to confirm it’s running:

sudo systemctl status php-fpm

Configuring Nginx for PHP Processing

By default, Nginx does not know how to process PHP files. You need to configure a virtual host file for Nginx to pass PHP requests to php-fpm.

You can modify the default Nginx configuration file or create a new one. Let’s modify the default server block, located at /etc/nginx/nginx.conf or within the /etc/nginx/conf.d/ directory (often in a file like default.conf).

Open the configuration file using a text editor, for example:

sudo nano /etc/nginx/nginx.conf

Locate the server block. You need to add or uncomment sections that handle PHP files. Look for lines similar to the following within the server block and ensure they are configured correctly:

  • Add index.php to the index directive so Nginx serves it as a default file:
    index index.php index.html index.htm;

  • Uncomment or add a location block to handle .php files and pass them to php-fpm. This block often looks something like this:

    location ~ .php$ {
    ** root /usr/share/nginx/html; # Ensure this points to your webroot**
    ** fastcgipass 127.0.0.1:9000; # This is the default address php-fpm listens on**
    ** fastcgi
    index index.php;**
    ** fastcgiparam SCRIPTFILENAME $documentroot$fastcgiscriptname;**
    ** include fastcgi
    params;**
    }

    Make sure the root directive inside the location block points to the same web root directory defined in your main server block (usually /usr/share/nginx/html on Fedora).

Save the changes to the configuration file.

Before restarting Nginx, check the configuration for syntax errors:

sudo nginx -t

If the test is successful, you should see messages indicating syntax is OK and the test is successful. Now, restart Nginx to apply the changes:

sudo systemctl restart nginx

Testing PHP Processing

To confirm that Nginx is correctly processing PHP files via php-fpm, create a simple PHP info file in your web root directory (usually /usr/share/nginx/html):

sudo nano /usr/share/nginx/html/info.php

Add the following lines to the file:


phpinfo();
?>

Save and close the file.

Now, open your web browser and navigate to your server’s IP address or domain name followed by /info.php (e.g., http://yourserverip/info.php).

You should see the PHP information page, which lists details about your PHP installation, configuration, and loaded modules. This page confirms that Nginx is passing .php files to php-fpm for processing.

For security reasons, it is strongly recommended to delete the info.php file once you have finished testing, as it reveals sensitive information about your server setup:

sudo rm /usr/share/nginx/html/info.php

You now have a fully functional LEMP stack (Nginx, MySQL 8, and PHP) installed on your Fedora system, ready to host your web applications. Remember to implement additional security measures relevant to your specific applications and server environment.

Source: https://kifarunix.com/install-lemp-stack-with-mysql-8-on-fedora-30-fedora-29/

900*80 ad

      1080*80 ad