Skip to content

Installation

Connect to the instance with ssh:

ssh debian@<IP_ADDRESS>

Upgrade the server:

sudo apt update && apt upgrade -y

Apache

apt-get install apache2  -y
systemctl start apache2
systemctl enable apache2

PHP8

apt-get install gnupg2 ca-certificates apt-transport-https software-properties-common -y
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
wget -qO - https://packages.sury.org/php/apt.gpg | apt-key add -
apt-get update -y
apt-get install php libapache2-mod-php php-pear php-cgi php-common php-mbstring php-zip php-net-socket php-gd php-xml-util php-php-gettext php-mysql php-bcmath unzip wget git -y

MariaDB

apt-get install mariadb-server mariadb-client -y
systemctl start mariadb
systemctl enable mariadb
Configure MariaDB for WordPress:
sed -i s/127.0.0.1/0.0.0.0/ /etc/mysql/mariadb.conf.d/50-server.cnf
systemctl restart mariadb.service

Create database:

mysqladmin -u root password
mysql -u root --password=<DB_ROOT_PASSWORD>
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"%" IDENTIFIED BY "<DB_PASSWORD>";
FLUSH PRIVILEGES;
EXIT

Warning

Don't forget to change <DB_ROOT_PASSWORD> and <DB_PASSWORD>

WordPress

Download last release:

cd /var/www/html
wget https://wordpress.org/latest.zip
unzip latest.zip
mv wordpress <DOMAIN_NAME>
chown -R www-data:www-data /var/www/html/<DOMAIN_NAME>

Configure WordPress with database:

cd <DOMAIN_NAME>
cp wp-config-sample.php wp-config.php
sed -i s/database_name_here/wordpress/ wp-config.php
sed -i s/username_here/wordpress/ wp-config.php
sed -i s/password_here/<DB_PASSWORD>/ wp-config.php

Warning

Don't forget to change <DOMAIN_NAME>

Configure Apache

Create the configuration file <DOMAIN_NAME>.conf:

<VirtualHost *:80>
    ServerAdmin <EMAIL>
    ServerName <DOMAIN_NAME>

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ $NDD/$1 [L,R=301]
    RewriteCond %{SERVER_NAME} = <DOMAIN_NAME>
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:443>
    ServerAdmin <EMAIL>
    DocumentRoot /var/www/html/<DOMAIN_NAME>

    ServerName <DOMAIN_NAME>

    <Directory /var/www/html/>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Warning

Don't forget to change <EMAIL> and <DOMAIN_NAME>

a2ensite <DOMAIN_NAME>
a2enmod rewrite
systemctl restart apache2

Warning

Don't forget to change <DOMAIN_NAME>

Add SSL with CertBot

Warning

Before add SSL, redirect your domain name to server IP !

Installation:

apt-get install certbot python3-certbot-apache -y

Generate certificate:

certbot -n --apache --agree-tos --redirect --hsts --uir --staple-ocsp --email <EMAIL> -d <DOMAIN_NAME>

Warning

Don't forget to change <EMAIL> and <DOMAIN_NAME>

Add to cronjob:

echo "@daily certbot renew --quiet &amp;&amp; systemctl reload apache2" >> /etc/cron.d/ssl
systemctl restart cron

Your WordPress instance is online!

final.png

Back to top