This tutorial shows you how to install WordPress in Debian 9 Stretch. WordPress is one of the most commonly used content management systems for creating and delivering dynamic web pages. It free and open source software (FOSS) and it is based on PHP and MySQL. Due to its ease of deployment and ease of use, it has become the most popular website management system.
We will start with a clean LAMP server. Assuming we’ll be wanting to use pretty permalinks (trust me, you will), you need to enable the Apache module mod_rewrite, which comes disabled by default. You should see some acknowledgement and a message to restart Apache. We might as well do as we’re told:
root@system:~# a2enmod rewrite Enabling module rewrite. To activate the new configuration, you need to run: systemctl restart apache2 root@system:~# systemctl restart apache2
Next we will need to create a MySQL user and a database for WordPress to use. Best practice is to create a separate user and database for each WordPress instance you might be deploying.
From the system prompt:
root@system:~# mysql -u root -p
Enter your MariaDB root password and you’ll be in the database prompt:
root@system:~# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 10.1.23-MariaDB-9+deb9u1 Debian 9.0 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
Ok, let’s create a user. I’m using wordpressdb, wordpressuser and wordpresspass as placeholders. Evidently you can substitute your own.
MariaDB \[(none)\]> CREATE DATABASE wordpressdb;
As you work in the database you should see output along the following lines if your command was successful. If you get an output saying ERROR, check your syntax.
MariaDB [(none)]> CREATE DATABASE wordpressdb; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]>
You can create your user and grant it permission to use the database in one command:
MariaDB [(none)]> GRANT ALL ON wordpressdb.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'wordpresspass';
Reload the newly granted privileges by typing:
MariaDB [(none)]> FLUSH PRIVILEGES;
And exit MariaDB:
MariaDB [(none)]> EXIT;
Check that your new user has access to the correct database:
root@system:~# mysql -u wordpressuser -p
After entering your password you should be allowed into MariaDB. Try and load the wordpressdb database. You should get a result like this:
MariaDB [(none)]> USE wordpressdb; Database changed
You can exit MariaDB, your work there is done.
Next you need to download WordPress.
I find it easiest to change to your site’s intended directory, then downloading the archive and extracting it in place. This way we can simply rename the WordPress directory, like this:
root@system:~# cd /var/www/example.com root@system:~# wget https://wordpress.org/latest.tar.gz root@system:~# gunzip latest.tar.gz root@system:~# tar -xvf latest.tar root@system:~# rm -rf html root@system:~# mv wordpress html
At this stage you should have a single folder inside
/var/www/example.com called html. Unfortunately the folder had the wrong ownership (probably nobody:nogroup), so we need to make it owned by Apache.
root@system:~# chown -R www-data:www-data html
We now have all the WordPress files in place and are almost ready to go. We can do some edits on the WordPress configuration to ease installation:
root@system:~# cp /var/www/example.com/html/wp-config-sample.php /var/www/example.com/html/wp-config.php root@system:~# chown www-data:www-data /var/www/example.com/html/wp-config.php root@system:~# nano /var/www/example.com/html/wp-config.php
Note that the copied file was owned by root so we’ve changed the ownership back to Apache. In this file, you need to update three lines with your database data:
/** The name of the database for WordPress */ define('DB_NAME', 'wordpressdb'); /** MySQL database username */ define('DB_USER', 'wordpressuser'); /** MySQL database password */ define('DB_PASSWORD', 'wordpresspass');
A bit further down are the Authentication Unique Keys and Salts, filled with placeholders:
define('AUTH_KEY', 'put your unique phrase here'); define('SECURE_AUTH_KEY', 'put your unique phrase here'); define('LOGGED_IN_KEY', 'put your unique phrase here'); define('NONCE_KEY', 'put your unique phrase here'); define('AUTH_SALT', 'put your unique phrase here'); define('SECURE_AUTH_SALT', 'put your unique phrase here'); define('LOGGED_IN_SALT', 'put your unique phrase here'); define('NONCE_SALT', 'put your unique phrase here');
These will secure our installation, so as recommended in the file’s comments above them, go to https://api.wordpress.org/secret-key/1.1/salt/ to obtain some unique, secure new keys, and replace the placeholders with those.
Load your site in your browser again, and you should see the first screen of WordPress installation:
Choose your language
Continue with the installation, filling in the required data and taking note of your username and password. When you’re ready, hit ‘Install WordPress’, and you’ll be all done! You’ll have a fully functioning installation of WordPress in Debian 9 Stretch! Choose a theme, and get on designing your site!