Setup a WordPress Website on Debian Based Linux

WordPress Logo

Setup a WordPress Website on Debian Based Linux

How to setup a WordPress website on Linux server that is based on Debian Linux

WordPress LogoAWS LogoAWS EC2 LogoMySQL LogoUbuntu Logo

Install WordPress on a Debian Based Linux Distribution

How to install WordPress on Debian based Linux distributions. Ubuntu, POP OS, Raspberry Pi OS, etc.

This write up will be using an Amazon AWS EC2 Instance running Ubuntu, however it will work on any Debian based Linux

Install Pre Requites

sudo apt install apache2 libapache2-mod-php php-mysql -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapache2-mod-php7.4 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libjansson4 liblua5.2-0 php7.4-cli php7.4-json php7.4-mysql php7.4-opcache php7.4-readline ssl-cert
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser php-pear openssl-blacklist
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php libapache2-mod-php7.4 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libjansson4 liblua5.2-0 php-mysql php7.4-cli php7.4-json php7.4-mysql php7.4-opcache php7.4-readline ssl-cert
0 upgraded, 19 newly installed, 0 to remove and 46 not upgraded.
Need to get 5009 kB of archives.
After this operation, 18.8 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libapr1 amd64 1.6.5-1ubuntu1 [91.4 kB]
Get:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libaprutil1 amd64 1.6.1-4ubuntu2 [84.7 kB]
Get:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libaprutil1-dbd-sqlite3 amd64 1.6.1-4ubuntu2 [10.5 kB]
Get:4 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libaprutil1-ldap amd64 1.6.1-4ubuntu2 [8736 B]
Get:5 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libjansson4 amd64 2.12-1build1 [28.9 kB]
Get:6 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/main amd64 liblua5.2-0 amd64 5.2.4-1.1build3 [106 kB]
Get:7 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 apache2-bin amd64 2.4.41-4ubuntu3.9 [1180 kB]
Get:8 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 apache2-data all 2.4.41-4ubuntu3.9 [159 kB]
Get:9 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 apache2-utils amd64 2.4.41-4ubuntu3.9 [84.3 kB]
Get:10 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 apache2 amd64 2.4.41-4ubuntu3.9 [95.5 kB]
Get:11 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-json amd64 7.4.3-4ubuntu2.10 [19.2 kB]
Get:12 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-opcache amd64 7.4.3-4ubuntu2.10 [198 kB]
Get:13 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-readline amd64 7.4.3-4ubuntu2.10 [12.6 kB]
Get:14 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-cli amd64 7.4.3-4ubuntu2.10 [1422 kB]
Get:15 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 libapache2-mod-php7.4 amd64 7.4.3-4ubuntu2.10 [1365 kB]
Get:16 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libapache2-mod-php all 2:7.4+75 [2836 B]
Get:17 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 php7.4-mysql amd64 7.4.3-4ubuntu2.10 [121 kB]
Get:18 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/main amd64 php-mysql all 2:7.4+75 [2000 B]
Get:19 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/main amd64 ssl-cert all 1.0.39 [17.0 kB]
Fetched 5009 kB in 0s (22.1 MB/s)
Preconfiguring packages ...
Selecting previously unselected package libapr1:amd64.
(Reading database ... 131233 files and directories currently installed.)
Preparing to unpack .../00-libapr1_1.6.5-1ubuntu1_amd64.deb ...
Unpacking libapr1:amd64 (1.6.5-1ubuntu1) ...
Selecting previously unselected package libaprutil1:amd64.
Preparing to unpack .../01-libaprutil1_1.6.1-4ubuntu2_amd64.deb ...
Unpacking libaprutil1:amd64 (1.6.1-4ubuntu2) ...
Selecting previously unselected package libaprutil1-dbd-sqlite3:amd64.
Preparing to unpack .../02-libaprutil1-dbd-sqlite3_1.6.1-4ubuntu2_amd64.deb ...
Unpacking libaprutil1-dbd-sqlite3:amd64 (1.6.1-4ubuntu2) ...
Selecting previously unselected package libaprutil1-ldap:amd64.
Preparing to unpack .../03-libaprutil1-ldap_1.6.1-4ubuntu2_amd64.deb ...
Unpacking libaprutil1-ldap:amd64 (1.6.1-4ubuntu2) ...
Selecting previously unselected package libjansson4:amd64.
Preparing to unpack .../04-libjansson4_2.12-1build1_amd64.deb ...
Unpacking libjansson4:amd64 (2.12-1build1) ...
Selecting previously unselected package liblua5.2-0:amd64.
Preparing to unpack .../05-liblua5.2-0_5.2.4-1.1build3_amd64.deb ...
Unpacking liblua5.2-0:amd64 (5.2.4-1.1build3) ...
Selecting previously unselected package apache2-bin.
Preparing to unpack .../06-apache2-bin_2.4.41-4ubuntu3.9_amd64.deb ...
Unpacking apache2-bin (2.4.41-4ubuntu3.9) ...
Selecting previously unselected package apache2-data.
Preparing to unpack .../07-apache2-data_2.4.41-4ubuntu3.9_all.deb ...
Unpacking apache2-data (2.4.41-4ubuntu3.9) ...
Selecting previously unselected package apache2-utils.
Preparing to unpack .../08-apache2-utils_2.4.41-4ubuntu3.9_amd64.deb ...
Unpacking apache2-utils (2.4.41-4ubuntu3.9) ...
Selecting previously unselected package apache2.
Preparing to unpack .../09-apache2_2.4.41-4ubuntu3.9_amd64.deb ...
Unpacking apache2 (2.4.41-4ubuntu3.9) ...
Selecting previously unselected package php7.4-json.
Preparing to unpack .../10-php7.4-json_7.4.3-4ubuntu2.10_amd64.deb ...
Unpacking php7.4-json (7.4.3-4ubuntu2.10) ...
Selecting previously unselected package php7.4-opcache.
Preparing to unpack .../11-php7.4-opcache_7.4.3-4ubuntu2.10_amd64.deb ...
Unpacking php7.4-opcache (7.4.3-4ubuntu2.10) ...
Selecting previously unselected package php7.4-readline.
Preparing to unpack .../12-php7.4-readline_7.4.3-4ubuntu2.10_amd64.deb ...
Unpacking php7.4-readline (7.4.3-4ubuntu2.10) ...
Selecting previously unselected package php7.4-cli.
Preparing to unpack .../13-php7.4-cli_7.4.3-4ubuntu2.10_amd64.deb ...
Unpacking php7.4-cli (7.4.3-4ubuntu2.10) ...
Selecting previously unselected package libapache2-mod-php7.4.
Preparing to unpack .../14-libapache2-mod-php7.4_7.4.3-4ubuntu2.10_amd64.deb ...
Unpacking libapache2-mod-php7.4 (7.4.3-4ubuntu2.10) ...
Selecting previously unselected package libapache2-mod-php.
Preparing to unpack .../15-libapache2-mod-php_2%3a7.4+75_all.deb ...
Unpacking libapache2-mod-php (2:7.4+75) ...
Selecting previously unselected package php7.4-mysql.
Preparing to unpack .../16-php7.4-mysql_7.4.3-4ubuntu2.10_amd64.deb ...
Unpacking php7.4-mysql (7.4.3-4ubuntu2.10) ...
Selecting previously unselected package php-mysql.
Preparing to unpack .../17-php-mysql_2%3a7.4+75_all.deb ...
Unpacking php-mysql (2:7.4+75) ...
Selecting previously unselected package ssl-cert.
Preparing to unpack .../18-ssl-cert_1.0.39_all.deb ...
Unpacking ssl-cert (1.0.39) ...
Setting up php7.4-json (7.4.3-4ubuntu2.10) ...

Creating config file /etc/php/7.4/mods-available/json.ini with new version
Setting up php7.4-mysql (7.4.3-4ubuntu2.10) ...

Creating config file /etc/php/7.4/mods-available/mysqlnd.ini with new version

Creating config file /etc/php/7.4/mods-available/mysqli.ini with new version

Creating config file /etc/php/7.4/mods-available/pdo_mysql.ini with new version
Setting up libapr1:amd64 (1.6.5-1ubuntu1) ...
Setting up php7.4-readline (7.4.3-4ubuntu2.10) ...

Creating config file /etc/php/7.4/mods-available/readline.ini with new version
Setting up libjansson4:amd64 (2.12-1build1) ...
Setting up ssl-cert (1.0.39) ...
Setting up liblua5.2-0:amd64 (5.2.4-1.1build3) ...
Setting up php7.4-opcache (7.4.3-4ubuntu2.10) ...

Creating config file /etc/php/7.4/mods-available/opcache.ini with new version
Setting up apache2-data (2.4.41-4ubuntu3.9) ...
Setting up libaprutil1:amd64 (1.6.1-4ubuntu2) ...
Setting up php-mysql (2:7.4+75) ...
Setting up php7.4-cli (7.4.3-4ubuntu2.10) ...
update-alternatives: using /usr/bin/php7.4 to provide /usr/bin/php (php) in auto mode
update-alternatives: using /usr/bin/phar7.4 to provide /usr/bin/phar (phar) in auto mode
update-alternatives: using /usr/bin/phar.phar7.4 to provide /usr/bin/phar.phar (phar.phar) in auto mode

Creating config file /etc/php/7.4/cli/php.ini with new version
Setting up libaprutil1-ldap:amd64 (1.6.1-4ubuntu2) ...
Setting up libaprutil1-dbd-sqlite3:amd64 (1.6.1-4ubuntu2) ...
Setting up apache2-utils (2.4.41-4ubuntu3.9) ...
Setting up apache2-bin (2.4.41-4ubuntu3.9) ...
Setting up libapache2-mod-php7.4 (7.4.3-4ubuntu2.10) ...
Package apache2 is not configured yet. Will defer actions by package libapache2-mod-php7.4.

Creating config file /etc/php/7.4/apache2/php.ini with new version
No module matches
Setting up apache2 (2.4.41-4ubuntu3.9) ...
Enabling module mpm_event.
Enabling module authz_core.
Enabling module authz_host.
Enabling module authn_core.
Enabling module auth_basic.
Enabling module access_compat.
Enabling module authn_file.
Enabling module authz_user.
Enabling module alias.
Enabling module dir.
Enabling module autoindex.
Enabling module env.
Enabling module mime.
Enabling module negotiation.
Enabling module setenvif.
Enabling module filter.
Enabling module deflate.
Enabling module status.
Enabling module reqtimeout.
Enabling conf charset.
Enabling conf localized-error-pages.
Enabling conf other-vhosts-access-log.
Enabling conf security.
Enabling conf serve-cgi-bin.
Enabling site 000-default.
info: Switch to mpm prefork for package libapache2-mod-php7.4
Module mpm_event disabled.
Enabling module mpm_prefork.
info: Executing deferred 'a2enmod php7.4' for package libapache2-mod-php7.4
Enabling module php7.4.
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-htcacheclean.service.
Setting up libapache2-mod-php (2:7.4+75) ...
Processing triggers for ufw (0.36-6ubuntu1) ...
Processing triggers for systemd (245.4-4ubuntu3.15) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Processing triggers for php7.4-cli (7.4.3-4ubuntu2.10) ...
Processing triggers for libapache2-mod-php7.4 (7.4.3-4ubuntu2.10) ...

Install WordPress

  • Create the directory for wordpress
  • Change permission on the desired directory
  • Download and unzip WordPress into the desired folder as desired user so that permissions are correct.
sudo mkdir -p /var/www/wordpress

sudo chown www-data: /var/www/wordpress

curl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /var/www

Configure Apache

Configure Apache to server the website from /var/www/wordpress/ rather than the default /var/www/html/

sudo nano /etc/apache2/sites-available/wordpress.conf

wordpress.conf

<VirtualHost *:80>
    DocumentRoot /var/www/wordpress
    <Directory /var/www/wordpress>
        Options FollowSymLinks
        AllowOverride Limit Options FileInfo
        DirectoryIndex index.php
        Require all granted
    </Directory>
    <Directory /var/www/wordpress/wp-content>
        Options FollowSymLinks
        Require all granted
    </Directory>
</VirtualHost>

Enable Website

sudo a2ensite wordpress

Enable URL ReWriting

sudo a2enmod rewrite

Disable the default “It Works” site

sudo a2dissite 000-default

Reload Apache

sudo service apache2 reload

Restart Apache

systemctl restart apache2

Configure WordPress

Configure WordPress to Connect to DataBase

sudo nano /var/www/wordpress/wp-config.php
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );

/** Database username */
define( 'DB_USER', 'username_here' );

/** Database password */
define( 'DB_PASSWORD', 'password_here' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );
  • https://wordpress.org/
, ,