Install and Configure WordPress on Debian 12 with Easy Steps
In this comprehensive guide, we’ll walk you through the process to Install and Configure WordPress on Debian 12. WordPress, a leading free and open-source content management system (CMS) written in PHP, empowers countless websites worldwide. This article provides detailed steps to get your WordPress site up and running smoothly on a Debian 12 server.
This guide is crafted for users of all skill levels. Follow the instructions below to Install and Configure WordPress on Debian 12 using the well-established LAMP Stack (Linux, Apache, MySQL/MariaDB, PHP).
Requirements for WordPress Setup
Before diving into the installation process, ensure you meet the following prerequisites. These steps are essential for a secure and functional WordPress setup on your Debian 12 server.
-
Server Access: You must have access to your Debian 12 server as a non-root user with sudo privileges. A basic firewall should also be configured. Refer to this guide for initial server setup: Initial Server Setup with Debian 12 Bookworm.
-
LAMP Stack Installation: A fully functional LAMP Stack is necessary. If you haven’t already, follow this guide to install it: How To Install LAMP Stack on Debian 12.
-
SSL Certificate: Secure your Apache web server with an SSL certificate using Let’s Encrypt. This provides a secure connection for your website visitors. Follow this guide: Secure Apache with Let’s Encrypt on Debian 12.
Once you’ve fulfilled these requirements, you’re ready to proceed with the steps to Install and Configure WordPress on Debian 12.
Step 1 – Create WordPress Database and User on Debian 12
The first step involves setting up the database that WordPress will use to store its data. This includes creating a database and a dedicated user with appropriate privileges.
Log in to your MariaDB shell as the root user:
sudo mariadb -u root -p
From the MariaDB shell, execute the following command to create a database for WordPress. Choose a descriptive name like wordpressdb
:
-- MariaDB [(none)]>
CREATE DATABASE wordpressdb DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Next, create a database user with a strong password and grant all necessary privileges to this user for the newly created database:
-- MariaDB [(none)]>
GRANT ALL ON wordpressdb.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
Replace 'wordpressuser'
and 'password'
with your desired username and a strong, unique password.
Finally, flush the privileges to apply the changes and exit the MariaDB shell:
-- MariaDB [(none)]>
FLUSH PRIVILEGES;
-- MariaDB [(none)]>
EXIT;
Step 2 – Install PHP Extensions for WordPress
WordPress relies on several PHP extensions to function correctly. Install the necessary extensions using the following command:
sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip -y
After installing the extensions, restart the Apache web server to activate them:
sudo systemctl restart apache2
Step 3 – Apache Configuration for WordPress on Debian 12
Configure Apache to properly serve your WordPress site. You should already have a virtual host configuration file for your domain in the /etc/apache2/sites-available/
directory.
Open your Apache configuration file using a text editor (e.g., vi, nano):
sudo vi /etc/apache2/sites-available/your-domain.conf
Within the virtual host block (<VirtualHost *:80>
or <VirtualHost *:443>
), add the following block to allow Apache to override settings defined in the WordPress .htaccess
file. Ensure the path matches your website’s document root:
<Directory /var/www/your-domain/>
AllowOverride All
</Directory>
Save and close the file.
Enable the rewrite
module, which is required for WordPress permalinks:
sudo a2enmod rewrite
Test your Apache configuration for syntax errors:
sudo apache2ctl configtest
If the configuration is correct, you should see the following output:
Output
Syntax OK
Finally, restart Apache to apply the changes:
sudo systemctl restart apache2
Step 4 – Download Latest WordPress Package on Debian 12
Download the latest version of WordPress from the official website.
Navigate to the /tmp
directory:
cd /tmp
Use curl
to download the latest WordPress package:
sudo curl -O https://wordpress.org/latest.tar.gz
Extract the downloaded archive:
sudo tar xzvf latest.tar.gz
Create a dummy .htaccess
file within the extracted WordPress directory:
sudo touch /tmp/wordpress/.htaccess
Copy the sample configuration file to the filename WordPress actually reads:
sudo cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
Create an upgrade
directory to prevent permission issues during WordPress updates:
sudo mkdir /tmp/wordpress/wp-content/upgrade
Copy all the contents of the extracted WordPress directory to your website’s document root:
sudo cp -a /tmp/wordpress/. /var/www/your-domain
Step 5 – WordPress Configuration on Debian 12
Now that the WordPress files are in place, you need to configure the file ownership and permissions.
Update the ownership of the WordPress files to the www-data
user and group:
sudo chown -R www-data:www-data /var/www/your-domain
Set the appropriate permissions for directories and files:
sudo find /var/www/your-domain/ -type d -exec chmod 750 {} ;
sudo find /var/www/your-domain/ -type f -exec chmod 640 {} ;
Retrieve secure, unique values from the WordPress secret key generator:
sudo curl -s https://api.wordpress.org/secret-key/1.1/salt/
Important: Each time you run the command above, you should receive a different set of values. Do not reuse the example values provided in the original article.
Open the wp-config.php
file using a text editor:
sudo vi /var/www/your-domain/wp-config.php
Locate the section with the dummy values for the authentication keys and salts:
. . .
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
. . .
Replace the dummy values with the unique values you obtained from the WordPress secret key generator.
Next, configure the database connection settings at the top of the wp-config.php
file:
. . .
define('DB_NAME', 'wordpressdb');
/** MySQL database username */
define('DB_USER', 'wordpressuser');
/** MySQL database password */
define('DB_PASSWORD', 'password');
. . .
Enter the database name, username, and password you created in Step 1.
Finally, add the following line to the file to enable direct file modification (required for some themes and plugins):
define('FS_METHOD', 'direct');
Save and close the wp-config.php
file.
Step 6 – Access WordPress Web Interface
Complete the WordPress installation through the web interface.
Open your web browser and navigate to your domain name or server’s IP address:
https://server_domain_or_IP
Select your preferred language and click "Continue."
On the next page, enter the following information:
- Site The name of your WordPress site.
- Username: A username for the WordPress administrator account (avoid using "admin").
- Password: A strong password for the administrator account.
- Your Email: Your email address.
- Search Engine Visibility: Choose whether to discourage search engines from indexing your site.
Click "Install WordPress."
Once the installation is complete, you will be redirected to the login page. Enter your username and password to access your WordPress dashboard.
Congratulations! You have successfully installed and configured WordPress on Debian 12.
Conclusion
This guide has provided a step-by-step walkthrough to Install and Configure WordPress on Debian 12 using the LAMP stack. You also secured your installation using Let’s Encrypt and accessed your WordPress dashboard via a web browser.
You can now start building and customizing your WordPress website.
Alternative Solutions
While the LAMP stack provides a traditional and reliable approach, alternative solutions exist for deploying WordPress on Debian 12. Here are two alternative approaches:
1. Using Docker Compose
Docker allows you to containerize your application and its dependencies, making deployment more consistent and portable. Docker Compose simplifies the process of defining and managing multi-container Docker applications.
Explanation:
This method packages WordPress, MariaDB, and related services into separate Docker containers. Docker Compose then orchestrates these containers, handling networking and dependencies automatically. This simplifies setup and ensures consistent behavior across different environments.
Example docker-compose.yml
file:
version: "3.8"
services:
db:
image: mariadb:10.6
restart: always
environment:
MYSQL_ROOT_PASSWORD: your_root_password
MYSQL_DATABASE: wordpressdb
MYSQL_USER: wordpressuser
MYSQL_PASSWORD: your_wordpress_password
volumes:
- db_data:/var/lib/mysql
wordpress:
depends_on:
- db
image: wordpress:latest
restart: always
ports:
- "80:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpressuser
WORDPRESS_DB_PASSWORD: your_wordpress_password
WORDPRESS_DB_NAME: wordpressdb
volumes:
- wordpress_data:/var/www/html
volumes:
db_data:
wordpress_data:
Steps:
- Install Docker and Docker Compose on your Debian 12 system.
- Create a
docker-compose.yml
file with the above content, replacing placeholders with your actual passwords. - Run
docker-compose up -d
in the directory containing thedocker-compose.yml
file.
This will start the WordPress and MariaDB containers in detached mode. Access your WordPress site by navigating to http://localhost
in your web browser.
2. Using a Managed WordPress Hosting Provider
Managed WordPress hosting providers handle all the technical aspects of running a WordPress site, including server setup, security, updates, and backups.
Explanation:
Instead of managing the server yourself, you can offload the responsibility to a specialized hosting provider. This allows you to focus solely on creating and managing your website content.
Example Providers:
- WP Engine: Known for its performance and WordPress-specific features.
- Kinsta: Offers a premium managed WordPress hosting experience on Google Cloud Platform.
- SiteGround: A popular choice with a balance of features, performance, and affordability.
Steps:
- Choose a managed WordPress hosting provider that meets your needs and budget.
- Sign up for an account and select a hosting plan.
- Follow the provider’s instructions to set up your WordPress site. This usually involves choosing a domain name and installing WordPress with a few clicks.
This approach eliminates the need for server management and provides a hassle-free WordPress experience.