Debian

How to Install WordPress on Debian 12

Wordpress

To publish and manage web content there are different tools but the most popular among them is WordPress. This is because it is an open-source tool that has nearly all the bells and whistles that other tools provide but with some extra cost. In other words, WordPress is also known as a content management system that helps you manage your site settings which include different kinds of plugins, website appearance, adds management, and more. Moreover, it is based on the PHP hypertext preprocessor language and uses MariaDB or MySQL for storing the database.

How to Install WordPress on Debian 12

Since WordPress is a content management tool, installing it requires having a web server and a database which makes its installation quite a long process, but it is easy to follow. So, to Install WordPress on Debian 12 here are some steps that you need to follow:

Step 1: Install Apache Web Server on Debian12

There are a number of web servers available like Nginx, Node.js, Lite speed, Apache, and more, you can use any of them but here I am using Apache. Apache is an open-source web server that uses the HTTP protocol and to install it on Debian 12 execute:

sudo apt install apache2 -y

Once the installation is complete check its version by executing:

sudo apache2 -v

Now check the Apache service if it is running using the systemctl command and if it is not running then try to enable it by executing:

systemctl enable apache2 --now

You may get this error of journalctl -xeu apache2.service then it means that there is any other server running that is accessing the same port. So in that case look for the server that is accessed by the respective pot 80 by executing:

sudo lsof -i tcp:80

Now here I already had Nginx installed which is using port 80 that is causing this error for Apache, so for that just use the kill command to terminate the root user process using its PID:

kill <root-PID>

Now execute the enable command for Apache:

sudo systemctl enable apache2 --now

Now use your IP address to visit the Apache2 default page for verification:

http://127.0.0.1

http://localhost


You might encounter firewall issues while accessing the server, so it is advisable to add a rule for allowing the TCP protocol at port 80 using the iptables command:

sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT

Step 2: Install MariaDB Database Server

MariaDB is a server database management tool that can store large amounts of data, it has a central access point from where the data can be retrieved and stored. So for the installation of WordPress on Debian12, we have to install the MariaDB server and client, for that execute:

sudo apt install mariadb-server mariadb-client -y

Once this database server is installed verify its version by executing:

mariadb --version

Now check the status of the database server usually, it is active and running and for that execute:

sudo systemctl status mariadb

If your database server is not active and running, then try enabling it and then starting it using the systemctl commands:

sudo systemctl enable mariadb --now

sudo systemctl start mariadb

The newer version of MariaDB comes with default configurations which are not that good when it comes to any potential of unauthorized access or in case of any breach. So, to provide better security for MariaDB run the mysql_secure_installation:

sudo mysql_secure_installation


You have to give prompts for various options that will be asked during the execution of the script and just for the prompt of root account password press n and for the rest of the prompts replay with y.

Step 3: Install PHP on Debian 12

As mentioned above WordPress is based on the PHP language so it is necessary to have PHP installed on Debian. Moreover, it also acts as a bridge between the web server that is Apache, and the database server which is MariaDB. Apart from installing the PHP WordPress requires some PHP extension as well to run properly so for that execute:

sudo apt install php libapache2-mod-php8.2 php8.2-cli php8.2-common php8.2-zip php8.2-curl php8.2-mysql -y

Here is a bit more detail for the PHP extensions that are installed:

  • libapache2-mod-php8.2: The Apache module that integrates PHP with the web server.
  • php8.2-cli: The command-line interface for PHP.
  • php8.2-common: The common files shared by different PHP extensions.
  • php8.2-zip: The PHP extension for handling ZIP archives.
  • php8.2-curl: The PHP extension for using the cURL library.
  • php8.2-mysql: The PHP extension for interacting with MySQL or MariaDB databases.

Now to see if PHP is installed successfully, check its version by executing:

php -v

Further, if you want to switch to any other PHP version that is installed on your Debian system then you have to deactivate the current one:

sudo a2dismod php<verison-number

Now to switch to the other version use the a2enmod command like this:

sudo a2enmod php<version-number>

Next, once you are done with the change restart the Apache server to apply the changes by using:

sudo systemctl restart apache2

Step 4: Install WordPress Backend on Debian 12

Web applications usually have two ends, one is the backend and the other is the frontend, the backend has all the programming that creates the frontend. The same is the case with WordPress, so first we have to install the backend end for WordPress from its official site by executing the:

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

Now extract the downloaded file to the HTML folder in the variables directory of Debian using the C flag:

sudo tar -xzvf latest.tar.gz -C /var/www/html/

Once the file is extracted change its permissions, first starting by changing the ownership of the WordPress directory by executing:

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

Here chown is for changing the owner and www-data:www-data is the user group that is the new owner whereas the R flag is used for recursive as this will apply to any subdirectories if any.

Next, change the permissions of the directory and the files inside it, the chmod 775 means that the owners can read, write, and execute this directory, to specify it for directory type d command is used.

However, for other users, it has only read and execute permission. Moreover, the permissions for the files in the directories are limited to reading and executing for the owner, and in the case of other users the permission is only for reading the files:

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

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


Step 5: Create a Database for WordPress

WordPress, as mentioned above uses a database for storing all the website data and user information, similarly, to access the database name, username, and password are to be stored. So, execute the MariaDB database server by executing:

sudo mariadb -u root

Now create a database using the command CREATE DATABASE along with the desired name, here for illustration I have created a database named WORDPRESSDB but you can give any name you want:

CREATE DATABASE WORDPRESSDB;

Now create a user for WordPress and set the password for accessing the database, here for illustration I have set a dummy name and password, but you can set any name and password based on your preference:

CREATE USER 'WPUSER'@localhost IDENTIFIED BY 'PASSWORD';

Once you have created a user and set its password key then grant the user all the rights for managing the database. Don’t forget to replace the username and password in the command below with your set password and username:

GRANT ALL PRIVILEGES ON WORDPRESSDB.* TO WPUSER@localhost IDENTIFIED BY 'PASSWORD';

Now just reload the grant tables which in other words reloads the database to apply the changes and after that exit the database:

FLUSH PRIVILEGES;

EXIT;


Step 5: Configure WordPress on Debian 12

The password and the user we created in the previous steps are saved in the configuration file of WordPress so that it can access it automatically. So, for that navigate to the WordPress directory we created previously and rename the sample configuration file by using the move command:

cd /var/www/html/wordpress/

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


Now open up the configuration file and just set the database name, username, and password as highlighted in the image below:

sudo nano wp-config.php

Once you have updated the details for the database in the WordPress configuration file, now there is an optional adjustment that you can do by adding the below code lines at the end of the file:

/* use the direct method to save files */

define( 'FS_METHOD', 'direct' );

/* Increase memory limit /

define('WP_MEMORY_LIMIT', '256M');

/* change database table prefix */

$table_prefix = 'wp_';

define( ‘FS_METHOD’, ‘direct’ ): To install and update the plugins or themes without providing conditionals every time WordPress can be directed to use the direct method for saving files. Which means it can write files without asking for FTP or SSH credentials.

define(‘WP_MEMORY_LIMIT’, ‘256M’): The default memory limit is 32 MB, which may not be enough for some sites so it is a preventive measure to increase the memory limit up to 256MB. As a result of this, the overall efficiency and stability of the website can be significantly improved.

$table_prefix = ‘wp_’; The table prefixes in WordPress are used to avoid any issue with the other tables and it can increase the security of the website. Using table prefixes makes it quite difficult for the attackers to guess your table names. Here by default wp_ is set but you set prefixes based on your preference don’t forget to use the underscore with the name.

Now add the security key for WordPress which it stores in the form of cookies and other site data. Normally you have to generate the keys from the official WordPress website and just place them in their placements in the configuration file:

It is always better to generate the keys prior to starting WordPress but if you do not add the keys then WordPress will generate it automatically.

Step 6: Configure Apache2 Server for WordPress

To successfully connect WordPress with the internet it is necessary to configure it with Apache properly. For that create a configuration file named the same as your domain name in the sites-available directory of the Apache2 server:

sudo nano /etc/apache2/sites-available/<domain-name>.conf

Here in the above command, you just need to replace the domain-name with your website name and then add the following lines of code:

<VirtualHost *:80>

ServerName yourdomain.com

ServerAlias www.yourdomain.com

DocumentRoot /var/www/html/wordpress

<Directory "/var/www/html/wordpress">

AllowOverride All

</Directory>

ErrorLog ${APACHE_LOG_DIR}/wordpress.error.log

CustomLog ${APACHE_LOG_DIR}/wordpress.access.log combined

</VirtualHost>

This code defines the settings for the WordPress site which includes the domain name, and server name along with the directory paths for saving the settings. Here in the code set your domain name and server name to the preferred one.

Step 7: Dry Run the Virtual Host

Once you have created the virtual host then just verify the file by testing it for any sort of errors and for that run the configuration test for the Apache server:

sudo apache2ctl configtest

Once there are no errors, then enable your website on the Apache server using your website configuration file:

sudo a2ensite <domian-name>.conf

Next, restart the Apache server to apply the changes:

sudo systemctl restart apache2

Step 8: Install WordPress Frontend

Once you are set now run the following address on your browser in Debian to start the WordPress frontend installation:

http://localhost/wp-login.php

After selecting the language click on Continue and in the next tab just fill up the necessary details and click on Install WordPress:

Once WordPress is installed log in to WordPress using the same credentials that you placed in the previous step:

Now the dashboard of WordPress will open and on the left side you will find the menu column from where you can manage your website:

Note: If you see an error of failed connection with the database then check for the password and username details in the configuration file of WordPress. If the credentials do not match with the database, the WordPress page won’t be able to load.

Conclusion

To install WordPress on Debian 12 you need to have a web server and a database server installed first and for that, you can install Apache2 and MariaDB. Next, install the backend for WordPress and then you have to create a database and share its credentials in the WordPress configuration file. Finally, run the local host on the browser and then install the front end of WordPress on Debian 12.

Similar Posts