How to Install WordPress on Debian 12

how to install wordpress on debian 12

WordPress is a free, open-source content management system (CMS) written in PHP. It is used for creating websites with various plugins and themes and is customizable in every aspect according to client needs.

In this blog post, we will install WordPress with the LAMP stack.

Installing WordPress with a LAMP stack is a straightforward process that may take up to 15 minutes. Let’s get started!

Prerequisites

  • A server with Debian 12 as OS
  • User privileges: root or non-root user with sudo privileges

Step 1. Update the System

Before we start with LAMP installation, we need to update the system packages to the latest versions available.

sudo apt-get update -y && sudo apt-get upgrade -y

Step 2. Install Apache Web Server

We will start with the Apache web server from the LAMP stack first. To install the Apache Web server execute the following command:

sudo apt install apache2 -y

Once installed, start and enable the service.

sudo systemctl enable apache2 && sudo systemctl start apache2

Check if the service is up and running:

sudo systemctl status apache2

You should receive the following output:

root@host:~# sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; preset: enabled)
     Active: active (running) since Thu 2023-08-03 06:02:42 CDT; 22h ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 711 (apache2)
      Tasks: 10 (limit: 4644)
     Memory: 29.7M
        CPU: 4.878s
     CGroup: /system.slice/apache2.service

Step 3. Install PHP8.2 with dependencies

Next, we will install PHP. PHP8.2 is by default enabled in the Debian 12 repository, so to install PHP8.2 with extensions, execute the following commands:

sudo apt-get install php8.2 php8.2-cli php8.2-common php8.2-imap php8.2-redis php8.2-snmp php8.2-xml php8.2-mysqli php8.2-zip php8.2-mbstring php8.2-curl libapache2-mod-php -y

To check the installed PHP version, execute the following command:

php -v

You should get the following output:

root@host:~# php -v
Created directory: /var/lib/snmp/cert_indexes
PHP 8.2.7 (cli) (built: Jun  9 2023 19:37:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies

Step 4. Install the MariaDB database server

The last of the LAMP stack is the MariaDB database server. To install it, execute the command below.

sudo apt install mariadb-server -y

Start and enable the mariadb.service with the following commands:

sudo systemctl start mariadb && sudo systemctl enable mariadb

Check the status of the mariadb.service

sudo systemctl status mariadb

You should receive the following output:

root@host:~# sudo systemctl status mariadb
● mariadb.service - MariaDB 10.11.3 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; preset: enabled)
     Active: active (running) since Fri 2023-08-04 05:04:01 CDT; 26s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 8511 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 16 (limit: 4644)
     Memory: 174.3M
        CPU: 907ms
     CGroup: /system.slice/mariadb.service
             └─8511 /usr/sbin/mariadbd

Step 5. Create a WordPress database and user

Next, we need to create a WordPress database, the WordPress user, and grant the permissions for that user to the database.

 CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'YourStrongPasswordHere';
 CREATE DATABASE wordpress;
 GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
 FLUSH PRIVILEGES;
 EXIT;

Step 6. Download and Install WordPress

Before we install WordPress, we first need to download it in the default Apache document root:

cd /var/www/html

wget https://wordpress.org/latest.zip

unzip latest.zip

rm latest.zip

Set the right permissions to files and folders.

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

cd wordpress/

find . -type d -exec chmod 755 {} \;

find . -type f -exec chmod 644 {} \;

Now, open the wp-config.php file with your favorite editor and enter the database credentials you created in the previous step.

mv wp-config-sample.php wp-config.php

nano wp-config.php

It should look similar to this:

// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

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

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

Step 7. Create Apache Virtual Host File

Go into the Apache directory and create a configuration file for WordPress.

cd /etc/apache2/sites-available/

touch wordpress.conf

Open the file, paste the following lines of code, save the file and close it.

<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/html/wordpress

<Directory /var/www/html/wordpress>
AllowOverride All
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Enable the Apache configuration for WordPress and rewrite the module.

sudo a2enmod rewrite

sudo a2ensite wordpress.conf

Check the syntax:

apachectl -t

You should receive the following output:

root@vps:~# apachectl -t
Syntax OK

If the syntax is OK, restartd the Apache service.

systemctl reload apache2

Once the Apache service is restarted, you can finish your WordPress installation at http://yourdomain.com.

That was all. You successfully installed and configured WordPress on Debian 12 with the LAMP stack.

If you do not want to configure it on your own, you can sign up for one of our NVMe VPS plans and submit a support ticket. Our admins are available 24/7 and will start to work on your request immediately. Always trust our epic support.

If you liked this post on how to install WordPress on Debian 12, please share it with your friends on social networks or simply leave a reply below. Thanks.

6 thoughts on “How to Install WordPress on Debian 12”

  1. Really excellent guide which met my needs pretty much exactly, which is a rarity in the self hosting server space. Helped that I already have Apache and DNS skills. Was able to get a starting WordPress site up and running in less than 2 hours using my Debian Bookworm server using this guide. Thanks

    Reply
    • Thank you for your contribution.

      From MariaDB 10.4, Unix socket authentication is applied by default, and there is usually no need to create a root password.

      Reply
  2. Nice advice, but it’s not obvious how you issue the create user/create database commands: you’re missing the tiny detail that you have to issue the command ‘sudo mysql’ before you can start issuing SQL statements!
    Apart from that, I could not initiate the WordPress install by visiting http://localhost. I think that’s because there’s a 000-default.conf in /etc/apache2/sites-available, and it takes precedence over the wordpress.conf your instructions have us create. I did a sudo mv 000-default.conf 000-default.conf.bkp, followed by a systemctl restart apache2 to fix that. Obviously, a2dissite 000-default might have been preferable at that point! Anyway: relatively minor nit-picks. Thanks for the step-by-step instructions.

    Reply

Leave a Comment