How to Install WordPress with Apache in Ubuntu

wordpress (Demo)
Advertisements by Google

WordPress is the most popular platform in the world for building websites, be it a blog, an e-commerce website, a business website, a portfolio website, an online business directory, and so on. It is free and open-source, easy to install, learn and use, highly pluggable and customizable too.

This guide shows how to install the latest version of WordPress with Apache in Ubuntu 20.04. It assumes that you have the LAMP stack installed and well configured for hosting websites, otherwise, see our guide:

Installing WordPress in Ubuntu 20.04

1. Once the LAMP stack (ApacheMariaDB, and PHP) installed and configured on the Ubuntu 20.04 server, you can proceed further to download the latest version of WordPress using the following wget command.

$ wget -c

Download WordPress in Ubuntu 20.04

2. Once the download is complete, extract the archived file using the tar command as shown.

$ tar -xzvf latest.tar.gz

Extract WordPress Files

3. Next, move the extracted WordPress directory into your document root i.e. /var/www/html/ and under your website as shown (replace with your website’s name or domain name). The following command will create a directory and move WordPress files under it.

$ ls -l

$ sudo cp -R wordpress /var/www/html/

$ ls -l /var/www/html/

Setup WordPress on Website

4. Now set appropriate permissions on the website (/var/www/html/ directory. It should be owned by the Apache2 user and group called www-data.

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

$ sudo chmod -R 775 /var/www/html/

Set Permissions on WordPress Files

Creating a WordPress Database for Website

5. To get started, log into your MariaDB database shell using the following mysql command with -u flag to supply the username which should be root and -p to enter a password that you set for the MySQL root account when you installed the MariaDB software.

$ sudo mysql -u root -p

6. After login, run the following commands to create your site’s database and a database user with privileges as shown. Remember to replace “mysite”, “mysiteadmin” and “SecureP@ssHere!” with your database name, database username, and the user’s password.

MariaDB [(none)]> CREATE DATABASE mysite;

MariaDB [(none)]> GRANT ALL PRIVILEGES ON mysite.* TO ‘mysiteadmin‘@’localhost’ IDENTIFIED BY ‘SecureP@ssHere!‘;


MariaDB [(none)]> EXIT

Create a WordPress Database

7. Next, move into your website’s document root, create a wp-config.php file from the sample configuration file provided as shown.

$ cd /var/www/html/

$ sudo mv wp-config-sample.php wp-config.php

8. Then open the wp-config.php configuration file for editing.

$ sudo vim wp-config.php

and update the database connection parameters (database name, database user, and the user’s password created above) as shown in the following screenshot.

Configure WordPress Database Settings

Creating Apache VirtualHost for WordPress Website

Advertisements by Google

9. Next, you need to configure Apache webserver to serve your WordPress site using your fully qualified domain name, by creating a Virtual Host for it under the Apache configuration.

To create and activate a new Virtual Host, create a new file under the /etc/apache2/sites-available/ directory. In this example, we will call the file (it should end with the .conf extension).

$ sudo vim /etc/apache2/sites-available/

Then copy and paste the following configuration in it (replacing the ServerName and ServerAdmin emails with your values).

<VirtualHost *:80>


      ServerAdmin webmaster@localhost

      DocumentRoot /var/www/html/

      ErrorLog ${APACHE_LOG_DIR}/error.log

      CustomLog ${APACHE_LOG_DIR}/access.log combined


Create WordPress Apache Virtual Host

Save the file and close it.

10. Then check the Apache configuration for syntax correctness. If the syntax is OK, enable the new site and reload the apache2 service to apply the new changes.

$ apache2ctl -t

$ sudo a2ensite

$ sudo systemctl reload apache2

Enable Website in Apache

11. Also, disable the default virtual host to allow your new site to load properly from a web browser.

$ sudo a2dissite 000-default.conf

$ sudo systemctl reload apache2

Disable Website in Apache

Completing the WordPress Installation via Web Interface

12. The final section demonstrates how to complete the WordPress installation using the web installer. So open your browser and navigate using your site’s domain name:

Once the WordPress web installer loads, pick the language you wish to use for installation and click Continue.

Select WordPress Installation Language

13. Next, set your site’s title, administrative username, and password and an email for managing your site content. Then click Install WordPress.

Add WordPress Site Details

14. Once the WordPress installation is complete, click on Log in to access your site’s administrative login page.

WordPress Installation Complete

15. Now log into your new WordPress website using your administrative credentials (username and password created above) and start to customize your site from Dashboard.

WordPress LoginWordPress Dashboard

In this article, we have explained how to install WordPress using Apache as a web server and MySQL as a database system for serving PHP websites.

Next, the crucial step is to secure your WordPress site with SSL. If you have deployed WordPress on a real domain, you can secure the site with Free Let’s Encrypt certificate. If you have deployed WordPress locally on a dummy website for testing or personal use, I suggest you to use a self-signed certificate instead.

Advertisements by Google

Related Posts

Leave a comment

Privacy Preferences
When you visit our website, it may store information through your browser from specific services, usually in form of cookies. Here you can change your privacy preferences. Please note that blocking some types of cookies may impact your experience on our website and the services we offer.
%d bloggers like this: