Step by Step Guide How to Install WordPress on Ubuntu 24.04 and Secure MySQL Server


In this detailed guide, we'll walk you through the process of installing WordPress on Ubuntu 24.04 and securing the MySQL server to ensure the safety of your website's data.


Before getting started, ensure you have the following:

  • Ubuntu 24.04 installed
  • SSH access to your server

Installing WordPress

Follow these simple steps to install WordPress on your Ubuntu 24.04 server:

  1. Update System Packages:

    1sudo apt update && sudo apt upgrade
  2. Install LAMP Stack:

    1sudo apt install apache2 mysql-server php php-mysql
  3. Configure MySQL: Secure your MySQL installation:

    1sudo mysql_secure_installation
  4. Create MySQL Database and User for WordPress: Log in to the MySQL shell:

    1mysql -u root -p

    Execute the following SQL commands to create a new database and user:

    1CREATE DATABASE wordpress;
    2CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
    3GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
  5. Download and Configure WordPress:

    1cd /tmp
    2wget -c
    3tar -xzvf latest.tar.gz
    4sudo mv wordpress /var/www/html/
    5sudo chown -R www-data:www-data /var/www/html/wordpress
    6sudo chmod -R 755 /var/www/html/wordpress
  6. Complete WordPress Installation: Open a web browser and navigate to your server's IP address or domain name. Follow the on-screen instructions to complete the WordPress installation.

Securing MySQL Server

Now, let's strengthen the security of your MySQL server:

  1. Update MySQL Root Password:

    1sudo mysql_secure_installation
  2. Remove Anonymous Users: Log in to the MySQL shell:

    1mysql -u root -p

    Execute the following SQL command to remove anonymous users:

    1DELETE FROM mysql.user WHERE User='';
  3. Disallow Root Login Remotely: Edit the MySQL configuration file:

    1sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

    Find the line that says bind-address and change its value to to allow connections only from localhost. Save and close the file, then restart MySQL:

    1sudo systemctl restart mysql
  4. Remove Test Database and Privileges:

    Log in to the MySQL shell:

    1mysql -u root -p

    Execute the following SQL commands to remove the test database and associated privileges:

2  DELETE FROM mysql.db WHERE Db='test' OR Db='test\_%';
4  EXIT;


Congratulations! You've successfully installed WordPress on Ubuntu 24.04 and fortified the security of your MySQL server. Your website is now ready for action, equipped with robust performance and protection against potential security threats.