How to Install WordPress On Debian 9 Stretch Linux

WordPress is one of the most popular website-building tools available out there. It is a simple way to get your online presence and perfect for those who do not know how to code and want a simple and effective way to share and build your story on the internet.

Prerequisites:

Create Your Database

Setup the database so the Wordpress can store in all the information. Log in to MariaDB as root user.

In this, we will create a Database, User and provide all kinds of privileges of managing the specific database to the user.

mysql -u root -p

output:

root@vps:~# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 15

Now, create your WordPress database. We're creating it with wp_database as an example, but you can name it related to the website you're going to host.

CREATE DATABASE wp_database;

output:

MariaDB [(none)]> CREATE DATABASE wp_database;
Query OK, 1 row affected (0.00 sec)    

Create a regular user for WordPress.

CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'StrongPassword';

Replace StrongPassword with an actual strong password.

output:

MariaDB [(none)]> CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

Finally, grant the new user all the privileges for the database wp_database.

GRANT ALL ON `wp_database`.* TO `wpuser`@`localhost`;

output:

MariaDB [(none)]> GRANT ALL ON `wp_database`.* TO `wpuser`@`localhost`;
Query OK, 0 rows affected (0.00 sec)

Flush your privileges and exit.

FLUSH PRIVILEGES;
EXIT;

output:

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

Download And Unzip WordPress

Visit the official Wordpress site to get to know the latest version available for download and also for more information on requirements of the server.

You can also use the below URL link to download the latest version at any given time.

cd /tmp
wget https://wordpress.org/latest.tar.gz

Unzip the downloaded WordPress file.

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

mkdir /var/www/wordpress

cp -R wordpress/* /var/www/wordpress/

Ofcourse, you can create the directory with the name of your choice or the name of the website.

Change the permissions and ownership to improve security and grant your webserver proper access.

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

find /var/www/wordpress -type d -exec chmod 755 {} \;

find /var/www/wordpress -type f -exec chmod 644 {} \;

Create a Apache vHost

Using your favourite editor, we will create a config file in /etc/apache2/sites-available.

The config file can be the name of the website but it has to end with a .conf file extension.

We're using nano for adding the configuration :

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

Add in the below contents:

<VirtualHost *:80>
    ServerName example.com
    # ServerAlias www.example.com
    ServerAdmin webmaster@example.com
    DocumentRoot /var/www/wordpress

    <Directory /var/www/wordpress>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>

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

Replace example.com with your actual domain name.

Next, we'll have to create a symbolic link, so the config file is available in sites-enabled as well.

ln -s /etc/apache2/sites-available/wordpress.conf /etc/apache2/sites-enabled/

Enable the new configuration,

a2ensite wordpress.conf

Test the configuration for any typos and syntax errors,

apachectl configtest

Once you get Syntax OK, restart apache web server for the changes to go live.

systemctl restart apache2

Open up a web browser and navigate to the domain name or IP address of your server, http://IP_address And complete the installation process by setting up your preferred language and username and password.

This concludes the installation of WordPress on Debian 9