How To Install WordPress on Ubuntu 24.04
Welcome to the Greenhost.Cloud blog! If you’re looking to create a website that’s easy to manage and packed with features, WordPress is one of the best platforms available. In this guide, we’ll walk you through the step-by-step process of installing WordPress on Ubuntu 24.04. Let’s dive in!
Prerequisites
Before we get started, make sure you’ve got the following prerequisites:
- Ubuntu 24.04: Ensure your server is running Ubuntu 24.04. This tutorial assumes you have a server set up and accessible via SSH.
- Root Privileges: You should have root privileges or the ability to use
sudo
commands. - LAMP Stack: WordPress requires a web server, PHP, and a database. For this guide, we will be using the LAMP (Linux, Apache, MySQL, PHP) stack.
- Domain Name (Optional): If you plan to make your WordPress site accessible via a domain, it’s helpful to have one ready, although it’s not essential for the installation process.
Step 1: Update Your System
First, always start with updating your package list to ensure you have the latest software.
sudo apt update && sudo apt upgrade -y
Step 2: Install Apache Web Server
To install the Apache web server, use the following command:
sudo apt install apache2 -y
After installation, ensure Apache is running by checking its status:
sudo systemctl status apache2
You should see an output indicating that Apache is active and running.
Step 3: Install MySQL
Next, you need to install MySQL, which will be used to store your WordPress data.
sudo apt install mysql-server -y
Once installed, run the MySQL Security Script to enhance security:
sudo mysql_secure_installation
You will be prompted to choose configurations based on your needs. It’s advisable to follow the prompts to set a strong password and remove any test users or databases.
Step 4: Install PHP
Now, let’s install PHP along with the necessary PHP extensions for WordPress.
sudo apt install php php-mysql php-xml php-mbstring php-curl php-zip php-gd -y
To ensure PHP is working, you can create a simple PHP file in the Apache web server’s root directory.
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
You can check your PHP installation by visiting http://your-server-ip/info.php
in your browser. Don’t forget to delete this file once you confirm PHP is working to maintain security.
sudo rm /var/www/html/info.php
Step 5: Create a MySQL Database and User for WordPress
Log into MySQL to create a database and user for WordPress:
sudo mysql -u root -p
Once logged in, run the following commands, replacing wordpressuser
and password
with your own:
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 6: Download WordPress
Now, let’s download the latest version of WordPress:
cd /tmp
wget https://wordpress.org/latest.tar.gz
Extract the downloaded file:
tar -xvzf latest.tar.gz
Next, we will move the WordPress files to the Apache server directory:
sudo mv wordpress/* /var/www/html/
Set the correct permissions:
sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/
Step 7: Configure WordPress
Next, you need to create the WordPress configuration file by copying the sample configuration file:
cd /var/www/html/
sudo cp wp-config-sample.php wp-config.php
Edit the wp-config.php
file using your favorite text editor (like nano or vim):
sudo nano wp-config.php
Update the database details in the configuration file with the database name, user, and password you created earlier:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpressuser');
define('DB_PASSWORD', 'password');
Generate and set the unique authentication keys and salts by visiting the WordPress secret key generator and copying the generated code into your wp-config.php
file.
Step 8: Complete the Installation via Browser
Now it’s time to complete the installation through your web browser. Open a web browser and navigate to:
http://your-server-ip
Follow the on-screen instructions to set up WordPress, such as selecting your language, entering your site title, and creating an admin account.
Step 9: Final Touches
Once the installation is complete, you can log into your new WordPress website at:
http://your-server-ip/wp-admin
Make sure to secure your installation by removing unnecessary theme and plugin files and regularly updating your WordPress, themes, and plugins.
Conclusion
Congratulations! You’ve successfully installed WordPress on Ubuntu 24.04. Now you can begin customizing your site and adding content.
Happy blogging!