Install WordPress on a virtual private server

How to Install WordPress on a Virtual Private Server

WordPress is usually the first choice for everyone who wants to start a simple or standard website. But choosing a hosting service that suits you and suits your needs is a different story. There are various options out there; there’s dedicated hosting, which is usually more suited to corporates; there’s shared hosting, which is the very starting point for many websites; there’s Virtual Private Server or VPS suited for most purposes; and there’s even Managed WordPress Hosting, for more convenience.

Which of these solutions works best for you, depends on the kind of website you want to create, how much traffic you are going to have on it, and how much control you want on it.

For most purposes, from a personal website to a business website to an online business, a VPS works fine. On a VPS you will have more control than on managed hosting, which actually helps with managing certain aspects of your website. It’s not as convenient, but it’s not hard at all. WordPress is easy to manage, and you just need to know how to install WordPress on a VPS server to start creating your own website.

How to Install WordPress on a VPS Hosting?

WordPress is the most popular content management system (CMS) in the world and is quite easy to handle. There are a lot (a lot!) of plugins for WordPress that can help you manage every aspect of creating, maintaining, optimizing and upgrading your website. You just first need to install WordPress on your VPS or other hosting plan.

There are various methods for installing WordPress CMS on your website, depending on the type of hosting and how much control you have on it, and your host’s operating system (Windows, Linux, or the BSD family.)

Different ways and steps to install WordPress on a VPS hosting:

  • Installing WordPress on a VPS using LAMP (prerequisites)
  • Getting ready: installing Apache 2 on a VPS
  • Getting ready: installing MySQL on a VPS
  • Getting ready: Installing PHP on a VPS
  • Getting ready: Secure SSL
  • Installing WordPress on a Ubuntu 18.04 VPS (LAMP)
  • Installing WordPress on a CentOS 7 VPS (with MariaDB)
    • How to connect to your VPS through SSH with PuTTY
  • Creating .htaccess file

 

How to Install WordPress on a Virtual Private Server Using LAMP Stack

WordPress can be installed in many ways, a common way is using LAMP stack. This method is mostly used when you want to have full control on your WordPress backend, whether for experimentation or for advanced users.

LAMP stands for Linux, Apache, MySQL, and PHP. Linux is the common operating system for hosting a WordPress website, used together with the Apache web server and MySQL database, using PHP to process and serve a dynamic website.

Before starting the process, you need to have access to your VPS server through SSH. We will show you how you can connect to your VPS using PuTTY.

We assume you already have a Linux distribution installed on your VPS. We first go through the steps for installing WordPress on Linux Ubuntu 18.04 VPS, and then once again show the steps for installing WordPress on a CentOS 7 VPS, but this time with MariaDB as the database.

Before continuing, let’s first learn how to install Apache 2 on your server.

 

How to Install and Configure Apache 2

LAMP uses the popular Apache 2 web server. With the commands below, you can install Apache using Ubuntu’s package manager:

sudo apt update
sudo apt install apache2

For these commands to work, you’ll need to enter your password. Press Y to give ok and then press ENTER to continue installing.

READ
How to Optimize WordPress VPS?【8 Tips To Speed UP】

UFW firewall is available on all Ubuntu installations by default. The UFW firewall should allow HTTP and HTTPS traffic. If you don’t use UFW, you can skip this level, but if you do, you need to check your UFW profile:

sudo ufw app list

This command will show an output like the below:

Available applications:
 Apache
 Apache Full
 Apache Secure
 OpenSSH

To allow HTTP and HTTPS traffic for Apache Full profile, you can execute the command below:

sudo ufw allow in "Apache Full"

To confirm this, have a look at this profile information by using:

sudo ufw app info "Apache Full"

To verify if Apache was installed correctly, you would need the public IP address. You can get it by using the command below:

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

This command will provide you with 2-3 IPs. You might have to try all of this by using http://[YourPublic_IP_Address] on a browser. It will display the default Ubuntu Apache page.

 

How to Install MySQL

Once you have the webserver running, you can install the MySQL database. Use the command below to start:

sudo apt install mysql-server

This command will ask you for a password. Once the installation starts, press Y to confirm the command and then press ENTER to continue installing.

After installation is finished, open MySQL terminal using:

sudo mysql

You can set a password for the root user using the command below:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Password;

To reflect these changes, use the Flush command, as shown below:

mysql> FLUSH PRIVILEGES;

You can type exit to come back from the MySQL prompt. This completes the MySQL installation.

 

How to Install PHP

To display dynamic content, you need PHP which you can install by using:

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

Install Additional PHP extensions for WordPress using the command below:

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

When you request a directory, the index.html is displayed as a default setting. In case you want to show index.php instead of index.html, you need to open the dir.conf file using the vi editor:

sudo vi /etc/apache2/mods-enabled/dir.conf

It will look like this:

<IfModule mod_dir.c>
   DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

Swap the positions of index.html and index.php and save the file.

For the changes to be visible, restart the Apache server using:

sudo systemctl restart apache2

To test the PHP, you can create a sample PHP file sample.php and add these lines of code:

<?php
phpinfo();
?>

This file needs to be added to the Web Root of Apache which is located at –

/var/www/html/

Once this is saved, you can try to access this page by using http://[YourPublic_IP]/Sample.php.

 

Secure Your Site with SSL

WordPress serves dynamic content and handles user authentication and authorization. TLS/SSL is the technology that allows you to encrypt the traffic from your site so that your connection is secure. The way you set up SSL will depend on whether you have a domain name for your site.

State 1: If you have a domain name… the easiest way to secure your site is with Let’s Encrypt, which provides free, trusted certificates.

State 2: If you do not have a domain… and you are just using this configuration for testing or personal use, you can use a self-signed certificate instead. This provides the same type of encryption, but without the domain validation.

 

How to Install WordPress on Your Ubuntu 18.04 VPS

You may have chosen to install Ubuntu on your VPS as your operating system of choice. In that case, you can follow these steps to install WordPress on your Ubuntu VPS server.

 

Step 1: Switch to the tmp Folder and Download the Latest Version of WordPress

First things first, We need to download the latest WordPress release from https://wordpress.org/latest.tar.gz. To do this, you can type the commands below on a terminal window:

$ cd /tmp
$ curl -O https://wordpress.org/latest.tar.gz

Step 2: Unzip the tar Archive

$ tar  -xzvf latest.tar.gz

After unzipping the package, a WordPress folder is created on the path /tmp/wordpress.

Step 3: Move the Directory to the Root of Your Website

In order for WordPress to work, we will need to move its directory to the root folder of our website using the command below:

$ sudo mv wordpress /var/www/html/wordpress

Step 4: Change Ownership and Set Permissions for WordPress Directory

In order for Apache to access WordPress, we need to change the ownership of the directory to www-data using the command below:

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

Then we need to set the right file permissions using the commands below:

$ sudo chmod -R 755 /var/www/html/wordpress/

Step 5: Open MySQL Server and Create a Database for WordPress

WordPress relies on a MySQL database. In order to create one we can use the commands below:

$ sudo mysql -u root -p

Enter your password and press Enter.

READ
How to Optimize WordPress VPS?【8 Tips To Speed UP】

Then enter the commands below, remember to replace the database, user and password with your own values:

CREATE DATABASE wp_database DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL PRIVILEGES ON wp_database.* TO 'wp_user'@'localhost' IDENTIFIED BY 'enterpasswordhere';
FLUSH PRIVILEGES;
EXIT;

Step 6: Open WordPress Configuration file and Edit it

When you installed WordPress, a default configuration file was created. We need to move the file and set the database configurations using the commands below:

$ sudo mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php

Then we need to edit the file using our nano editor using the command below:

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

You will see a screen similar to the image below, enter the correct database name, user and password:

How to Install WordPress on a VPS Hosting - 2

When you are done, press CTR+X and Y to save the changes and exit the editor.

Step 7: Finalize the WordPress Installation

Next, you need to visit the new WordPress site using the public IP address or domain name on your browser to finalize the configuration.

Since we installed our WordPress on a sub-folder, we will have to visit www.example.com/wordpress for our site to work.

A screen similar to the one below will be displayed and we can click continue to finish the installation:

If you get the error “Your PHP installation appears to be missing the MySQL extension which is required by WordPress” then You will need to install all PHP modules required for the functioning of WordPress using the command below:

$ sudo apt-get install php-cli php-common php-mbstring php-gd php-intl php-xml php-mysql php-zip php-curl php-xmlrpc

Then, restart Apache using the command below:

$ sudo service apache2 restart

Then, visit your WordPress site one more time to finalize the installation.

How to Install WordPress on a CentOS 7 VPS Manually (In 4 Steps)

Regardless of what options are provided in your VPS hosting control panel, you can always install WordPress on your VPS manually. Following, we will go through the steps of installing WP on your VPS running CentOS 7.

Step #1: Connect to Your VPS via SSH

After you receive your VPS hosting plan details from your hosting provider, you need two things before starting to install WordPress:

  1. Your server’s root password or a user with sudo rights;
  2. An SSH client software such as PuTTY to connect to your VPS server.

You need to install PuTTY before starting. After installing and opening PuTTY, you’ll see a section where you enter your destination server’s name or IP address. The default port number remains 22.

How to Install WordPress on a VPS Hosting - 3

Under connection type, choose SSH. A command window will pop up, where you can log into your server using your credentials. Enter root as your user, or another user name with sudo rights; then press enter. Next, enter the password for that user (root password, if you’re using that.)

Step #2: Install the Software You Need to Run WordPress

To run WordPress, you need an HTTP server, a database, and PHP. For the sake of this tutorial, we will first show you how to install Apache, MariaDB, and the latest version of PHP. You can install all the necessary packages with a single command. Run the following commands in your command window:

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

How to Install WordPress on a VPS Hosting - 4

With this command, your server starts downloading and installing all the prerequisites you requested. It may take a few minutes. When everything’s ready, your server is ready to receive more commands.

READ
WordPress SSH – Secure Remote WordPress Access

Now that the underlying software is installed, you need to set it up so that they are run every time the server boots up. These are the commands for the job:

sudo systemctl start httpd
 sudo systemctl start mariadb
 sudo systemctl enable httpd
 sudo systemctl enable mariadb

Now all is left before installing WordPress on your VPS and start using it, is to configure your database.

Step #3: Configure MariaDB and Create a WordPress Database

In this step, we are going to create a database for the website. But security of the database is one of the most important things about a website, so before all else, you are going to ‘secure’ your MariaDB isntallation. To begin, enter the following command:

sudo mysql_secure_installation

Afterward, MariaDB will ask you for its root user password, which should be blank, so just hit the enter key. Then, you’ll be able to set a new root password. For the rest of the settings, hit Y for yes; particularly enter yes for number three, which disallows remote logins.

Now you can login into your MariaDB account using the following command and the password you just set a few moments ago:

mysql -u root -p

After you log in, you need to enter and run four commands one by one. Each line below is a separate command. (Remember that ‘user’ and ‘password’ in the following lines are placeholders for your actual user name and password.)

CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES on wordpress.* to 'user'@'localhost' identified by 'password';
FLUSH PRIVILEGES;
exit

That’s it! Your database is ready to use.

Step #4: Install and Run WordPress

Now that the infrastructure is ready, the last step is to download and install WordPress, and then configure it. Let’s get started with a few quick commands to download the latest version of the platform, extract its files, and move them to your root directory. (Keep in mind that each line below is an individual command, run separately):

wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
sudo cp -avr wordpress/* /var/www/html/

Now let’s create an Uploads folder for your installation and assign the correct permissions to your files and folders using the following two commands:

sudo mkdir /usr/local/lsws/Example/html/wordpress/wp-content/uploads
sudo chown -R apache:apache /var/www/html/
sudo chmod -R 755 /var/www/html/

Finally, let’s rename your WordPress wp-config-sample.php file:

cd /var/www/html/
sudo mv wp-config-sample.php wp-config.php

Now we’re going to configure the WordPress installation to connect to the database. The next command will open the WordPress configuration file using the nano editor within the command line:

sudo nano wp-config.php

Now, just navigate the file using your keyboard arrows and replace the following fields with the same data you entered during step number three:

define('DB_NAME', 'wordpress');
define('DB_USER', 'user');
define('DB_PASSWORD', 'password');

After updating those fields, type CTRL+O and CTRL+X on your keyboard. These shortcuts will save the changes you made to the file and close the nano editor.

All that’s left to do now is to configure your VPS to allow HTTP and HTTPS connections, with these commands:

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd –reload

Once you run them, you’ll be able to access the WordPress installer by visiting your VPSs, just enter your VPS IP address after https://.

Creating .htaccess File

The file WordPress.conf will be the Apache configuration file for this testing. In the file, you can enable .htaccess by adding these lines to the VirtualHost block:

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

Once this is edited, save the file.

Here you can create a .htaccess file:

vi /tmp/wordpress/.htaccess

Save the file.

Summary

There are many ways to install WordPress on your VPS server. The most common combination for its backend is LAMP stack, which stands for Linux (operating system), Apache (web server), MySQL (database), and PHP.

We showed how you can install WordPress on Ubuntu 18.04 using LAMP stack. To do that, we explained how you can install Apache 2, MySQL, and PHP on your VPS to get it ready. We also showed how you can connect to your VPS server through SSH using PuTTY to do all of these stuff.

In addition to that, we also showed the steps to install WordPress on a CentOS 7 VPS, this time using MariaDB instead of MySQL.

0 0 vote
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
quba sen

This is a really very helpful post, to install wordpress on my system

1
0
Would love your thoughts, please comment.x
()
x