These are the steps to install WordPress on Ubuntu 24.04, using Nginx, MariaDB and PHP
Step 1: Update the system
Before starting, it is advisable to update the system packages.
sudo apt update && sudo apt upgrade -y
Step 2: Install Nginx
Install the Nginx web server.
sudo apt install nginx -y
Enable and check the status of the service:
sudo systemctl enable nginx
sudo systemctl start nginx
sudo systemctl status nginx
To test that it works, open a browser and go to http://server-ip/. You should see the Nginx welcome page.
Step 3: Install MariaDB (MySQL)
WordPress needs a database, so we installed MariaDB.
sudo apt install mariadb-server mariadb-client -y
Start the service and enable it:
sudo systemctl enable mariadb
sudo systemctl start mariadb
To improve security, we implemented:
sudo mysql_secure_installation
Recommended options:
- Set the MariaDB root password.
- Remove anonymous users.
- Disable remote root access.
- Delete the test database.
- Reload privileges.
Step 4: Create the WordPress user and database
Access MariaDB:
sudo mysql -u root -p
Create the database:
CREATE DATABASE wordpress;
Create user and give it permissions:
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 5: Install PHP and required extensions
WordPress needs PHP, so we install it along with its extensions:
sudo apt install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip php-json -y
Verify version:
php -v
Step 6: Download and install WordPress
Move to the Nginx directory and download WordPress:
cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
Extract the file:
sudo tar -xvzf latest.tar.gz
sudo rm latest.tar.gz
Change permissions:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
Step 7: Set up Nginx for WordPress
Create a new configuration file:
sudo nano /etc/nginx/sites-available/wordpress
Paste the following content:
server {
listen 80;
server_name davidalvarezp.com www.davidalvarezp.com;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
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;
}
}
Save and close the file (CTRL + X, then Y and ENTER).
Create a symbolic link to enable the site:
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
Verify the Nginx configuration:
sudo nginx -t
Restart Nginx:
sudo systemctl restart nginx
Step 8: Set up WordPress
Rename the WordPress configuration file:
cd /var/www/html
sudo cp wp-config-sample.php wp-config.php
Edit the file:
sudo nano wp-config.php
Look for the following lines and replace them with the data from the database:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'secure_password');
define('DB_HOST', 'localhost');
Save (CTRL + X, Y, ENTER).
Step 9: Complete the installation
Follow the setup wizard.
Set the site title, admin user and password.
Finish the installation and access the administration panel.
Step 10: Set up HTTPS (Optional)
If you have a domain, you can install Let's Encrypt to enable HTTPS:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d davidalvarezp.com -d www.davidalvarezp.com
You're done! Replace davidalvarezp.com with your domain. WordPress is now installed on Ubuntu 24.04