
{{ $('Map tags to IDs').item.json.title }}
Deploying WordPress on a LEMP Stack
WordPress is a popular content management system (CMS) that powers millions of websites worldwide. In this tutorial, we will guide you through the process of deploying WordPress on a LEMP stack, which consists of Linux, Nginx, MySQL, and PHP.
Prerequisites
- A server running a Linux distribution (e.g., Ubuntu).
- Root or sudo privileges on the server.
- Basic knowledge of using the command line.
1. Installing the LEMP Stack
First, let’s install Nginx, MySQL, and PHP along with the necessary PHP extensions.
1.1. Install Nginx
Update your package index and install Nginx:
sudo apt update
sudo apt install nginx -y
1.2. Install MySQL
Install MySQL server:
sudo apt install mysql-server -y
1.3. Secure MySQL Installation
Run the security script to set the root password and secure your installation:
sudo mysql_secure_installation
Follow the prompts to enhance security.
1.4. Install PHP
Install PHP along with the required extensions for WordPress:
sudo apt install php-fpm php-mysql -y
Optionally, install additional PHP extensions:
sudo apt install php-curl php-mbstring php-xml php-zip -y
2. Configuring Nginx for WordPress
Now, we will configure Nginx to serve WordPress. Create a new configuration file:
sudo nano /etc/nginx/sites-available/wordpress
Add the following server block:
server {
listen 80;
server_name your_domain_or_IP;
root /var/www/wordpress;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ \/favicon\.ico { access_log off; log_not_found off; }
}
Replace your_domain_or_IP
with your domain name or server’s IP address.
To enable the configuration, create a symbolic link to the sites-enabled directory:
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
3. Downloading and Configuring WordPress
Now, let’s download WordPress:
wget https://wordpress.org/latest.tar.gz
Extract the WordPress files:
tar -xvzf latest.tar.gz
Move the extracted files to the document root:
sudo mkdir -p /var/www/wordpress
sudo mv wordpress/* /var/www/wordpress/
Set the correct permissions:
sudo chown -R www-data:www-data /var/www/wordpress
sudo chmod -R 755 /var/www/wordpress
4. Creating the MySQL Database for WordPress
Log in to the MySQL shell:
sudo mysql -u root -p
Create a database and user:
CREATE DATABASE wordpress;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace your_password
with a strong password for the MySQL user.
5. Configuring WordPress
Next, you need to configure WordPress. Rename the sample configuration file:
cd /var/www/wordpress
cp wp-config-sample.php wp-config.php
Edit the configuration file:
sudo nano wp-config.php
Find and update the database configuration section:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost');
6. Completing the Installation
Your web server and WordPress are now configured. Complete the installation by navigating to:
http://your_domain_or_IP
Follow the on-screen instructions to set up your WordPress site, including site title and admin account.
7. Securing Your WordPress Site
To enhance security, consider the following:
- Change the database table prefix in
wp-config.php
. - Install security plugins within WordPress.
- Keep WordPress and all plugins/themes updated.
8. Conclusion
By following this tutorial, you have successfully deployed WordPress on a LEMP stack. This setup allows you to take full advantage of Nginx’s performance and Apache’s flexibility. As you expand your use of WordPress, explore additional plugins and configurations to customize your web experience.