In this tutorial, we'll learn how to install and host WordPress website on Ubuntu 24.04 Server.
We understand the importance of having a secure, fast, and reliable website. We will guide you through the process of installing and configuring WordPress on an Ubuntu 24.04 server. Whether you are setting up a new blog, business website, or portfolio, WordPress provides a flexible platform to get your site up and running in no time.
Before we begin, ensure that you have access to your Ubuntu server, either through SSH or directly. You should also have a non-root user with sudo privileges for performing administrative tasks.
Prerequisites
Before proceeding, make sure you have the following in place:
- A Fresh Ubuntu 24.04 dedicated server or KVM VPS.
- Root or Sudo Privileges: You should have sudo privileges to install packages and make system-wide changes.
- A Valid Domain Name (Optional but Recommended)
Install and Host WordPress Website on Ubuntu 24.04
Step 1: Update the System
First, we need to update the system to ensure that we have the latest security patches and software packages. Open your terminal or SSH into your server and run the following command:
sudo apt update && sudo apt upgrade -y
This command updates the list of available packages and installs the latest versions of all installed packages. Once completed, reboot the system to apply any updates:
sudo reboot
Step 2: Install LAMP Stack (Linux, Apache, MySQL, PHP)
WordPress requires a LAMP stack to run: Linux, Apache, MySQL (or MariaDB), and PHP. We will install each of these components on our Ubuntu server.
Install Apache Web Server
Apache is a popular web server that will serve the WordPress files. To install Apache, run the following command:
sudo apt install apache2 -y
Once installed, enable Apache to start automatically on boot:
sudo systemctl enable apache2
sudo systemctl start apache2
Check if Apache is running by accessing your server’s public IP address. Open a browser and enter:
http://<your-server-ip>
If you see the Apache2 Ubuntu Default Page, Apache is working correctly.
Install MySQL
WordPress uses MySQL (or MariaDB) to store its data. To install MySQL, run:
sudo apt install mysql-server -y
Once MySQL is installed, start and enable it:
sudo systemctl enable mysql
sudo systemctl start mysql
Now, secure your MySQL installation:
sudo mysql_secure_installation
Follow the prompts to set up a root password and remove insecure default settings.
Install PHP and Required Extensions
WordPress requires PHP and several PHP extensions to work correctly. Install PHP and the necessary extensions by running:
sudo apt install php php-mysql libapache2-mod-php php-cli php-cgi php-xml php-mbstring php-zip php-curl php-soap -y
Once installed, restart Apache to load the PHP module:
sudo systemctl restart apache2
Step 3: Create a MySQL Database for WordPress
Now that MySQL is installed, we need to create a database for WordPress to use. Start the MySQL command-line interface:
sudo mysql -u root -p
Enter the root password you set earlier, and then create a new database and user for WordPress:
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace 'your_password' with a strong password for the wordpressuser.
Step 4: Download and Install WordPress
Now that the LAMP stack is set up, let’s download WordPress and configure it on our server.
Download WordPress
First, navigate to the /var/www/html
directory, which is the default location for web files on Apache:
cd /var/www/html
Remove the default index.html file:
sudo rm index.html
Next, download the latest version of WordPress:
sudo wget https://wordpress.org/latest.tar.gz
Extract the WordPress archive:
sudo tar -xvzf latest.tar.gz
Move the extracted files to the correct directory:
sudo mv wordpress/* .
Remove the downloaded archive and WordPress directory:
sudo rm -rf wordpress latest.tar.gz
Now, change the ownership of the files to the Apache user:
sudo chown -R www-data:www-data /var/www/html
Step 5: Configure WordPress
To configure WordPress, copy the sample configuration file:
sudo cp wp-config-sample.php wp-config.php
Now, open the wp-config.php
file for editing:
sudo nano wp-config.php
Look for the following lines and update them with the database information we created earlier:
define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wordpressuser' );
define( 'DB_PASSWORD', 'your_password' );
define( 'DB_HOST', 'localhost' );
Save and close the file (in nano, press CTRL+X, then Y, and Enter).
Step 6: Create Apache Virtual Host for Domain
To host your domain name on the server, we need to create a Virtual Host in Apache. Here's how to do it:
Create the Virtual Host Configuration File
First, navigate to the Apache sites-available directory:
cd /etc/apache2/sites-available/
Now, create a new configuration file for your WordPress website. Replace yourdomain.com with your actual domain name:
sudo nano yourdomain.com.conf
Add Virtual Host Configuration
Inside the file, add the following configuration:
<VirtualHost *:80>
ServerAdmin webmaster@yourdomain.com
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Make sure to replace yourdomain.com with your actual domain and email address. The DocumentRoot should point to /var/www/html, which is where WordPress files are located.
Enable the Virtual Host
After saving and closing the file (in nano, press CTRL+X, then Y, and Enter), you need to enable the Virtual Host configuration:
sudo a2ensite yourdomain.com.conf
Enable Rewrite Module
WordPress relies on Apache's mod_rewrite module for pretty permalinks. To ensure this module is enabled, run:
sudo a2enmod rewrite
Restart Apache
Finally, restart Apache to apply the changes:
sudo systemctl restart apache2
Step 7: Secure WordPress with SSL (Certbot)
To improve your website’s security and SEO ranking, it is important to secure it with SSL. We will use Certbot to install a free SSL certificate from Let’s Encrypt.
Install Certbot
First, install Certbot and the Apache plugin:
sudo apt install certbot python3-certbot-apache -y
Obtain an SSL Certificate
Now, run Certbot to automatically obtain and install the SSL certificate for your website:
sudo certbot --apache
Follow the prompts to enter your email address and agree to the terms of service. Certbot will automatically configure Apache to use HTTPS.
Verify SSL Installation
Once the process is complete, you can check your site’s security by visiting:
https://<your-server-ip>
You should see a padlock icon in the browser’s address bar, indicating that SSL is enabled.
Certbot automatically configures a cron job to renew your SSL certificate, but you can test it manually to ensure everything is working:
sudo certbot renew --dry-run
If no errors appear, your SSL certificate will be automatically renewed when needed.
Step 8: Complete WordPress Installation
Now, we need to finish the installation through the web interface. In your browser, visit:
https://<your-domain>/wp-admin/install.php
You will be prompted to select a language and set up your website. Enter the required information, including the site title, admin username, and password. Be sure to choose a strong password to secure your WordPress installation.
Once completed, click Install WordPress. You should see a success message.
Conclusion
Congratulations! In this tutorial, we've learnt how to install and host WordPress website on Ubuntu 24.04 Server. With SSL enabled, your website is more secure, which can boost your search engine rankings. You can now start customizing your site, installing themes and plugins, and publishing content.
We hope this guide has helped you set up WordPress smoothly. If you need further assistance, our expert team is always available to help you with hosting, configurations, and optimizations.