WordPress is the leading content management system for good reason. It’s the same software we use to power our own blog and is used by over a third of the entire internet. 

There is a whole range of different ways to host WordPress, for the best possible performance we always recommend installing WordPress on OpenLiteSpeed or installing WordPress on servers running NGINX (both of which are supported out of the box on RunCloud with our easy, 1-click WordPress installation). 

That being said, if you’ve made your way to this tutorial – the chances are that your mind is already set on installing WordPress on Apache. So, without further ado – let’s dive right in. 

Before You Install WordPress

Before we start running scripts, here’s what you’ll need in order to be able to successfully follow this tutorial step-by-step: 

1 – A server deployed that is running the latest version of Ubuntu

You can deploy a server with your cloud provider of choice. For the purposes of this tutorial, we’ll be using UpCloud which is extremely easy & simple to work with. 

2 – Privileged access to that Linux server (as root or via the sudo command)

When deploying ensure to make a note of the credentials for the root user (or the privileged sudo user). 

1 – Installing All Of The Required Packages (LAMP) & Getting Your Server Ready To Install WordPress

The first step is to install Apache, PHP, and MySQL on your freshly-deployed server. These are the packages you’ll need to be able to run WordPress (since it requires a database and is a PHP based content management system). 

After running each of the commands in these sections in succession, you will have to wait for a few moments each time for the installation process to complete successfully. 

Here’s what that looks like: 

Alright so, open terminal (command line) and SSH into your server as a privileged user. Doing so is incredibly simple: 

ssh root@[your server ip]

Upon hitting enter you will be prompted to enter the password for the root user. Enter the password that you set when deploying your server (or depending on your provider may have been emailed to you once the deployment process was complete). 

As a best practice, you’ll want to start by updating the package manager cache. This is done by running the following command: 

sudo apt update

1.1 – Installing & Preparing Apache

After which you can install Apache by running the following: 

sudo apt install apache2

Note: You will be prompted to confirm the installation of Apache by entering Y

Once the installation is complete, update your firewall settings in order to allow HTTP traffic.

sudo ufw allow in "Apache"

Note: You can verify the status by running: sudo ufw status at any time and in this case can also proof that it had the desired impact by attempting to visit http://[your server ip] in your web browser. At this stage you will only see this default page: 

1.2 – Install & Configure MySQL 

Now your Apache web server is up & running but in order to use it to host WordPress (which heavily relies on the presence of a database), you’ll need to install MySQL. 

To do so, run the following command: 

sudo apt install mysql-server

Once installed, it’s time to get your database ready. Get started by running the following command: 

sudo mysql_secure_installation

Upon running this command, you will be prompted to answer a series of question by entering either the letter Y or the letter n and then hitting the enter key. 

Here are the questions you will be asked along with the corresponding answers: 

VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: 

If you answer yes, you will be asked to set a level of password validation (where 2 is the strongest level and will require all passwords to contain numbers, upper, lowercase letters and special characters, etc. Regardless of what you choose here, you will then have to set a password for your MySQL database.

Remove anonymous users? [Y/n] 

Purely for the purposes of testing all MariaDB installations come with an anonymous user (this makes it possible to log into MariaDB without having a user account ready to use). Since this is for testing and not advised for servers that are being used in production, you’re going to want to go ahead and remove the anonymous users by replying Y here. 

Disallow root login remotely? [Y/n] 

In single-server setups the database only needs to be accessible by this server (which would be considered localhost access as opposed to remote access). Therefore, this can be disabled by responding Y

Remove test database and access to it? [Y/n] 

Respond Y to this step to simply remove the tables and ensure that the database is empty and ready for us to install WordPress later. 

Reload privilege tables now? [Y/n] 

And last but not least, respond Y here. 

1.3 – Installing PHP

And now that your Apache web server is running and database is ready. The final package left to install is PHP. The WordPress content management system is PHP-based so it requires PHP in order to be able to run on your server. 

To install PHP (along with the modules necessary for PHP to be able to communicate with your MySQL database), run the following command: 

sudo apt install php libapache2-mod-php php-mysql

Note: Once installed you can check your PHP version at any time by conveniently running the php -v command. 

Now that you’ve installed PHP, it’s important to install these additional extensions which are required/useful for WordPress to operate in its best form: 

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

After installing these changes restart Apache by running the following command: 

sudo systemctl restart apache2

1.4 – Create a Virtual Host File

Apache operates on the concept of virtual hosts (these are somewhat similar to NGINX server blocks) and are what make it possible to run web applications on multiple domains on a single server. In this scenario we’re going to set up our server up to run our site at apache.runcloudsandbox.com – so going forward, you can replace that with your own domain in these instructions. 

Create the directory for your domain by running the following command: 

sudo mkdir /var/www/runcloudsandbox.com

Then, assign the current user ownership of that directory: 

sudo chown -R $USER:$USER /var/www/runcloudsandbox.com

Now, open up a new configuration file, by running the following command: 

sudo nano /etc/apache2/sites-available/runcloudsandbox.com.conf

This will open up the built-in text editor in the command line. Proceed to populate this file with the following configuration:

<VirtualHost *:80>
    ServerName runcloudsandbox.com
    ServerAlias www.runcloudsandbox.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/runcloudsandbox.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory /var/www/runcloudsandbox.com/>    AllowOverride All</Directory>

Once you’ve modified the above to be suitable for your installation and domain, you can safely close the file by pressing CTRL+X, followed by entering Y to confirm that you wish to save the changes. Before we can enable this virtual host configuration, we need to disable the one that is in place by default that results in the Apache welcome page appearing: 

sudo a2dissite 000-default 

And now that your configuration file is ready to go, you can run the a2ensite command to enable the use of this virtual host configuration: 

sudo a2ensite runcloudsandbox.com

Then, reload Apache in order for these changes to take effect: 

systemctl reload apache2

At this stage, when visiting your server’s IP address in your browser – you should observe the following:

2 – Create MySQL Database & User for WordPress

You’ve already installed MySQL in the first section of this tutorial, but now it’s time to create the database that you’ll be using in order for WordPress to store post, page, comment, user content and more. The first step is to run the following command to access MySQL: 

sudo mysql 

This will go ahead and open up MySQL. Assuming that all previous steps have been completed correctly, upon running this command you should see the following appear in your terminal window: 

Now, in order to create a new database for WordPress, run the following command (in this case we have called ours runcloud_db): 


You can name yours whatever you feel is more suitable of course. 

The database has now been created but we also need to let WordPress access the database. And in order to make that possible, you’re going to need to create a database user by running the following command: 

CREATE USER 'runcloud_db_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Replacing the user name with something that you wish to use as the database user for WordPress. Make a note of this information as you will need it during the WordPress setup process later. Running the command above only creates the user but it doesn’t grand it the necessary privileges. In order to give it full access to the WordPress database, run the following command. 

GRANT ALL PRIVILEGES ON runcloud_db.* to runcloud_db_user@'localhost';

If you chose a different user name for the database name and database user name during creation (which we highly recommend) you will need to update that when running this command. 

And now, you can save all of these changes made to the permissions and exit MySQL entirely. This is done by running the following two commands in succession: 


3 – Other Preparations for WordPress

3.1 – Run The Following Command To Enable The Rewrite Module

sudo a2enmod rewrite

Note: This step is necessary in order to make use of human-readable permalink structures in WordPress. 

4 – Installing WordPress (almost there!)

Now, we’re finally onto the final three commands. 

Run these in succession to install the latest stable release of WordPress, unzip it and place it into the directory set up earlier: 

wget -O /tmp/wordpress.tar.gz https://wordpress.org/latest.tar.gz
sudo tar -xzvf /tmp/wordpress.tar.gz -C /var/www/runcloudsandbox.com
sudo chown -R www-data.www-data /var/www/runcloudsandbox.com

Upon running these commands, you will then be able to begin the famous 1-minute WordPress setup process in your browser by navigating to your server’s IP address and the path at which you’ve installed WordPress: 

This is the stage at which you will need the database username, database name and database password we indicated it would be important to note earlier: 

As you’ll be prompted to enter it as shown below: 

Once you click submit, you’ll be prompted to login normally via the default WordPress login screen after which you’ll be able to use your WordPress website normally: 

And well, we would say that’s it – but that would imply this was an easy & enjoyable process which we can confidently say it isn’t. Not a single developer we know enjoys running these commands manually. It’s tedious, boring and easy to make mistakes. Plus, you can spend time focused on better higher-level programming if you’re good at programming as opposed to repetitive server-level tasks like deploying WordPress on your cloud infrastructure. Especially since this is only the beginning and doesn’t even take into consideration any maintenance work you’ll need to do, securing the server and ensuring that it remains in good working order. 

Fortunately, that’s exactly what RunCloud is for. With everything from 1-click server and WordPress deployments all the way to staging for WordPress, security optimizations and more. You’ll never have to worry about server deployment, management and more. 

Interested in learning more & getting started? Kick-off your free trial today and don’t hesitate to reach out to us if you have absolutely any questions.