Build Your WordPress Site with 0 Fee.

WorkPress is the most popular CMS in the market. You can build your own website on top of that and you need only web server. In this article Im going to explain how to deploy WordPress application on your Ubuntu server. So I use AWS Ubuntu box which is under Free tier for this.

Setup Cloud Server

Create an account on AWS cloud service using below link.

https://aws.amazon.com/console/

Select AWS region nearest to your country.

In main window, Click on EC2 and then in detail page, click on Instances.

Now click on Lunch Instance and you will get a page to create Server. In there, click on Free tier only checkbox and it will show all boxes available on free tier. For this article I have chosen Ubuntu Server 18.04 LTS (HVM), SSD Volume Type which has 1 vCPU, 1GB RAM and 8GB SSD storage.

Other than, all option select as default value and remember to choose Auto-assign Public IP Enabled. Because We need a public IP to access website from your PC.

At the end, you have to download the SSH key pair, later you can use to login to web server using terminal.

Setup WordPress – Few Steps to follow

Install and Configure Apache 2

First update all packages in virtual machine using below command.

sudo apt update

Install Apache Web Server on it using below command

sudo apt install apache2

After install Apache server, you grab the Public IP from the AWS Server and type on your browser. http://<public id> . So you will see the apache server home page. If you face any issue, then follow below step to skip the firewall.

Troubleshoot

By default Ubuntu comes with UFW firewall. so you have to configure some rules if you can’t access apache home page.

Execute below command to see UFW application profiles 

sudo ufw app list

You will see result something like this.

Available applications:
 Apache
 Apache Full
 Apache Secure
 OpenSSH

To allow HTTP and HTTPS traffic for Apache Full profile, execute below command.

sudo ufw allow in "Apache Full"

You can test it using your bowser http://<public id>

Install MySQL

To install mysql, execute blow command

sudo apt install mysql-server

To open mysql terminal, execute below command

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 'Your Password';

To apply changes immediately, execute below command

mysql> FLUSH PRIVILEGES;

Install PHP

Execute blow command to install basic module for running php page.

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

To test the php is working or not, you can execute below command to create test.php file

sudo nano /var/www/html/test.php

It will open up text editor and add these lines into it and save.

<?php
phpinfo();
?>

Now in your bowser, type this url http://<public id>/test.php. if everything configured properly. You will get PHP information page.

Setup MySQL for WordPress

Login into MySQL Terminal,

mysql -u root -p

It will prompt password to enter, if everything is ok, you will be in MySQL terminal.

To Create new Database, execute below command.

mysql> CREATE DATABASE <New Database name> DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Create separate user for that database, so that WordPress will use that user to access the database. This is more about security concern.

To create new user, execute below command

mysql> GRANT ALL ON <Database name>.* TO 'NewUserName'@'localhost' IDENTIFIED BY 'NewPassword';

To propagate changes immediately,

mysql> FLUSH PRIVILEGES;

Install WordPress on Ubuntu

Configuration on Apache

To redirect all request to new website, you have to edit site config file.

sudo nano  /etc/apache2/sites-available/000-default.conf

Change DocumentRoot /var/www/ to new folder you going to create for website.

Now You can enable the mod_rewrite to use the WordPress permalink feature. This can be done using

sudo a2enmod rewrite

After these config changes, execute below command to restart the apache service

sudo systemctl restart apache2

Deploy WordPress site

Execute below command to create folder in tmp and download WordPress package from WordPress.org

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

Extract files using

tar xzvf latest.tar.gz

.htaccess which is a hidden file used to configure additional features for websites hosted on Apache Web Server.

Create file using below command and add few lines onto it.

sudo nano /tmp/wordpress/.htaccess

Add below lines and Save it.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress


To rename wp-config-sample.php file, execute below command.

mv /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

Now all files are ready to copy into www folder. For that execute below command.

sudo cp -a /tmp/wordpress/. /var/www/wordpress


Grant permission on apache server to access this folder

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

Also grant permission you to access this folder using execute below command.

sudo find /var/www/wordpress/ -type d -exec chmod 750 {} \;
sudo find /var/www/wordpress/ -type f -exec chmod 640 {} \;


Also you need to generate WordPress salt and place that info in wp-config.php file.

To generate salt

curl -s https://api.wordpress.org/secret-key/1.1/salt/
define('AUTH_KEY',         'Q?5II IiN`Q L+[wE@&Zkt;Ge`e_Smfrt~asL6``C#O3%O6jZX=YO71&*+qTg /C');
define('SECURE_AUTH_KEY',  '}i5TP0m~M?GVkd_06LUXNQD&UU_RCz*Xhg+m##?2UsD/e|dk-=zIPaGPXhFeC@-M');
define('LOGGED_IN_KEY',    'dzsF)dAkstzrA3hdnLN^Yi|#Go>h6X&dccS$YUS:.4_knIk?{S~-t>)oU8+YR|q9');
define('NONCE_KEY',        'bH--dT*@6z?4kglB/#++=+2f2yFe<ufF}-{)>ZU : :`M=Aai^ZF<%-&oMDZ(J&0');
define('AUTH_SALT',        'L7 urD`;c(ZhC*|J;&6B6Fl=-A0JT)e-6g{6~-P(45(*O e(!j+:=_*<]?0ty&T$');
define('SECURE_AUTH_SALT', '*FNX>9SoKo;M,[ctz*X?M:fGn$*R?.UP$DkxnrkldB8R;g+x$]?sR.q_c%[!q-ox');
define('LOGGED_IN_SALT',   'I)TKb5+liM:uhJSw:Zz)@y9AM4!Jr`h/2W[!`@d*-<6H9[:Tz;@<V]u+%L@B-F2f');
define('NONCE_SALT',       'i:jpB[cxA|9M}([=go|73?7C5V/~lnQl(>/T5CMPIBYhl/i(lb)-/`g=6*-6uuMB');

You need to copy and past over to wp-config.php file using below command.

sudo nano vi /var/www/wordpress/wp-config.php


Also you need to update the database connection in wp-config.php file.

define('DB_NAME', 'NewDatabaseName');
/** MySQL database username */
define('DB_USER', 'NewUser');
/** MySQL database password */
define('DB_PASSWORD', 'NewPassword');

Add following line at very bottom of wp-config.php file

define('FS_METHOD', 'direct');

Now save wp-config.php file.

To restart apache server

sudo systemctl restart apache2

Congratulation !, now you have configured WordPress side in cloud server, to access web site in your browser type http://<public id>

Wrap Up

Now you know how to setup WordPress website on Ubuntu Server. You can find many amazing plugins and features on https://wordpress.org/plugins/

Leave a Reply