These are the steps to install WordPress on Ubuntu 24.04, using Apache, 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 Apache
Install the Apache web server.
sudo apt install apache2 -y
Enable and check the status of the service:
sudo systemctl enable apache2
sudo systemctl start apache2
sudo systemctl status apache2
To test that it works, open a browser and go to http://server-ip/. You should see the Apache 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 php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip php-json libapache2-mod-php -y
Verify version:
php -v
Step 6: Download and install WordPress
Move to the Apache 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 Apache for WordPress
Create a new configuration file:
sudo nano /etc/apache2/sites-available/wordpress.conf
Paste the following content:
ServerAdmin admin@your-domain.com
DocumentRoot /var/www/html
ServerName your-domain.com
ServerAlias www.your-domain.com
AllowOverride All
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Save and close the file (CTRL + X, then Y and ENTER).
Enable the necessary configuration and modules:
sudo a2ensite wordpress
sudo a2enmod rewrite
Restart Apache:
sudo systemctl restart apache2
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-apache -y
sudo certbot --apache -d davidalvarezp.com -d www.davidalvarezp.com
You're done! Replace davidalvarezp.com with your domain. WordPress is now installed on Ubuntu 24.04