Logo

How To Install WordPress with LEMP on Ubuntu 24.04

Mar 16, 2024

To install WordPress with LEMP on Ubuntu 24.04, follow the steps below:

Step 1 : Install LEMP Stack

If you haven't installed the LEMP stack yet, follow the guide in the article Ubuntu 24.04 Guides.

Step 2 : Create Database

- Log in to MySQL:

sudo mysql

- Create a new MySQL user and database:

CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;

Step 3 : Download and Install WordPress

- Create a directory for your WordPress installation:

mkdir /var/www/html/example.devtutorial.io

- Change directory to the new directory:

cd /var/www/html/example.devtutorial.io

- Download WordPress:

wget https://wordpress.org/latest.tar.gz

- Extract the downloaded file:

tar -xzvf latest.tar.gz

- Move WordPress files to the root directory:

mv wordpress/* .

- Adjust permissions:

sudo chown -R www-data:www-data /var/www/html/example.devtutorial.io

Step 4 : Create a new Nginx server block configuration file:

sudo nano /etc/nginx/sites-available/example.devtutorial.io

- Add the following configuration (replace example.devtutorial.io with your domain):

server {
    listen 80;
    server_name example.devtutorial.io;

    root /var/www/html/example.devtutorial.io;
    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.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    error_log /var/log/nginx/example.com_error.log;
    access_log /var/log/nginx/example.com_access.log;
}

- Save and close the file.

Step 5 : Enable the Nginx server block:

sudo ln -s /etc/nginx/sites-available/example.devtutorial.io /etc/nginx/sites-enabled/

Step 6 : Test the Nginx configuration and restart Nginx:

sudo nginx -t
sudo systemctl restart nginx

Step 7 : Open your browser and navigate to your domain to install WordPress:

- Select your preferred language.

- Click "Let's go!".

- Enter the database information created in Step 2.

- If the information is correct, click "Run the installation".

- Enter WordPress information and click "Install WordPress".

Step 8 : Log in to WordPress.

Step 9 : Access the WordPress dashboard.

Congratulations! You have successfully installed WordPress with LEMP on Ubuntu 24.04.

Recommended