Introduction:
WordPress is a popular content management system (CMS) used by millions of websites around the world. It provides a user-friendly interface for managing and publishing content. In this article, we will walk you through the process of installing WordPress with LEMP (Linux, Nginx, MySQL, PHP) stack on Ubuntu 22.04. This powerful combination will enable you to create a robust and efficient WordPress website.
Prerequisites:
Before we begin, make sure you have the following requirements:
- A server running Ubuntu 22.04.
- SSH access to the server with root privileges.
- Basic knowledge of the Linux command line.
Step 1: Update System Packages
To start, let’s update the system packages to their latest versions. Open a terminal and run the following commands:
sudo apt update sudo apt upgrade
Step 2: Install Nginx
Nginx is a high-performance web server that will serve as the frontend for our WordPress installation. Install Nginx by running the following command:
sudo apt install nginx
After the installation, start the Nginx service with the following command:
sudo systemctl start nginx
Step 3: Install MySQL
Next, we need to install the MySQL database server to store our WordPress data. Run the following command to install MySQL:
sudo apt install mysql-server
Once the installation is complete, secure the MySQL installation by running the command:
sudo mysql_secure_installation
Follow the prompts to set the root password and improve the security of your MySQL installation.
Step 4: Install PHP and Required Extensions
PHP is the server-side scripting language used by WordPress. We’ll also need some PHP extensions for WordPress to function properly. Run the following command to install PHP and the necessary extensions:
sudo apt install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-zip
Step 5: Configure Nginx to Serve WordPress
Now, let’s configure Nginx to serve our WordPress website. Open the Nginx default configuration file using a text editor:
sudo nano /etc/nginx/sites-available/default
Inside the file, locate the server
block and modify it as follows:
server { listen 80; server_name your_domain_or_IP_address; root /var/www/html; 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/php8.0-fpm.sock; } location ~ /\.ht { deny all; } }
Replace your_domain_or_IP_address
with your server’s domain name or IP address. Save the changes and exit the editor.
Next, test the Nginx configuration for any syntax errors:
sudo nginx -t
If there are no errors, reload the Nginx configuration:
sudo systemctl reload nginx
Step 6: Create a MySQL Database and User
To store WordPress data, we need to create a MySQL database and a dedicated user for it. Access the MySQL command-line interface:
sudo mysql
Create a new database:
CREATE DATABASE wordpress;
Create a new user and grant privileges on the database:
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost'; FLUSH PRIVILEGES; EXIT;
Remember to replace 'your_password'
with a strong password of your choice.
Step 7: Download and Install WordPress
Navigate to the web server’s document root directory:
cd /var/www/html
Download the latest WordPress package using the following command:
sudo wget https://wordpress.org/latest.tar.gz
Extract the downloaded archive:
sudo tar -xvzf latest.tar.gz
Rename the extracted folder to something more appropriate:
sudo mv wordpress your_domain_name
Step 8: Configure WordPress
Now, it’s time to configure WordPress. Create the WordPress configuration file by making a copy of the sample file:
cd your_domain_name sudo cp wp-config-sample.php wp-config.php
Open wp-config.php
in a text editor:
sudo nano wp-config.php
Locate the following lines and update them with the database details you created earlier:
define('DB_NAME', 'wordpress'); define('DB_USER', 'wordpressuser'); define('DB_PASSWORD', 'your_password'); define('DB_HOST', 'localhost');
Save the changes and exit the editor.
Step 9: Complete the WordPress Installation
Open your web browser and navigate to http://your_domain_or_IP_address
. You will be greeted with the WordPress installation page.
Provide the requested information, including the site title, admin username, password, and email. Click on the “Install WordPress” button to finalize the installation.
Conclusion:
Congratulations! You have successfully installed WordPress with the LEMP stack on Ubuntu 22.04. You can now begin customizing your website and adding content. Remember to regularly update WordPress, themes, and plugins for better security and performance. Enjoy building your website with the power and flexibility of WordPress and the performance benefits of the LEMP stack!