Have a Question?
< All Topics
Print

Install WordPress on Debian 10

Tutorial on how to install WordPress on Debian 10

Nginx

Add the official NGINX repository to install the latest stable version (1.18)

$ sudo echo "deb http://nginx.org/packages/debian/ buster nginx" | sudo tee -a /etc/apt/sources.list.d/nginx.list
$ sudo echo "deb-src http://nginx.org/packages/debian/ buster nginx" | sudo tee -a /etc/apt/sources.list.d/nginx.list

Add NGINX public key

#Install wget in Debian 10 Minimal Server
$ sudo apt install wget -y
$ sudo wget http://nginx.org/keys/nginx_signing.key
$ sudo apt-key add nginx_signing.key

Update and install latest version of NGINX

$ sudo apt-get update
$ sudo apt install nginx

$ sudo nginx -v
nginx version: nginx/1.18.0

Enable NGINX to start automatically when system boot up

$ sudo systemctl enable nginx.service
$ sudo systemctl restart nginx
$ sudo systemctl status nginx

Backup the default NGINX configuration file

$ sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak

PHP 7.3

PHP 7.3 is the default PHP version in Debian 10

Install PHP FastCGI Processing Manager together with required PHP Extensions for WordPress

$ sudo apt install php-fpm php-mysql -y
#Install Extra PHP Extension for WordPress
$ sudo apt-get install php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip -y

Add the following PHP Configuration to the default Nginx Configuration File – /etc/nginx/conf.d/default.conf

$ sudo nano /etc/nginx/conf.d/default.conf

server {
    listen       80;
    #Replace the server_name to your own URL
    server_name  aventis.dev;
    #Specify the default location of root document
    root /usr/share/nginx/html;

    location / {
        root   /usr/share/nginx/html;
        index  index.php;
    }

    # Insert the PHP Configuration below
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html/UAT/$fastcgi_script_name;
        include fastcgi_params;
        }
}

# Create a info.php file in /usr/share/nginx/html
$ echo "<?php phpinfo();" | sudo tee -a /usr/share/nginx/html/info.php

#Add nginx user to www-data group
$ sudo usermod -aG www-data nginx

#Restart both nginx & PHP fpm services
$ sudo systemctl restart php7.3-fpm nginx

Go to http://IP-ADDRESS/info.php to verify PHP-FPM is configured properly

Install WordPress on Debian 10

MariaDB 10.3

Install MariaDB 10.3 Server

$ sudo apt install mariadb-server mariadb-client -y

#Set Root Password
$ sudo mysql

ALTER USER root@localhost IDENTIFIED VIA mysql_native_password;
SET PASSWORD = PASSWORD('P@ssw0rd!@#$');
flush privileges;
quit

#Secure MariaDB by enter "Y" for all options
$ sudo mysql_secure_installation

#systemctl enable mariadb
$ sudo systemctl enable mariadb

Login to MariaDB to verify version 10.3 is installed

$ sudo mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 58
Server version: 10.3.23-MariaDB-0+deb10u1 Debian 10

Prepare a Database called wordpress and a user called wpuser

sudo mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'XXXXXXXX';
GRANT ALL ON wordpress.* TO 'wpuser'@'localhost' IDENTIFIED BY 'P@ssw0rd!@#$' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

WordPress

Download the latest version of WordPress in /tmp

$ cd /tmp
$ sudo wget https://wordpress.org/latest.tar.gz
# Extract the latest.tar.gz to /tmp/wordpress
$ sudo tar -zxvf latest.tar.gz

Move the extracted /tmp/wordpress to a newly created new directory – /usr/share/nginx/wordpress

$ sudo mkdir -p /usr/share/nginx/wordpress
$ sudo mv wordpress/* /usr/share/nginx/wordpress/

#Grant ownership to www-data 
sudo chown -R www-data:www-data /usr/share/nginx/wordpress/
#Assign full permission to owner (www-data), and remove write permission for other users
sudo chmod -R 755 /usr/share/nginx/wordpress/

Modify the location of Root Document in /etc/nginx/conf.d/default.conf to point to /usr/share/nginx/wordpress/ and set index to index.php only

$ sudo nano /etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  aventis.dev;
    root /usr/share/nginx/wordpress;

    location / {
        root   /usr/share/nginx/wordpress;
        index  index.php;
    }

Create a wp-config.php file from /usr/share/nginx/wordpress/wp-config-sample.php

$ sudo cp /usr/share/nginx/wordpress/wp-config-sample.php /usr/share/nginx/wordpress/wp-config.php

Add DB Connection in wp-config.php

$ sudo nano /usr/share/nginx/wordpress/wp-config.php 

 // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define( 'DB_NAME', 'wordpress' );

    /** MySQL database username */
    define( 'DB_USER', 'wpuser' );

    /** MySQL database password */
    define( 'DB_PASSWORD', 'P@ssw0rd!@#$' );

Restart both Nginx & PHP-FPM

$ sudo systemctl restart php7.3-fpm nginx

SSL Support in Nginx

Generate a Let’s Encrypt Free Wildcard SSL Certificate by following this link

Switch to root account and copy fullchain.pem & privkey.pem to /etc/nginx/ssl

$ su -
$ sudo mkdir -p /etc/nginx/ssl
$ sudo cp /etc/letsencrypt/live/aventis.dev/fullchain.pem /etc/nginx/ssl/fullchain.pem
$ sudo cp /etc/letsencrypt/live/aventis.dev/privkey.pem /etc/nginx/ssl/privkey.pem

Enable HTTPS & HTTP/2 support in /etc/nginx/conf.d/default.conf

$ sudo nano /etc/nginx/conf.d/default.conf
  
  listen 443 ssl http2;
  ssl_certificate /etc/nginx/ssl/fullchain.pem;
  ssl_certificate_key /etc/nginx/ssl/privkey.pem;

Verify there is no error found in Nginx configuration file and reload nginx service

$ sudo nginx -t 
$ sudo systemctl reload nginx

Setup WordPress

Go to https://aventis.dev to complete the WordPress setup in GUI

Enter Site Name, Username, Password and Email Address and click Install WordPress

Click Log In to login to WordPress

413 Request Entity Too Large

By default, Nginx has a limit of 1MB on file upload, and we can increase the file upload limit to 10MB

$ sudo nano /etc/nginx/conf.d/default.conf
    client_max_body_size 10M;

# Restart Nginx
$ sudo systemctl reload nginx

Briefly unavailable for scheduled maintenance. Check back in a minute.

Refer to How to Fix Briefly Unavailable for Scheduled Maintenance Error on WordPress for more information

Login to Debian to delete to .maintenance file to force WordPress from returning to normal mode

$ sudo rm /usr/share/nginx/wordpress/.maintenance

Prismjs with WordPress

Download prism.js & prism.css from https://prismjs.com/ and upload it to wordpress theme folder

$ sudo cp /tmp/prism.js /usr/share/nginx/wordpress/wp-content/themes/astra-child
$ sudo cp /tmp/prism.css /usr/share/nginx/wordpress/wp-content/themes/astra-child

Add the PHP Function

$ sudo nano /usr/share/nginx/wordpress/wp-content/themes/astra-child/functions.php

function add_prism()
{
    wp_enqueue_style( 'prism-css',  get_stylesheet_directory_uri() . '/prism.css' );
    wp_enqueue_script( 'prism-js',  get_stylesheet_directory_uri() . '/prism.js', [], false, true );
}

add_action( 'wp_enqueue_scripts', 'add_prism' );

Restart Nginx Service

$ sudo systemctl reload nginx

Codes is highlighted by Prism successfully

Refer to PrismJS (syntax highlighter) with WordPress for more information

Table of Contents
Scroll to Top