How to install WordPress on Ubuntu 22.04 with LEMP
We show you the detailed manual on how to install WordPress on Ubuntu 22.04 with LEMP:
Step 1: Update the operating system
Before starting to install WordPress, it is important to ensure that the Ubuntu 22.04 operating system is up to date. Open the terminal and run the following commands:
sudo apt-get update
sudo apt-get upgrade
Step 2: Install Nginx
Nginx is a web server that will be used to host the WordPress website. Run the following command to install Nginx:
sudo apt-get install nginx
Once the installation is complete, start the Nginx service with the following command:
sudo systemctl start nginx
Step 3: Install MySQL
MySQL is a database management system that will be used to store the WordPress website data. Run the following command to install MySQL:
sudo apt-get install mysql-server
During the installation, you will be asked to set a password for the MySQL root user.
Once the installation is completed, start the MySQL service with the following command:
sudo systemctl start mysql
Step 4: Install PHP
PHP is a programming language used to execute code on the web server. Run the following command to install PHP and the necessary modules:
sudo apt-get install php-fpm php-mysql
Step 5: Configure Nginx
Now that the necessary components have been installed, it is time to configure Nginx to host the WordPress website. Open the default Nginx configuration file with the following command:
sudo nano /etc/nginx/sites-available/default
Inside the file, look for the section that begins with server { and replace its content with the following:
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.php index.html index.htm;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Remember to replace example.com and www.example.com with your website's domain name.
Save and close the configuration file.
Check and reload the new nginx configuration:
nginx -t
/etc/init.d/nginx reload
Step 6: Create the WordPress database
Create a MySQL database for WordPress with the following command:
mysql -u root -p
You will be asked to enter the password for the MySQL root user. Once you are in the MySQL console, run the following commands:
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
exit;
Remember to replace password with a secure password.
Step 7: Download and install WordPress
Download the latest version of WordPress with the following command:
cd /tmp
wget https://wordpress.org/latest.tar.gz
Decompress the downloaded file with the following command:
tar -zxvf latest.tar.gz
Copy the decompressed WordPress files to the web server's root directory with the following command:
sudo cp -r /tmp/wordpress/* /var/www/html
Change the ownership of the root directory to the www-data user with the following command:
sudo chown -R www-data:www-data /var/www/html
Step 8: Configure WordPress
Open your browser and access the webpage.
Follow the WordPress installation, first selecting the language and, on the next tab, the database details: the database name, user, password, and server.
Throughout the manual, we have used the following data:
Database name: wordpress
User: wordpressuser
Password: password
As the server, you should specify "localhost".
Complete the WordPress configuration details and follow the instructions to set up your website.
success That's it! Now you have WordPress installed on Ubuntu 22.04 with LEMP.