Setting up Wordpress

2 minutes read

Priliminary Setup

Set hostname

sudo vim /etc/hostname

For example the put the following line as hostname.

myserver

Setup /etc/hosts

sudo vim /etc/hosts

For example the put the following line as hosts.

127.0.0.1 localhost
:: localhost
127.0.1.1 wordpress mywebsite.com

Create New User

sudo useradd -m -g users -G sys,adm -s /bin/bash dev

sudo passwd dev

Add the user to sudo

sudo usermod -aG sudo dev

Wordpress Setup

Install packages

sudo apt install -y mariadb-server apache2 apache2-utils unzip imagemagick libmagickcore-6.q16-6-extra libapache2-mod-php php-imagick php-curl php-gd php-intl php-mbstring php-mysql php-soap php-xml php-zip
sudo systemctl status apache2

Setup MariaDB

sudo systemctl status mariadb # It should be active and running.
sudo mysql_secure_installation

For the unix_socket authentication we can answer no. That will enable standard authentication and will work just fine.

sudo mariadb -u root -p
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE IF NOT EXISTS db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
SHOW DATABASES;
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress'@'localhost';
FLUSH PRIVILEGES;
quit;

Download and Extract WordPress

cd /var/www

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

sudo unzip latest.zip

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

Add a configuration file for WordPress to Apache

sudo vim /etc/apache2/sites-available/wordpress.conf
<VirtualHost *:80>
    DocumentRoot /var/www/wordpress
    <Directory /var/www/wordpress>
        Options FollowSymLinks
        AllowOverride All
        DirectoryIndex index.php
        Require all granted
    </Directory>
    <Directory /var/www/wordpress/wp-content>
        Options FollowSymLinks
        Require all granted
    </Directory>
</VirtualHost>

sudo a2dissite 000-default.conf

sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

After all of that, access your site and then fill out form in the web browser. Then, you’re all set!