debian

How To Install WordPress On Debian 12

WordPress is a popular content management system (CMS) used for creating and managing websites. It is an open-source platform written in PHP and paired with a MySQL or MariaDB database. WordPress provides a user-friendly interface and a wide range of themes, plugins, and customization options, making it accessible to users with varying levels of technical expertise.

In this tutorial we’ll show you how to install WordPress on Debian 12 OS.


Step 1: Update Operating System

Update your Debian 12 operating system to make sure all existing packages are up to date:

sudo apt update && apt upgrade

Also, install necessary packages:

sudo apt install nano wget unzip

Step 2: Install Nginx web server on Debian 12

To install Nginx, run the following command:

sudo apt intsall nginx

You can start the Nginx service and configure it to run on startup by entering the following commands:

sudo systemctl start nginx

sudo systemctl enable nginx

Verify the status of the Nginx service using systemctl status command:

sudo systemctl status nginx

● nginx.service – A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; preset: enabled)
Active: active (running)
Docs: man:nginx(8)
Process: 674 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 873 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 875 (nginx)
Tasks: 2 (limit: 2273)
Memory: 4.5M
CPU: 402ms
CGroup: /system.slice/nginx.service
├─875 “nginx: master process /usr/sbin/nginx -g daemon on; master_process on;”
└─876 “nginx: worker process”

Step 3: Install PHP and PHP extensions for WordPress

You can install PHP and other supporting packages using the following command:

sudo apt install php php-curl php-fpm php-bcmath php-gd php-soap php-zip php-curl php-mbstring php-mysqlnd php-gd php-xml php-intl php-zip

Verify if PHP is installed.

php -v

Output:

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

After installing all the packages, edit the php.ini file:

sudo nano /etc/php/8.2/fpm/php.ini

Change the following settings per your requirements:

max_execution_time = 300
memory_limit = 512M
post_max_size = 128M
upload_max_filesize = 128M

To implement the changes, restart the php-fpm service:

sudo systemctl restart php8.2-fpm

Step 4: Install MariaDB Database Server

You can install MariaDB with the following command:

sudo apt install mariadb-server mariadb-client

Start the database server daemon, and also enable it to start automatically at the next boot with the following commands:

sudo systemctl start mariadb

sudo systemctl enable mariadb

Verify the status of the MariaDB service using systemctl status command:

sudo systemctl status mariadb

Output:

● mariadb.service – MariaDB 10.11.3 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; preset: enabled)
Active: active (running)
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 959 (mariadbd)
Status: “Taking your SQL requests now…”
Tasks: 12 (limit: 2273)
Memory: 256.5M
CPU: 6.621s
CGroup: /system.slice/mariadb.service
└─959 /usr/sbin/mariadbd

Once the database server is installed, run the following command to secure your MariaDB server:

sudo mysql_secure_installation

You will then be asked several configuration questions, which you must answer Y to each of them.

Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y

Restart the database server for the changes to take effect.

sudo systemctl restart mariadb

Step 5: Create a New Database for WordPress

To do this, log in to your MariaDB server using the following command:

sudo mysql -u root -p

Run the following commands to create a new database and user:

MariaDB [(none)]> CREATE DATABASE wordpress_db;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress_db.* TO ‘wordpress_user’@’localhost’ IDENTIFIED BY ‘password’;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT

Note: Make sure to replace ‘password’ with a strong password of your choice.
Step 6: Download WordPress

We will now download the latest version of WordPress from the WordPress Official site.

Use the following command to download WordPress:

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

Extract file into the folder /var/www/html/ with the following command,

sudo unzip latest.zip -d /var/www/html/

Next, navigate to the /var/www/html/wordpress/ directory:

cd /var/www/html/wordpress

WordPress comes with a configuration sample file. Make a copy of this file:

sudo cp wp-config-sample.php wp-config.php

Next, edit the WordPress configuration file and define your database settings:

sudo nano wp-config.php

Change the following lines that match your database settings:

/** The name of the database for WordPress */
define( ‘DB_NAME’, ‘wordpress_db’ );

/** MySQL database username */
define( ‘DB_USER’, ‘wordpress_user’ );

/** MySQL database password */
define( ‘DB_PASSWORD’, ‘password’ );

/** MySQL hostname */
define( ‘DB_HOST’, ‘localhost’ );

Save the file when you are finished.

Change the permission of the website directory:

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

Step 7: Configure Nginx Web Server for WordPress

Navigate to /etc/nginx/conf.d directory and run the following command to create a configuration file for your installation:

sudo nano /etc/nginx/conf.d/wordpress.conf

Add the following content:

 server {
	server_name yoursite.name www.yoursite.name;

	root /var/www/html/yoursitename;
	index index.html index.htm index.php;

	client_max_body_size 64M;  # Increase this value as needed

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

	location ~ \.php$ {
			include snippets/fastcgi-php.conf;
			fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; # change version if needed
	}

	location ~ /\.ht {
			deny all;
	}
	location ~* \.(jpg|jpeg|png|gif|ico|svg|webp)$ {
			expires 30d;
			add_header Cache-Control "public, no-transform";
	}

}

Save the file and Exit.

Restart the Nginx web server.

sudo systemctl restart nginx

Step 8: Access WordPress Web Installer

Open your browser type your domain e.g http://your-domain.com You will be redirected to the language selection screen:

Installation wizard

wordpress install 900x507 1

Select your language and click on the Continue button.

Welcome page

Provide the requested information and click on the Install WordPress button. Once the installation has been finished. You should see the following screen:

WordPress success installation

Click on the Log in button. You should see the WordPress login screen:

WordPress login page

Enter your administrator user, password and click on the Log In button. You will get the dashboard in the following screen:

wordpress dashboard 900x432 1