Skip to content

How to install WordPress with LEMP on Ubuntu 22.04

WordPress is a popular content management system that can be installed on a LEMP stack, which consists of Linux, Nginx, MySQL, and PHP.

This article will guide you through the process of installing WordPress with LEMP on Ubuntu 22.04, providing step-by-step instructions for setting up the necessary components and configuring them to work together seamlessly.

ou will learn how to install and configure Nginx as the web server, MySQL as the database management system, and PHP for server-side scripting. Additionally, you will be guided through the process of downloading and setting up WordPress, enabling you to create a dynamic and responsive website on your Ubuntu 22.04 server. Whether you are a beginner or an experienced user, this article will help you navigate the installation process with ease, empowering you to harness the full potential of WordPress on your LEMP stack.


Prerequisites

Before you start, make sure you have:

  1. An Ubuntu 22.04 server with root access.
  2. A domain configured with DNS properly set.
  3. Certbot installed to configure SSL (optional, but recommended).

Step 1: Update the system

Run the following commands to update the system and make sure all packages are updated:

sudo apt update
sudo apt upgrade

Step 2: Install Nginx

Install Nginx with the command:

sudo apt install nginx

After installation, start and enable Nginx to start on startup:

sudo systemctl enable nginx

Step 3: Install MySQL

Install MySQL server:

sudo apt install mysql-server

After installation, run the security command:

sudo mysql_secure_installation

Follow the instructions to configure the security of your MySQL server.

Step 4: Create a Database for WordPress

Access the MySQL prompt:

sudo mysql

Then create a database and a user for WordPress:

CREATE DATABASE wordpress_db;
CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'una_password_sicura';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 5: Install PHP

Install PHP and the necessary extensions:

sudo apt install php-fpm php-mysql php-cli php-curl php-gd php-xml php-mbstring

Step 6: Configure Nginx for WordPress

Create a configuration file for your WordPress site:

sudo nano /etc/nginx/sites-available/miosito.com

Add the following configuration, replacing “miosito.com” with your domain:

server {
    listen 80;
    server_name miosito.com www.miosito.com;
    root /var/www/miosito.com;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

Activate the site and restart Nginx:Ezoic

sudo ln -s /etc/nginx/sites-available/linuxguidehq.com/etc/nginx/sites-enabled/
sudo systemctl restart nginx

Step 7: Install WordPress

Download and install WordPress:

cd /tmp
wget https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
sudo mv wordpress /var/www/linuxguidehq.com

Assign the correct owner to the files:

sudo chown -R www-data:www-data /var/www/linuxguidehq.com

Step 8: Configure WordPress

Copy the WordPress configuration file:

cd /var/www/linuxguidehq.com
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php

Edit the file to enter the details of your database:

define('DB_NAME', 'wordpress_db');
define('DB_USER', 'wordpress_user');
define('DB_PASSWORD', 'una_password_sicura');

Save the file and close the editor.

Step 9: Complete the installation via the web interface

Now, open your browser and go to “http://linuxguidehq.com“. Follow the instructions to complete the WordPress installation.

Conclusion

Great job! You’ve successfully set up WordPress with LEMP on Ubuntu 22.04. You’re now ready to begin creating your website, incorporating themes, plugins, and content. Don’t forget to set up an SSL certificate to guarantee a secure connection to your site. Well done!

Last Updated on January 16, 2024 by admin

Share this post on social

Copyright 2022 Linuxguidehq.com. All rights reserved. No part of this website may be reproduced, distributed, or transmitted in any form or by any means, including photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the copyright owner.