WordPress is easily one of the most popular and versatile content management systems in existence today, and for good reasons too. It can be used to create all types of websites and blogs and it also provides flexibility in terms of customization.
Additionally, it is a free and open-source application which means that anyone can make use of it with little to no restrictions.
Despite being a free platform for creating a website or blog, in most cases, you will need web hosting, as the version from WordPress.org is a self-hosted content management system. Most beginners opt for shared hosting which is great for newly created websites with low traffic. Shared hosting means that your website shares the same pool of resources as other sites on the same server. This lets hosting providers drive costs down dramatically.
The downside is that you will face performance issues as your website grows and generates more traffic. You will notice that your website is unavoidably slow resulting in poor user experience. When this happens, then it is time to upgrade to a better web hosting service.
Virtual Private Service or VPS hosting is often the next logical step for most website owners. It offers the users full control of their websites and is quite easy to manage if you got some CLI experience. Most VPS hosting services provide excellent support teams that give 24-hours support services to the user in case they encounter issues. But it is worth mentioning, that you should definitely access your technical skills before purchasing a VPS hosting solution.
There is a misconception that VPS hosting will tear through your wallet, but luckily that is not true, as there are cheap VPS hosting options out there, that have all the must-have features.
I will take you through a step by step process of installing WordPress on a Linux-based VPS. For this, you’ll need to gain access to your virtual private server through SSH. Pick your favorite SSH client, ours is PuTTY, install it, and you’re ready to go.
Installing WordPress on VPS
Now that you have your SSH client, and VPS credentials, let’s deploy WordPress on a VPS running CentOS7.
Step 1 – Download an SSH client
After you open PuTTY, you’ll need to type in your server’s IP address and port and select the SSH connection type.
After you finish typing, click Open.
Type root in the CLI that appears and then enter your VPS password. If this is done correctly, you will see your VPS name displayed on the screen.
Step 2 – Install a LAMP stack
Install an HTTP server, a database, and PHP using the command:
sudo yum install httpd mariadb mariadb-server php php-common php-mysql php-gd php-xml php-mbstring php-mcrypt php-xmlrpc unzip wget -y
This will download all necessary files and once it is done. This is called a LAMP stack – a software bundle for site and application management.
In this case, the LAMP stack is made up of:
- Linux – the operating system that the server is running.
- Apache – our chosen web server.
- MariaDB – a database system.
- PHP – the programming language that we will use.
Input the next commands to ensure the server initializes and boots up the applications, and keeps them running at all times.
sudo systemctl start httpd
sudo systemctl start mariadb
sudo systemctl enable httpd
sudo systemctl enable mariadb
Step 3 – Configure the database
To secure your database, enter the command (for this example, I am using MariaDB)
You will be prompted to enter the root user password. Leave it blank and tap the enter key so that you can set a new root password. Tap the Y key for all other options.
Log into your MariaDB account using the command:
mysql -u root –p
Then enter the root user password. Once you are in, run the next four commands in sequence and remember to replace the default username and password.
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES on wordpress.* to ‘user’@’localhost’ identified by ‘password’;
Now your database is set. We can proceed with installing WordPress.
Step 4 – Install WordPress
To deploy WordPress, enter and run the commands below in sequence. To download the latest version of WordPress and extract it to the root directory, enter the following commands:
tar -xzvf latest.tar.gz
sudo cp -avr wordpress/* /var/www/html/
Now you have to create an upload folder and assign the right permissions to it, so WordPress doesn’t run into privilege issues. Use the next command lines:
sudo mkdir /var/www/html/wp-content/uploads
sudo chown -R apache:apache /var/www/html/
sudo chmod -R 755 /var/www/html/
Next, you have to rename your WordPress wp-config-sample.php file with these commands:
sudo mv wp-config-sample.php wp-config.php
sudo nano wp-config.php
The last command will open the wp-config.php file with the nano editor. Here you will have to replace the following fields with the data you entered in Step 3 when you configured your database. This will include the database name, assigned user, and the password:
After updating the required fields press CTRL+O to save the changes, and CTRL+X to exit the editor.
Finally, configure your VPS to allow both HTTP and HTTPS connections using the commands:
sudo firewall-cmd –permanent –zone=public –add-service=http
sudo firewall-cmd –permanent –zone=public –add-service=https
sudo firewall-cmd –reload
After running these last commands, you will be able to access the WordPress Installer by opening your preferred browser and entering your VPS’ IP address like so – http://yourVPSIP.
There you will have to complete the standard WordPress setup, which will set up the site and create the administrator account. Make sure to do this quickly, as anyone that has your VPS IP can access the installer before you. While this is unlikely, it’s always better to be safe than sorry.
Congratulations you have successfully deployed WordPress on a virtual private server. Hopefully, this will put an end to any issues you may have been having with performance on your website. Good luck!