How to Install WordPress?

This article will teach you how to install a fresh WordPress instance. We will assume that the server is secured and has apache2 and MySQL server already installed.

let’s begin…

Setting up MySQL server

We will begin with creating a MySQL Database

sudo mysql -u root -p 

Enter your password for the root user.

If you did not setup a password you can login to mysql simply as follows. But you should know that this is less secured.

sudo mysql

We will now create a Data Base called “wordpress” (you can name it whatever you want).

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

We will now create a new user called “wordpressuser” (you can name it whatever you want).

Please remember to change the password to a unique and strong password.

CREATE USER 'wordpressuser'@'%' IDENTIFIED WITH mysql_native_password BY '<secret password>';

We will give the new user access to the new database

GRANT ALL ON wordpress.* TO 'wordpressuser'@'%';

Finally

FLUSH PRIVILEGES;
exit;

Installing WordPress

It is a very simple process of downloading files, small edits and copying them in the correct directory. but first we need php extensions

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

Restart apache2

sudo systemctl restart apache2

We need to enable .htaccess overrides

sudo vim /etc/apache2/sites-available/<domain name>.conf

We need to add these rules to the configuration file. copy and paste the following

NOTE: you need to place outside of the VirtualHost tag

<Directory /var/www/<domain name>/>
    AllowOverride All
</Directory>

Run

sudo a2enmod rewrite 

Now to enable the changes

sudo apache2ctl configtest

If OK

sudo systemctl restart apache2

Now we will download WordPress packages. I like to do it in the “/tmp” folder

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

Create .htaccess for the apache to be happy

touch /tmp/wordpress/.htaccess

Copy the example to the wp-config.php

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

Create a upgrade folder

mkdir /tmp/wordpress/wp-content/upgrade

Copy the downloaded  files to the right place

sudo cp -a /tmp/wordpress/. /var/www/<domain name>

Finally we need to set the right permissions to the folder

sudo chown -R www-data:www-data /var/www/<domain name>
sudo find /var/www/<domain name>/ -type d -exec chmod 750 {} \;
sudo find /var/www/<domain name>/ -type f -exec chmod 640 {} \;

Setting up WordPress config file

Run the following command in your terminal

curl -s https://api.wordpress.org/secret-key/1.1/salt/

This will generate unique key for the WordPress instance

open “wp-config.php” file with your favorite editor. I use VIM.

sudo vim /var/www/<domain name>/wp-config.php

Copy and Paste the output of the previous command in this file. And delete the placeholders.

Finally Edit the PHP Variables.

DataBase name

define( 'DB_NAME', 'wordpress' );

DataBase username

define( 'DB_USER', 'wordpressuser' );

DataBase password

define( 'DB_PASSWORD', 'password' );

THANK YOU

If you find any mistakes in this guide please leave a comment below.

Leave a Comment