Optimize Your Server with a LEMP Stack on Rocky Linux 8

This tutorial walks you through optimizing your server by setting up a LEMP (Linux, Nginx, MySQL, PHP) stack on Rocky Linux 8. A LEMP stack offers improved performance and scalability for hosting dynamic websites and applications.

rocky linux Nginx MySQL PHP
Nano
VPS
1
vCPU
1 GB
Memory
10 GB
NVMe Disk
512 GB
Traffic
2.90
/month
* Up to 3GB RAM, 30GB NVMe Disk Space and 1Gbit/s Network Speed
#### Prerequisites Before you begin, ensure you have: - A server running Rocky Linux 8 - SSH access to your server with sudo privileges - Basic familiarity with the command line and package management on Rocky Linux #### Step 1: Install Nginx Install Nginx web server using DNF package manager: ```bash sudo dnf install nginx ``` Start Nginx and enable it to start on boot: ```bash sudo systemctl start nginx sudo systemctl enable nginx ``` #### Step 2: Install MySQL (MariaDB) Install MySQL database server (MariaDB) and secure the installation: ```bash sudo dnf install mariadb-server sudo systemctl start mariadb sudo systemctl enable mariadb sudo mysql_secure_installation ``` Follow the on-screen prompts to secure your MySQL installation. #### Step 3: Install PHP Install PHP and necessary PHP modules for Nginx: ```bash sudo dnf install php-fpm php-mysqlnd php-json php-gd php-mbstring ``` #### Step 4: Configure Nginx for PHP Create a new Nginx server block configuration file for your web application: ```bash sudo nano /etc/nginx/conf.d/your_domain.conf ``` Add the following configuration (replace `your_domain` with your actual domain or IP): ```nginx server { listen 80; server_name your_domain; root /var/www/html; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/run/php-fpm/www.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; } } ``` Save and close the file. Test the Nginx configuration for syntax errors: ```bash sudo nginx -t ``` If no errors are reported, reload Nginx to apply the changes: ```bash sudo systemctl reload nginx ``` #### Step 5: Test PHP Processing Create a PHP info file to test your PHP installation with Nginx: ```bash echo "" | sudo tee /var/www/html/info.php ``` Access the PHP info file in your web browser: ``` http://your-domain/info.php ``` #### Conclusion You have successfully optimized your server with a LEMP stack on Rocky Linux 8. Start deploying and hosting your PHP-based websites and applications with enhanced performance and scalability. **Additional Resources:** - **Nginx Documentation:** [https://nginx.org/en/docs/](https://nginx.org/en/docs/) - **PHP Documentation:** [https://www.php.net/docs.php](https://www.php.net/docs.php) - **Rocky Linux Documentation:** [https://docs.rockylinux.org/](https://docs.rockylinux.org/)

Related Tutorials



    Created with ❤ at Estonia
    EcoStack Technology OÜ