LEMP stack is a popular set of open-source software that is used to serve dynamic websites and applications. LEMP stands for Linux, Nginx (pronounced "Engine-X"), MariaDB, and PHP. In this guide, we will walk you through how to install and configure the LEMP stack with PHP Opcache, Redis, and secure your server using Let's Encrypt SSL on Fedora 32. Whether you're hosting your server on a Windows VPS UK or another cloud service, this guide will help you set up a powerful web server.
Prerequisites
Before starting, ensure you have the following:
- A Fedora 32 server, which could be hosted on a UK Windows VPS, Windows Virtual Private Servers, or another Windows VPS Hosting UK solution.
- Root or sudo privileges on your server.
- A domain name pointed to your server’s IP address.
Step 1: Update Your System
First, make sure your system is up to date. Run the following commands:
sudo dnf update -y
Step 2: Install Nginx
Nginx will serve as the web server for your LEMP stack. Install Nginx with the following command:
sudo dnf install nginx -y
Once installed, start Nginx and enable it to start on boot:
sudo systemctl start nginx
sudo systemctl enable nginx
Step 3: Install PHP and PHP Extensions
Next, install PHP along with necessary extensions, including Opcache for improved performance:
sudo dnf install php php-fpm php-mysqlnd php-opcache php-xml php-mbstring php-zip php-json php-curl -y
Configure PHP-FPM by editing the following file:
sudo nano /etc/php-fpm.d/www.conf
Find the line that starts with user =
and group =
and change it to:
user = nginx
group = nginx
Save the file and restart PHP-FPM:
sudo systemctl restart php-fpm
sudo systemctl enable php-fpm
Step 4: Install MariaDB
MariaDB is a powerful open-source database management system that will store your website's data. Install MariaDB by running:
sudo dnf install mariadb-server -y
Once installed, start and enable MariaDB:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Secure the MariaDB installation by running the security script:
sudo mysql_secure_installation
Follow the on-screen instructions to set a root password and secure your database server.
Step 5: Install Redis
Redis is a powerful in-memory key-value store that can be used to speed up your web applications. Install Redis with the following command:
sudo dnf install redis -y
Start and enable Redis:
sudo systemctl start redis
sudo systemctl enable redis
To integrate Redis with PHP, install the Redis PHP extension:
sudo dnf install php-redis -y
Step 6: Configure Nginx for PHP
Create a new Nginx server block to host your website. For example, create a configuration file for your domain:
sudo nano /etc/nginx/conf.d/your-domain.conf
Add the following configuration:
server {
listen 80;
server_name your-domain.com www.your-domain.com;
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_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
Save the file and restart Nginx to apply the changes:
sudo systemctl restart nginx
Step 7: Secure Your Website with Let's Encrypt SSL
To secure your website, you can use Let's Encrypt to obtain a free SSL certificate. First, install Certbot:
sudo dnf install certbot python3-certbot-nginx -y
Next, run the following command to obtain an SSL certificate for your domain:
sudo certbot --nginx -d your-domain.com -d www.your-domain.com
Follow the on-screen instructions to complete the process. Certbot will automatically configure Nginx to use SSL.
Step 8: Test Your LEMP Stack
To test if everything is working, create a simple PHP file in the /var/www/html
directory:
sudo nano /var/www/html/info.php
Add the following content to the file:
<?php phpinfo(); ?>
Save the file and navigate to http://your-domain.com/info.php
in your web browser. You should see the PHP information page, which indicates that PHP is working correctly with Nginx.
Conclusion
By following these steps, you have successfully installed the LEMP stack with PHP Opcache, Redis, and Let's Encrypt SSL on Fedora 32. Whether you are hosting your website on a Windows VPS UK, Windows VPS Italy, or another Windows Virtual Private Server Hosting, this setup will help you create a fast and secure web application.