CMS
WordPress

WordPress

WordPress is an open-source Content Management System (CMS) used to create and manage various types of websites, such as blogs, corporate sites, online stores, and news portals. WordPress was first released in 2003 by Matt Mullenweg and Mike Little, with an initial focus on a blogging platform. However, over time, WordPress has become one of the most popular CMS platforms globally, supported by a vast ecosystem of themes, plugins, and a global community.

WordPress is known for its ease of use, flexibility in customization, and extensive support from a global community. Built using PHP and utilizing MySQL/MariaDB as its database, WordPress offers a variety of features such as the block editor (Gutenberg), content management, SEO-friendly capabilities, and plugin support to add extra functionality.

1. System Requirements

System requirements for WordPress:

  • PHP 7.4+
  • MySQL 8.0+ or MariaDB 10.5+
  • Nginx or Apache with mod_rewrite
  • HTTPS support

Before starting the deployment, prepare:

  • A VPS or server with Ubuntu LTS OS
  • SSH access to the server
  • A domain already pointed to the server

2. Server Preparation

Update the system

sudo apt update 
sudo apt upgrade -y

Install MariaDB

sudo apt install mariadb-server -y

Add the PPA ondrej/php repository

sudo add-apt-repository ppa:ondrej/php -y
sudo apt update 
sudo apt upgrade -y

Install PHP 8.3 and the required extensions

sudo apt install php8.3 php8.3-cli php8.3-common \
  php8.3-apcu php8.3-mbstring php8.3-gd php8.3-intl \
  php8.3-xml php8.3-soap php8.3-bcmath php8.3-mysql php8.3-zip \
  php8.3-curl php8.3-tidy php8.3-imagick php-pear -y

Install WP-CLI

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

3. Create Database

Log in to MariaDB

sudo mysql

Create a database contohcom and user 'contohcom'@'localhost'

CREATE DATABASE contohcom;
CREATE USER 'contohcom'@'localhost' IDENTIFIED BY 'rahasia';
GRANT ALL PRIVILEGES ON contohcom.* TO 'contohcom'@'localhost';
FLUSH PRIVILEGES;
EXIT;

4. Web Server Configuration

Apache

Install Apache

sudo apt install apache2 libapache2-mod-php8.3 -y

Create a virtual host

sudo nano /etc/apache2/sites-available/contoh.com.conf

Enter the configuration

<VirtualHost *:80>
    ServerName www.contoh.com
    ServerAlias contoh.com
    DocumentRoot /var/www/contoh.com
    <Directory /var/www/contoh.com>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog /var/log/apache2/contoh.com_error.log
    CustomLog /var/log/apache2/contoh.com_access.log combined
</VirtualHost>

Enable the module and virtual host

sudo a2enmod rewrite
sudo a2ensite contoh.com.conf
sudo systemctl restart apache2

Install certbot for Apache

sudo apt install certbot python3-certbot-apache -y

Request an SSL certificate

sudo certbot --non-interactive \
    -m [email protected] \
    --agree-tos \
    --no-eff-email \
    --apache -d contoh.com -d www.contoh.com \
    --redirect	

Nginx

Install Nginx

sudo apt install nginx php8.3-fpm -y

Create a virtual host

sudo nano /etc/nginx/sites-available/contoh.com.conf

Masukkan konfigurasinya

server {
    listen 80;
    server_name www.contoh.com contoh.com;
    root /var/www/contoh.com;
    index index.php;

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

    location ~ \.php$ {
        try_files $fastcgi_script_name =404;
        include fastcgi_params;
        fastcgi_pass unix:/run/php/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param DOCUMENT_ROOT
        $realpath_root;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    }

    access_log /var/log/nginx/contoh.com_access.log;
    error_log /var/log/nginx/contoh.com_error.log;
}

Enable the virtual host

sudo ln -s /etc/nginx/sites-available/contoh.com.conf /etc/nginx/sites-enabled/
sudo systemctl restart nginx

Install certbot untuk Nginx

sudo apt install certbot python3-certbot-nginx -y

Request an SSL certificate

sudo certbot --non-interactive \
    -m [email protected] \
    --agree-tos \
    --no-eff-email \
    --nginx -d contoh.com -d www.contoh.com \
    --redirect	

4. Install WordPress

Create a directory for WordPress with the domain name contoh.com

cd /var/www
mkdir contoh.com
cd contoh.com

Download WordPress

sudo wp core download --allow-root 

Create the wp-config.php configuration file

sudo wp config create \
    --dbname="contohcom" \
    --dbuser="contohcom" \
    --dbpass="rahasia" \
    --dbhost="localhost" \
    --allow-root

Install WordPress

sudo wp core install \
    --url="https://www.contoh.com" \
    --title="Contoh.Com" \
    --admin_user="admin" \
    --admin_password="password" \
    --admin_email="[email protected]" \
    --allow-root

Change the user and group of the directory

sudo chown -R www-data:www-data /var/www/contoh.com

WordPress installation is complete. Access https://www.contoh.com to test the results.