Objective

Install WordPress on Debian 9 Stretch

Distributions

Debian 9 Stretch

Requirements

A working install of Debian Stretch with root privileges

Difficulty

Easy

Conventions

  • # - requires given command to be executed with root privileges either directly as a root user or by use of sudo command
  • $ - given command to be executed as a regular non-privileged user

Introduction

WordPress is easily the most popular content management system available. It's probably also the most popular platform on the web altogether. Whether you're hosting a small blog of a large online publication, WordPress is an excellent option. Since Debian is ultra-stable and has massive package repositories, it's a great distribution to host WordPress on. You can get WordPress running on Debian Stretch very easily, and get your website started fast.

Set Up A LAMP Or LEMP Stack

Before you can install WordPress, you're going to need to set up your server to serve PHP web applications. You can either follow our LAMP Guide or our LEMP Guide to get set up.

Create Your Database

Once your server is ready, you can set up the database where you're going to store everything from WordPress. Log in to MariaDB as your root user.
# mysql -u root -p
Once you're signed in, create a regular user for WordPress.
MariaDB [(none)]> CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'userpassword';
Now, create your WordPress database.
MariaDB [(none)]> CREATE DATABASE wp_database;
Finally, grand your user all permissions on the database.
MariaDB [(none)]> GRANT ALL ON `wp_database`.* TO `wpuser`@`localhost`;
Flush your privileges and exit.
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit;

Download And Unpack WordPress

Here's where WordPress makes its entrance. You can either head over to the https://wordpress.org and download it that way, or just use wget. The URL never changes, so wget will always work.
$ cd Downloads
$ wget https://wordpress.org/latest.tar.gz
Unpack WordPress using tar.
$ tar xpf latest.tar.gz
The resulting folder will be wordpress. It contains the entire WordPress install. How and where you copy it is entirely up to you and depends on your web server configuration. The example provided covers the most basic possible install on Apache.
# rm -rf /var/www/html
# cp -r wordpress /var/www/html
If you're using Nginx, you probably just want to place the folder in /var/www/ as it is, and point your configuration at it. When WordPress is where you want it, change the permissions and ownership to improve security and grant your webserver proper access.
# chown -R www-data:www-data /var/www/html
# find /var/www/html -type d -exec chmod 755 {} \;
# find /var/www/html -type f -exec chmod 644 {} \;
Certainly, if your webserver is configured to run under a different user, change the ownership to that one.

WordPress Setup


Initial Startup Of The WordPress Installer on Debian Stretch

WordPress's web-based installer handles the rest of the process. So, open up a web browser and navigate to the domain name or IP address of your server.

WordPress Database Setup on Debian Stretch

The first screen that you'll see will just greet you. When you click through to the next screen, WordPress will prompt you for your database information. Enter everything that you set up.

WordPress Account Creation on Debian Stretch

The final screen will ask you for information about your site. Enter everything as it pertains to the website that you're setting up. After that screen, the WordPress installer will run and set up everything. When it finishes, it will present you with the WordPress login screen. You can then log in and gain access to your admin interface.

Closing Thoughts

Congratulations! You have a working WordPress installation on Debian Stretch. If you're running this server in production, make sure that you properly secure it, and that includes WordPress itself.