Ubuntu

How to Setup WordPress on Ubuntu Server with Apache

Setup WordPress on Ubuntu Server with Apache

WordPress is a free and open-source content management system (CMS) that you can use to create, publish and manage great-looking websites, blogs, and associated content with minimal coding experience. WordPress is used by many globally recognized organizations and celebrities.

To get started with WordPress, you could either use a hosting provider or download and install it yourself. This guide focuses on installing WordPress by yourself for development or testing purposes on a Ubuntu 20.04 Linux server with Apache

Install Apache

Let us begin by installing the Apache webserver if it’s not already installed. Run the following commands to check for package updates and install the latest Apache version respectively.

$ sudo apt-get update
$ sudo apt-get install apache2 -y

Check the status of the Apache web service as follows.

$ sudo systemctl status apache2

The output of the command should indicate that apache2 is active (running) as shown in figure 1 below. If not, run the following command to start Apache.

sudo systemctl start apache2

Figure 1: Check apache service status

Press q to return to the terminal prompt.

Install WordPress, PHP and MySQL

The next step is to install WordPress, PHP, MySQL, and associated components by running the command below.

$ sudo apt-get install wordpress php libapache2-mod-php mysql-server php-mysql

If prompted, enter y to continue.

Configure MySQL for WordPress

After the installation completes successfully, run the next command and follow the instructions to secure your MySQL installation.

$ sudo mysql_secure_installation

The script will guide you accordingly.

Next, you would need to create a database as well as a user account in MySQL for WordPress. Run the command below to login to MySQL. Enter your MySQL root password when prompted.

$ sudo mysql -u root -p

To create a database for WordPress, run the following command.

$ CREATE DATABASE wordpress;

To create a user account for WordPress in MySQL, run the next commands. Replace wordpressuser and password with your own values.

$ CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';

To save changes, run:

$ FLUSH PRIVILEGES

Now, run the following command to grant the wordpressuser account the required permissions on the WordPress database.

$ GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';

Save changes again and quit MySQL with the following commands.

$ FLUSH PRIVILEGES
$ quit

Configure Apache for WordPress

Run the command below to copy the WordPress installation folder from /usr/share to the default website root var/www/html.

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

Change ownership of the WordPress folder and content to the default apache web service account and group.

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

Also, grant the apache web service account and group full permissions on the WordPress folder and content as follows.

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

Next, open the default virtual host configuration file and change the value of the DocumentRoot directive to /var/www/html/wordpress as shown in figure 2 below.

$ sudo nano /etc/apache2/sites-available/000-default.conf

Figure 2: Change default apache document root

Save changes to the file with CTRL + O, hit the enter key to confirm, and then press CTRL + X to exit.

Configure WordPress

First, change the working directory to the WordPress installation folder by running the command below.

$ cd /var/www/html/wordpress

Next, copy the sample config file as follows.

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

Now, open the wp-config.php file, scroll down and input the WordPress database name, database user account, and password which you created earlier while configuring MySQL for WordPress.

$ sudo nano wp-config.php

Figure 3: Configure WordPress settings

Save changes and close the wp-config.php file.

Reload the apache web service by running the next command.

$ sudo systemctl reload apache2

Launch the WordPress Web Installer

Open a web browser and enter the IP address of your Ubuntu server. You should see the WordPress installation wizard as shown in figure 4 below. Follow the wizard to complete your WordPress installation.

Figure 4: WordPress installation wizard

Conclusion

In this guide, we successfully installed WordPress — including Apache, MySQL, and PHP, on the Ubuntu Linux server. We hope that you enjoy using WordPress. We would be glad to read about your experiences using this content management system.

Similar Posts