×


Configure WordPress on Ubuntu Server with Apache - Step by step process to do it ?

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.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to configure WordPress on their Linux Server.

In this context, we shall look into how to install WordPress by yourself for development or testing purposes on a Ubuntu 20.04 Linux server with Apache.


Steps to Setup WordPress on Ubuntu 20.04 Linux server ?

To get started, ensure that you log into your Server as the root user with sudo rights.

Then once logged in, follow the steps provided below.


1. 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). 

If not, run the following command to start Apache:

$ sudo systemctl start apache2

Press q to return to the terminal prompt.


2. 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.


3. Configure MySQL for WordPress

i. 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.

ii. 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

iii. 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';

iv. Save changes again and quit MySQL with the following commands:

$ FLUSH PRIVILEGES
$ quit


How to Configure Apache for WordPress ?

i. 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

ii. 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

iii. 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

iv. Next, open the default virtual host configuration file and change the value of the DocumentRoot directive to /var/www/html/wordpress:

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

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


How to Configure WordPress ?

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

$ cd /var/www/html/wordpress

ii. Next, copy the sample config file as follows:

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

iii. 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

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

v. Reload the apache web service by running the next command.

$ sudo systemctl reload apache2


How to Launch the WordPress Web Installer ?

i. Open a web browser and enter the IP address of your Ubuntu server. 

ii. You should see the WordPress installation wizard. 

iii. Then, Follow the wizard to complete your WordPress installation.


[Need urgent assistance in installing WordPress on your Linux Server? We are available to help you. ]


Conclusion

This article covers setup WordPress — including Apache, MySQL, and PHP, on the Ubuntu Linux server. WordPress is the most popular CMS (content management system) on the internet. It allows you to easily set up flexible blogs and websites on top of a MySQL backend with PHP processing. WordPress has seen incredible adoption and is a great choice for getting a website up and running quickly. After setup, almost all administration can be done through the web frontend.


How to install PHP Extensions on Ubuntu?

1. You can download and install some of the most popular PHP extensions for use with WordPress by executing the commands:

$ sudo apt update
$ sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip

2. Then restart Apache to load these new extensions in the next section. 

If you are returning here to install additional plugins, you can restart Apache now by running:

$ sudo systemctl restart apache2


To install WordPress on Ubuntu:

1. Change into a writable directory and then download the compressed release by typing:

$ cd /tmp
$ curl -O https://wordpress.org/latest.tar.gz

2. Extract the compressed file to create the WordPress directory structure:

$ tar xzvf latest.tar.gz

3. Add a dummy .htaccess file so that this will be available for WordPress to use later.

Create the file by typing:

$ touch /tmp/wordpress/.htaccess

4. Copy over the sample configuration file to the filename that WordPress actually reads:

$ cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

5. Create the upgrade directory, so that WordPress won't run into permissions issues when trying to do this on its own following an update to its software:

$ mkdir /tmp/wordpress/wp-content/upgrade

6. Copy the entire contents of the directory into our document root:

$ sudo cp -a /tmp/wordpress/. /var/www/wordpress