How to Install WordPress on any Cloud Sever on Ubuntu 18.04

Disclosure: Some of the links on this site are affiliate links, meaning that if you click on one of the links and purchase an item, I may receive a commission. All opinions however are my own.

After spending a long time on SSH console, Speed testing tools, and web hosting panels; I figured out a server stack that you can use to host a Fast WordPress website. Hosting a WordPress site is not a big task if you know how to get a shared hosting plan from Interserver. But when you want to ultimately control your web server and manage it at your own to host WordPress, you need to know the best stack.

install wordpress on any cloud server

Here’s what I have explained in this tutorial.

  1. Deploying a Linode cloud server with Ubuntu 18.04 (You can choose any other OS but Ubuntu is best)
  2. Nginx as Web Server
  3. Php7.4 FPM
  4. Installation of PhpMyAdmin and accessing it through your domain
  5. Installation of WordPress with the right permissions

LOGIN as root in putty, terminal or browser SSH terminal.

Start with the commands below.

I have also recorded the whole setup process in above 4 videos.

sudo apt-get update

This will update all the packages on my ubuntu machine.

sudo apt-get install nginx

Nginx server will be installed. Nginx is considered to be better than Apache when it comes to talking about performance; and that too when you run WordPress application only.

sudo apt-get install mysql-server

MySQL server installation will ask you to use storage on your machine. Give permissions by typing Y and enter.

Next, I will go ahead and setup the SQL server with the command below.

sudo mysql_secure_installation

Here, I will skip installing validate password module. Type any letter and enter.

Set a root database password. Type Y whenever it asks.

FLUSH PRIVILEGES;

exit;

For this article, I will install PHP 7.4 fpm because it is the latest version and recommended to run WordPress 5.4 on your server.

sudo apt-get install software-properties-common

sudo add-apt-repository ppa:ondrej/php

sudo apt-get install php7.4 php7.4-fpm php7.4-xml php7.4-mysql php7.4-gd php7.4-bz2 php7.4-cli php7.4-common php7.4-curl php7.4-json php7.4-mbstring php7.4-opcache php7.4-readline php7.4-zip

Lets

sudo nano /etc/php/7.4/fpm/php.ini

You will see a line ;cgi.fix_pathinfo=1, if the line is quoted, remove the quote “;” and replace ‘1’ with ‘0’

cgi.fix_pathinfo=0

Start the php7.4 module using the command below

service php7.4-fpm start

Using the below command, I will edit the default server block in the Nginx configuration.

sudo nano /etc/nginx/sites-available/default

server{
listen 80 default_server;
listen [::]:80 default_server;

root /var/www/html;
index index.php index.html index.htm index.nginx-debin.html;

server_name mydomain;

location / {
try_files $uri $uri/ /index.php$is_args$args;
}

location ~ \.php$ {
include snippets/fastcgi.php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}

location ~ /\.ht {
deny all;
}

}

You have to make sure every rule is not commented out. if the comments are there, just select the whole content on the file and replace with the above content. (after replacing the bold characters with your values)

sudo nginx -t

You can test the server block file for any syntax error using above commands. If the command returns “syntax is OK”, proceed to the next command and reload the Nginx Server.

sudo systemctl reload nginx

Now, the server is setup. Lets install PhpMyadmin

sudo apt-get update

sudo apt-get install phpmyadmin

Lets link to Phpmyadmin

sudo ln -s /usr/share/phpmyadmin /var/www/mydomain

sudo phpenmod mcrypt

Do not panic if the above command does not work. Let’s move the next.

sudo service php7.4-fpm restart

Let’s change the phpmyadmin dashboard location. I will simply navigate to my document rule and make a link to the phpmyadmin there.

cd /var/www/html

sudo mv phpmyadmin database

I have used database only to rename the phpmyadmin link inside the document root, you can use anything to keep it secret.

Open yourdomain/database to verify the install.


So far, we have installed Nginx, PHP 7.4 fpm, MySQL and phpmyadmin on the Ubuntu 18.04.

Now is the time to access your MySQL through SSH and create a database, a new database user, and grant all permissions to that user.

LOGIN to your server as root and enter the MySQL

sudo mysql -u root -p

Enter your MySQL root password and hit enter.


Lets create a database (below are SQL commands)

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

GRANT ALL ON wordpress.* TO ‘wpdbuser‘@’localhost’ IDENTIFIED BY ‘password‘;

You should replace the values in bold characters with your own values.

  • wordpress – your database name
  • wpdbuser – database user’s username
  • password – database user password

Now is the time to login to your database through the phpmyadmin console.


Let’s get the WordPresss files on your server.

Navigate to your document root

cd /var/www/mydomain/

sudo wget https://wordpress.org/latest.zip

Above command will download the latest version of WordPress right from the wordpress.org website. To make sure that the file is there on your server now, use the below command.

ls

The output should be – “latest.zip”

Unzip this file and create necessary files.

sudo apt-get update

sudo apt-get install zip unzip

cd /var/www/mydomain/

sudo unzip latest.zip

Above command will extract latest.zip in a directory named wordpress. Move the files in wordpress directory to the document root.

sudo mv wordpress/* /var/www/mydomain/

Remove the unnecessary files.

sudo rm -r latest.zip

Let’s set the ownership so that you can install themes and plugins from the WordPress dashboard.

chown -R www-data:www-data /var/www/mydomain

Open your browser and hit your domain in the address bar. You should see the WordPress Installation Screen.

Choose the language, Input values of the database, and Run the installation. You should now be able to visit your website on yourdomain.com and sign in to your WordPress.

Conclusion

You can host a WordPress site yourself with ease on Linode VPS or any other cloud VPS hosting provider. Please feel free to use comments to ask your questions and request more videos/tutorials.