Introduction
Welcome to this complete tutorial on how to install WordPress with LEMP (Linux, Nginx, MySQL, PHP) on Ubuntu 22.04. WordPress is one of the most popular and versatile content management platforms in the world, and is used by millions of websites. LEMP is a software stack that offers everything you need to run WordPress and other CMS. In this tutorial, we'll walk you through every step of the process, from preparing your server to installing and configuring WordPress.
Prerequisites
Before you begin, make sure you have:
- An Ubuntu 22.04 server with root access.
- A configured domain with correctly set DNS.
- Installed Certbot to configure SSL (optional, but recommended).
Step 1: Update the system
Run the following commands to update your system and ensure 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, launch and enable Nginx to start on boot:
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 WordPress Database
Access the MySQL prompt:
sudo mysql
Then create a database and 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 "mysite.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:
sudo ln -s /etc/nginx/sites-available/miosito.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/miosito.com
Assign the correct owner to the files:
sudo chown -R www-data:www-data /var/www/miosito.com
Step 8: Configure WordPress
Copy the WordPress configuration file:
cd /var/www/miosito.com
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php
Edit the file to insert your database details:
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://mysite.com ". Follow the instructions to complete the WordPress installation.
Conclusion
Congratulations, you have just installed WordPress with LEMP on Ubuntu 22.04! Now you can start building your site, adding themes, plugins and content. Remember to also set up an SSL certification to ensure a secure connection to your site. Good work!