Install WordPress on Ubuntu 19.04

WordPress is one of the most popular Content Management Systems available. It is being used for building websites. To install WordPress on Ubuntu 19.04 distribution, we have two options available.

A. We need to prepare a list of packages to install.
B. Install packages as a group with the help of package tool tasksel.

Installing packages with the help of package tasksel is usually preferred. Therefore, we are going discuss steps involved in installing Lamp-Server through tasksel.

The whole installation process is easy to execute and mainly involves five steps that are mentioned below:

1: Get super user privileges.
2: Install Lamp-Server.
3: Create database user and grant privileges.
4: Install relevant PHP packages and edit few config files.
5: Install WordPress.

Setup LAMP on Ubuntu 19.04

STEP – 1: Login with superuser privileges, if you don’t have one then contact System Administrator for assistance.

STEP – 2: If you don’t have the package tasksel installed, then install it by issuing following command.

sudo apt install tasksel

Then, install lamp-server with by typing the following command in terminal –

sudo tasksel install lamp-server

STEP – 3: Now, we need to securely install MySQL. So, type –

sudo mysql_secure_installation

It will ask for a password. Remember the password as it will be used while creating a database for WordPress soon. For plugin validation, we need to press NO and for the rests of prompts press YES. Now, we will be create a database for WordPress. So, type –

mysql -u root -p

Enter the password that was provided while doing secure installation of MySQL and type the following commands. This is being done to create a database “wp_database” for user “wp_user” and password as “password”. We will next grant privileges to the user.

CREATE DATABASE wp_database;
CREATE USER `wp_user`@`localhost` IDENTIFIED BY `password`;
GRANT ALL PRIVILEGES ON wp_database.* TO `wp_user`@`localhost`;
FLUSH PRIVILEGES;
quit

STEP – 4: You can install following useful PHP extensions by issuing following commands:

sudo apt install php-curl php-mbstring php-xml

Now restart Apache services,

sudo systemctl restart apache2

We are doing configuration of hosting one website on our server, so we will edit the default file:

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

and, add the following code in the above file – 000-default.conf. Then, save and exit.

<Directory /var/www/html/>
    AllowOverride All
</Directory>

We now have enable rewrite module so that we can use Permalink feature of WordPress;

sudo a2enmod rewrite

Run the following command to spot any error in syntax.

sudo apache2ctl configtest

It should return with the output Syntax OK.

Lastly, run

sudo systemctl restart apache2
Install WordPress on Ubuntu 19.04

STEP – 5: Download WordPress from the official website. The file downloaded will be – latest.tar.gz and save it in directory /tmp/. Then, issue the following in terminal –

tar xzvf latest.tar.gz

tar command extracts the downloaded file.

Now, we have to copy the wp-config-sample.php file as wp-config.php in the same folder by typing the following command.

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

Once done, copy the entire WordPress directory to /var/www/html/ directory.

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

Next, we provide ownership of the all files copied (also making plugins and themes editable) to the Apache Web Server by using chown command,

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

Lastly, update details in wp-config.php file –

sudo nano /var/www/html/wp-config.php

and, edit the following entries with relevant ones created in the STEP – 3.

define( 'DB_NAME', 'wp_database' );
define( 'DB_USER', 'wp_user' );
define( 'DB_PASSWORD', 'password' );

Now, save and exit. Remove index.html file from /var/www/html/ directory by issuing following command,

sudo rm /var/www/html/index.html

Open your Web Browser and type:

http://localhost

and, provide relevant details including your username and password for WordPress login. Once, successfully done you will taken to WordPress login prompt.

For some reason, if you are still unable to edit themes and plugins then you need to append /var/www/html/wp-config.php file with the following –

define( 'FS_Method', 'direct' );

In conclusion, we have discussed how to install WordPress on Ubuntu 19.04.