In this tutorial we will guide you through the steps of installing WordPress on an Ubuntu 18.04 VPS with all necessary components, such as Apache web server, PHP and MySQL/MariaDB database server, and configure WordPress to use a database on a remote server.
WordPress is the most popular and most widely-used content management system (CMS). It is the CMS of choice for 26% of the entire web. It is based on PHP, and it stores its information in a MySQL database. The large amount of themes and plugins makes this CMS an excellent choice for someone that needs a user-friendly way to get their ideas onto a website that looks good. Let’s get started with the installation.
Table of Contents
Prerequisites
- Ubuntu 18.04 VPS + Remote database server
- PHP version 7.3 or newer.
- MySQL database version 5.6 or newer OR MariaDB version 10.1 or newer.
- HTTPS support
Step 1: Log in and Update the Server
Log in to your Ubuntu 18.04 VPS via SSH as user root
ssh root@IP_Address -p Port_number
Don’t forget to replace ‘IP_Address‘ and ‘Port_number‘ with the actual IP address of your server and the SSH port number.
Once you are in, run the following commands to make sure that all installed packages on your server are updated to the latest available versions:
apt update && apt upgrade
Step 2: Install Apache Web Server
We need to install a web server to serve WordPress’ content. For this purpose, we will install and use Apache web server. It is available in the official Ubuntu repository and it can be easily installed using the apt package manager:
apt -y install apache2
Once the installation of the web server is completed, Apache should be automatically started. You can confirm this by checking its status
systemctl status apache2
Output:
apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: active (running) since Fri 2019-08-09 02:31:39 CST; 14min ago Main PID: 406 (apache2) Tasks: 7 (limit: 1110) CGroup: /system.slice/apache2.service ├─ 407 /usr/sbin/apache2 -k start ├─ 423 /usr/sbin/apache2 -k start ├─ 426 /usr/sbin/apache2 -k start ├─ 427 /usr/sbin/apache2 -k start ├─ 428 /usr/sbin/apache2 -k start
Enable Apache to automatically start after a server reboot
systemctl enable apache2
Step 3: Install PHP
As we already mentioned, WordPress is a PHP-based application, so we have to install PHP and several PHP extensions on the server. Run the following command to install all necessary components:
apt -y install php php-xml php-common php-gd php-mbstring php-xmlrpc php-curl php-soap php-zip php-intl
After the installation of PHP is completed, you can check the installed version:
PHP 7.2.19-0ubuntu0.18.04.1 (cli) (built: Jun 4 2019 14:48:12) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.19-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies
Step 4: Install MySQL on the Remote Server
The next step is to install a database server. For the purposes of this tutorial, we will install it on a remote server.
Login to the remote server via SSH
ssh root@remote_IP -p Port_number
and install the MySQL database server using the following command
apt -y install mysql
To accept remote connections, edit the MySQL configuration file and modify the bind-address
option. It is set to listen on localhost only. We will change 127.0.0.1
to the database server IP address.
/etc/mysql/mysql.conf.d/mysqld.cnf
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = remote_IP
and restart MySQL for the changes to take effect:
systemctl restart mysql
Step 5: Create MySQL Database and User
While you are still logged in to the remote server which we will use as our database server, create a MySQL user and database for the WordPress installation. Login to the MySQL cli as the root user and execute the following commands:
mysql -u root -p
mysql> CREATE DATABASE wp;
mysql> CREATE USER 'wpser'@'IP_address' IDENTIFIED BY 'PASSWORD';
mysql> GRANT ALL PRIVILEGES ON wp.* TO 'wpser'@'IP_address';
mysql> FLUSH PRIVILEGES;
Where ‘IP_address‘ is the IP address of the Ubuntu 18.04 server where WordPress will be installed. Make sure to replace the password with a good and unique one.
Step 6: Install WordPress
Now, go back to the Ubuntu 18.04 VPS where we installed Apache and PHP, and install WordPress on it. To do that, download the WordPress archive:
wget https://wordpress.org/latest.zip
Unpack the downloaded ZIP archive to the document root directory:
unzip latest.zip /var/www/html
Set the proper ownership to the WordPress files:
chown -R www-data:www-data /var/www/html/wordpress
Rename the wp-config-sample.php
WordPress configuration file to wp-config.php
:
mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
Edit the WordPress configuration file and modify the following lines
nano /var/www/html/wordpress/wp-config.php /** The name of the database for WordPress */ define('DB_NAME', 'wp'); /** MySQL database username */ define('DB_USER', 'wpuser'); /** MySQL database password */ define('DB_PASSWORD', 'PASSWORD'); /** MySQL hostname */ define('DB_HOST', 'remote_IP');
and save the file.
Step 7: Create an Apache Virtual Host
In order to be able to access WordPress with a domain name instead of the IP address, we have to create Apache virtual host for the specific domain. We will use as an example. Replace all occurences of domain.com
with your actual domain name.
<VirtualHost *:80> ServerAdmin admin@domain.com ServerName domain.com ServerAlias www.domain.com DocumentRoot /var/www/html/wordpress <Directory /var/www/html/wordpress> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/domain.com_error.log CustomLog ${APACHE_LOG_DIR}/domain.com_access.log combined </VirtualHost>
Enable the virtual host
a2ensite domain.com
And restart Apache for the changes to take effect
systemctl restart apache2
With this step the WordPress installation is completed, and you can finish its configuration by opening http://domain.com
in your favorite web browser. Then follow the on-screen instructions to select a language, create your administrative account, etc…
Congratulations! We have not only installed WordPress on our Ubuntu 18.04 VPS, but we also made it use a database server that is remote to the one hosting the WordPress instance.
Of course, you don’t have to install WordPress on Ubuntu 18.04 and configure it to use a Remote Database if you use one of our Optimized WordPress Hosting services, in which case you can simply ask our expert system administrators to install WordPress on Ubuntu 18.04 and configure it to use a Remote Database for you, using the LAMP stack or any other web hosting stack of your choice. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post, on how to install WordPress on Ubuntu 18.04 and configure it to use a remote database, please share it with your friends on the social networks using the buttons below or simply leave a comment in the comments section. Thanks.