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