Install WordPress with Apache and Let’s Encrypt on Ubuntu 24.04|22.04

Today’s tutorial will show you how to install WordPress with Apache and Let’s Encrypt on an Ubuntu 24.04|22.04 Linux system step by step. WordPress is the most widely used, powerful, feature-rich, and open-source PHP-based content management system. WordPress uses a MySQL relational database to store its data.

WordPress allows you to construct a website that is specifically tailored to your needs. You may use WordPress to make a blog, a company website, a portfolio, an online store, or anything else. Give WordPress a try if you’re looking for the best Content Management System for your website or blog and you’ll probably love it.

Features of WordPress CMS

WordPress have the following cool features:

  • Pages, posts, products, and more are all unlimited.
  • Manage your website’s content with ease.
  • Dashboard widgets can be added, moved, and deleted.
  • Accessibility Mode for Widgets.
  • Image retouching.
  • Links, movies, and other multimedia can be embedded.
  • To create links, paste URLs into the Visual Editor.
  • Posting of News and Blogs at One Place.
  • Rollback Versioning and Restore Deleted Pages.
  • Website security that is managed.

Install WordPress with Apache and Let’s Encrypt on Ubuntu

The following steps will take us through the installation of WordPress with Apache and Let’s Encrypt on Ubuntu.

Step 1: Perform System Updates

Run the following commands to update Ubuntu system:

sudo apt update && sudo apt upgrade -y

Check if a reboot is required once the system has been rebooted.

[ -f /var/run/reboot-required ] && echo "Reboot is required" || echo "No reboot is required"

Step 2: Install Apache on Ubuntu

The following command can be used to install the Apache web server:

sudo apt install apache2 -y

Start and enable Apache after successful installation:

sudo systemctl enable --now apache2

Step 3: Install MariaDB Database server

We will install MariaDB database server as follows:

sudo apt install mariadb-server -y

Harden MariaDB database:

$ sudo mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Access the root user shell after the database server has been installed:

sudo mysql -u root -p

Now, create a database and user for WordPress:

CREATE DATABASE WordPressDB;
CREATE USER 'admin'@'localhost' identified by 'StrongPassword';
GRANT ALL PRIVILEGES ON WordPressDB.* TO 'admin'@'localhost';
FLUSH PRIVILEGES;
QUIT;

Remember to replace StrongPassword with the password for your database user.

Verify that the user can login to the database using the password provided:

$ mysql -u admin -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 40
Server version: 10.11.8-MariaDB-0ubuntu0.24.04.1 Ubuntu 24.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| WordPressDB        |
| information_schema |
+--------------------+
2 rows in set (0.001 sec)

MariaDB [(none)]> 

Step 4: Install  PHP and required Extensions

WordPress runs on PHP, which is included with Ubuntu. We’ll install PHP and the required extensions.

sudo apt install php php-{fpm,mysql,cli,json,opcache,xml,gd,curl}

Then install the following apache module:

sudo apt install libapache2-mod-php

Step 5: Download and Install  WordPress

Before we can proceed let’s install the following packages first:

sudo apt install wget vim -y

Download the latest WordPress as follows in it’s Download’s page:

wget https://wordpress.org/latest.tar.gz

Run the following command to extract the archive when it has been downloaded successfully:

tar xvf latest.tar.gz

Move the resulting directory to your Web Document Root:

sudo mv wordpress /var/www/html/wordpress

Configure WordPress Database connection:

cd /var/www/html/wordpress
sudo cp wp-config-sample.php wp-config.php

Edit  wp-config.php and make the following changes:

$ sudo vim wp-config.php
define('DB_NAME', 'WordPressDB');
define('DB_USER', 'admin');
define('DB_PASSWORD', 'StrongPassword');

Remember to replace according to your WordPress database created above.

Change the owner of /var/www/html/mywpblog to a web user:

sudo chown -R www-data:www-data /var/www/html/wordpress

Step 6: Configure Apache and Initialize WordPress

For your WordPress site, create an Apache virtual host setup.

sudo vim /etc/apache2/sites-available/wordpress.conf

Add the following content:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName wordpress.example.com
    DocumentRoot /var/www/html/wordpress
    
    <Directory /var/www/html/wordpress>
       AllowOverride All
    </Directory>

    ErrorLog /var/log/apache2/wp.error.log
    CustomLog /var/log/apache2/wp.access.log combined
</VirtualHost>

Now, check Apache syntax errors:

$ sudo apachectl -t
Syntax OK

If there are no errors as per the output above, enable WordPress site configuration:

sudo a2ensite wordpress.conf

Then disable the default Apache site:

sudo a2dissite 000-default.conf

Now, restart Apache:

sudo systemctl restart apache2

To finish installing WordPress on Ubuntu, open a browser and go to http://your-server-ip> to access your WordPress site.

Choose your preferred Language:

Provide Site Title, Admin username, Password and Email Address.

To complete WordPress installation, click the Install WordPress button.

Use the username and password you created to access the WordPress Administration Dashboard.

You should now be on the WordPress Dashboard, which is as seen below.

Changing WordPress Permalink

To set permalinks, click on Settings ->Permalinks and adjust accordingly.

Changing WordPress Password and Email

To change password and email, click on Users ->Profile.

Changing WordPress Themes

Click on Appearance ->Themes and install your favorite theme.

Installing WordPress Plugins

Click on Plugins -> Add New and select the plugin to install.

Configuring WordPress Backups

Backups can be done by installing backup plugin as shown below.

Secure WordPress Site with Let’s Encrypt SSL

We’ll use the Certbot tool to install Let’s Encrypt SSL and generate a free SSL certificate for our WordPress site. To install the Certbot utility, run the following command:

sudo apt install certbot python3-certbot-apache

Let’s generate a free Let’s Encrypt SSL certificate for Apache after installing Certbot.

sudo certbot --apache

You will be asked to submit your email address as well as a series of questions, which you should do.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.4-April-3-2024.pdf. You must agree in
order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Account registered.

Which names would you like to activate HTTPS for?
We recommend selecting either all domains, or all domains in a VirtualHost/server block.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: wordpress.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for wordpress.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/wordpress-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/wordpress-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/wordpress-le-ssl.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/wordpress.conf to ssl vhost in /etc/apache2/sites-available/wordpress-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://wordpress.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=wordpress.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/wordpress.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/wordpress.example.com/privkey.pem
   Your cert will expire on 2028-07-28. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

You can now access your WordPress site using  https://wordpress.example.com/ link.

Conclusion

Congratulations! We’ve reached the end of our tutorial on how to install WordPress on Ubuntu using Apache and Let’s Encrypt. We hope you found the information in this guide to be helpful.

Amazing Guides:

Your IT Journey Starts Here!

Ready to level up your IT skills? Our new eLearning platform is coming soon to help you master the latest technologies.

Be the first to know when we launch! Join our waitlist now.

Join our Linux and open source community. Subscribe to our newsletter for tips, tricks, and collaboration opportunities!

Recent Post

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Post

For most system admins, their day-to-day life activities revolve around having access to remote systems.VNC an acronym for Virtual Network […]

PostgreSQL is an open-source object-relational database management system (ORDBMS) based on POSTGRES, Version 4.2. Postgresql was developed at the University […]

Most Linux users prefer a minimal Linux installation where you are only provided with the command line. This is due […]

Let's Connect

Unleash the full potential of your business with CloudSpinx. Our expert solutions specialists are standing by to answer your questions and tailor a plan that perfectly aligns with your unique needs.
You will get a response from our solutions specialist within 12 hours
We understand emergencies can be stressful. For immediate assistance, chat with us now

Contact CloudSpinx today!

Download CloudSpinx Profile

Discover the full spectrum of our expertise and services by downloading our detailed Company Profile. Simply enter your first name, last name, and email address.