How To Install WordPress With Apache On Ubuntu 18.04

WordPress is by far the most popular open source blogging and CMS platform that powers over a quarter of the world’s websites. It is based on PHP and MySQL and packs a ton of features that can be extended with free and premium plugins and themes. WordPress enables you to easily build your eCommerce store, website, portfolio or blog.

Prerequisites

  • Have a domain name pointing to your server public IP. We’ll use example.simpleinformation.com.
  • Logged in as a user with sudo privileges.
  • Apache installed on your Ubuntu server.
  • MySQL or MariaDB installed on your Ubuntu server.
  • PHP 7.2 installed on your Ubuntu server.

Once you have fulfilled the above requirements, continue on with this guide.

Configure a MySQL User and Database

To begin, log into MySQL:

mysql -u root -p

Once you have successfully authenticated, you will be dropped into a MySQL prompt. First, create a database for your WP installation to use.

CREATE DATABASE db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Next, create a MySQL user account and grant access to the database:

GRANT ALL ON db_name.* TO 'wpuser'@'localhost' IDENTIFIED BY 'password';

Finally, exit the mysql console by typing:

EXIT

Downloading Wordpress

Before downloading the Wordpress archive, first create a directory for WP files:

sudo mkdir /srv/example.com

Next step is to download the latest version of WordPress

cd /tmp
wget https://wordpress.org/latest.tar.gz

Now extract the archive and move the extracted files into the root directory:

tar xf latest.tar.gz
sudo mv /tmp/wordpress/* /srv/example.com/

Set the correct permissions so that the web server can have full access to the site’s files and directories

sudo chown -R www-data:www-data /srv/towaway.com

Configuring Apache

Next step is to create and edit the Apache virtual hosts configuration for our WP domain:

So, Create a new file /etc/apache2/sites-available/example.com.conf.

<VirtualHost *:80>
  # Admin email, Server Name (domain name) and any aliases
  ServerAdmin example@simpleinformation.com
  ServerName  example.simpleinformation.com
  # Index file and Document Root (where the public files are located)
  DocumentRoot /srv/example.com/
  # Custom log file locations
  LogLevel warn
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /srv/example.com/>
  Options Indexes FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>
</VirtualHost>

Enable the virtual host for the domain. The command below will create a symbolic link from the sites-available to the sites-enabled directory:

sudo a2ensite example.com.conf.

Now restart the Apache service

sudo service apache2 restart

Completing the WordPress Installation

Now that Wordpress is downloaded and the server configuration is complete, it is time to finalize the WordPress installation through the web interface.