How to Install WordPress on Debian

In this article, I'll show you how to install MariaDB and PHP, as well as wordpress.
In my last article, I walked you through the process of installing Nginx as well as certbot to get your website off the ground. If you haven't set up Nginx or Certbot, and you want to set up wordpress, you should go back to that article and follow those instructions by clicking here, since this article assumes you've just completed all the steps laid out there.

Install MariaDB

In order to store WordPress's data, you'll need the MariaDB program. It's a fork of MySQL, which is a database software. If you're interested in how this works, you should check out this article.

Install the MariaDB server by typing the following command.

apt install mariadb-server

Then run the installation security script.

mariadb-secure-installation

In this script, you'll be given the option to do several things. I'll walk you through it. If you know what you're doing, you should decide on your own settings.

Secure Install Script

  • Enter the root password: Since this is the first time you're installing MariaDB on this server, you can press enter here without typing a password at all.
  • Switch to unix_socket authentication: y
  • Change root password: y
  • Enter your new password
  • Remove anonymous users?: y
  • Disallow root login remotely?: y
  • Remove test database and access to it?: y
  • Reload privilege tables now?: y

Once that's done, run

mariadb

to launch the MariaDB shell. This is where you'll set up the database that wordpress will connect to once it has been installed.

Creating a database and user

In this section, we'll set up the database that WordPress will use, as well as the user account that WordPress will log into in order to access it. You'll enter some of these values during the installation process itself. Although you won't often use them, you should keep this information safe, just in case the need arises.

Modify the following commands as necessary. I strongly recommend that you consider changing database names, usernames and passwords.

CREATE DATABASE WORDPRESS;
CREATE USER 'WPUSER'@localhost IDENTIFIED BY 'some_password';
GRANT ALL PRIVILEGES ON WORDPRESS.* TO WPUSER@localhost IDENTIFIED BY 'some_password';
FLUSH PRIVILEGES;
EXIT;

That's it. MariaDB is now ready for WordPress.

Install PHP

PHP (hypertext preprocessor) is, in my opinion anyway, the second coolest part of the LEMP stack. It pretty much takes your average static website created with HTML and CSS to a new level by allowing you to add dynamic content. It's a coding language for websites. It runs on a server, and when paired with Nginx or Apache2, sends custom generated content back to your user's browser as HTML. It powers many large social media websites such as Facebook and Tumblr, information sites like Wikipedia, and, of course, WordPress.

You can install PHP by typing the following command.

apt install php-fpm php-mysqli php-curl php-dom php-imagick php-mbstring php-zip php-gd php-intl

Type y when prompted, and then head over to your Nginx configuration folder that we set up last time, where we'll connect the two pieces of software together.

cd /etc/nginx/sites-enabled

Setting up Nginx

Before we start, you should check your PHP version by typing

php -v

My version is PHP 8.2. Note your version, it will be important in a minute.

In your Nginx configuration folder, usually located at /etc/nginx/sites-enabled, you should find several files. One should be named default, and another named after your site. Edit your site's configuration using nano by typing the following. Remember to replace example.com with the name of your file.

nano example.com

There should be a section of code that starts with location /.
Remove that section, and replace it with the following. You should edit it according to your needs.

location / {
    try_files $uri $uri/ /index.php?$args;
}

location = /favicon.ico {
    log_not_found off;
    access_log off;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires max;
    log_not_found off;
}

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

In the line that reads

fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;

Replace 8.2 with the PHP version running on your own machine.

Close the Nano text editor by typing control+x then y, then type

nginx -t

to test that your Nginx configuration is working correctly before restarting.

If the test was successful, type

systemctl restart nginx

to restart Nginx. After this, you're ready to move on to the final step, installing wordpress itself.

Installing WordPress

Now, for the fun part. CD into your site's directory,

cd /var/www/example.com/public_html

Then, download the latest WordPress package from their website by typing the following.

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

Once the download has completed, extract the file by typing

tar -xvf latest.tar.gz

After that, remove the package with

rm latest.tar.gz

Then move the files out of the wordpress directory and into the public_html folder by typing

mv wordpress/* .

Next, you can remove the unused wordpress directory by typing

rm -rf wordpress

Then, change the permissions of these files so the install script can run by typing

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

Once this is done, head over to your site and proceed with the install.

Once that's complete, I'd recommend visiting the site health page to make sure everything is running properly. As far as the setup goes, assuming you didn't get any errors, you should now be done.

Tips

Looking for some good themes and plugins?

Personally, for the WordPress theme, I recommend Generate Press, the theme this site uses. If you like the layout of this site, you should give it a shot.

Here's a list of some good plugins to get you started.

  • Classic Editor and Classic Widgets - They're separate plugins, however they do the same sort of thing so I'll include them here as one. If you're like me; A screen reader user, you should use this. It improves the accessibility of the wordpress panel a lot.
  • Simple CloudFlare Turnstile - A really easy Captcha plugin to protect your comment, login, registration and forgot password forms from bots. I set it up in 5 minutes; It's fantastic.
  • Total Upkeep by BoldGrid - A really nice WordPress backup plugin. It lets you create backups of your entire site (Even your database!) automatically. You aren't limited to local storage, either. the SFTP upload feature allows me to send the generated backups right to my server, and I get an email right after a backup has been taken, that way I know whether it has succeeded or failed.
  • WP Githuber MD - If you're interested in writing posts and pages in markdown, this is the best one I've tried so far.
  • WP Mail SMTP - Super simple mail plugin for WordPress. Works with Gmail, Sendgrid, self-hosted Email servers, etc.

As usual, I hope this article was helpful. I plan to start posting on here again, it's been more than a year, I know.

3 thoughts on “How to Install WordPress on Debian”

  1. you forgot about a command to use because wordpress neads these extensions. apt install php php-{fpm,pear,cgi,common,zip,mbstring,net-socket,gd,xml-util,mysql,bcmath}

    Reply

Leave a Comment