How to Set Up a WordPress Site on Debian 12 Bookworm Using Apache
Categories:
5 minute read
WordPress is one of the most widely used content management systems (CMS) in the world. With its flexibility, extensive plugin ecosystem, and active community, it’s the go-to choice for bloggers, small businesses, and developers alike. If you’re running Debian 12 “Bookworm” and want to host your WordPress site using Apache, this guide walks you through the process step by step — from installing required packages to accessing your new site in a web browser.
Table of Contents
- Table of Contents
- Prerequisites
- Step 1: Update Your System
- Step 2: Install Apache Web Server
- Step 3: Install PHP and Required Modules
- Step 4: Install MariaDB and Secure It
- Step 5: Create a WordPress Database and User
- Step 6: Download and Configure WordPress
- Step 7: Configure Apache for WordPress
- Step 8: Enable the Site and Restart Apache
- Step 9: Complete WordPress Installation via Web Browser
- Conclusion
Prerequisites
Before beginning the installation process, ensure you have:
- A Debian 12 “Bookworm” system (either bare-metal or virtualized)
- Root access or a user with
sudo
privileges - A basic understanding of Linux terminal commands
- An active internet connection
Step 1: Update Your System
Start by updating your system’s package index and upgrading installed packages:
sudo apt update && sudo apt upgrade -y
It’s always a good practice to make sure your system is up-to-date before installing new software.
Step 2: Install Apache Web Server
Apache is a powerful and widely-used open-source web server. Install it with:
sudo apt install apache2 -y
Once installed, enable and start Apache:
sudo systemctl enable apache2
sudo systemctl start apache2
You can verify the installation by visiting your server’s IP address in a web browser:
http://your-server-ip
You should see the default Apache welcome page.
Step 3: Install PHP and Required Modules
WordPress is written in PHP, so you’ll need to install PHP along with several commonly used modules:
sudo apt install php php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip libapache2-mod-php -y
To check the installed PHP version:
php -v
Debian 12 typically ships with PHP 8.2, which is supported by WordPress.
Step 4: Install MariaDB and Secure It
MariaDB is a drop-in replacement for MySQL and is well-supported by WordPress. Install it with:
sudo apt install mariadb-server mariadb-client -y
Enable and start the database service:
sudo systemctl enable mariadb
sudo systemctl start mariadb
Then run the security script to harden your installation:
sudo mysql_secure_installation
You’ll be asked several questions, such as setting a root password and removing anonymous users. It’s recommended to answer “yes” to most of the prompts for a more secure setup.
Step 5: Create a WordPress Database and User
Now, log into the MariaDB shell to create the WordPress database:
sudo mariadb -u root -p
Then execute the following commands:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL ON wordpress.* TO 'wpuser'@'localhost' IDENTIFIED BY 'strong_password_here';
FLUSH PRIVILEGES;
EXIT;
Replace 'strong_password_here'
with a secure password and save it — you’ll need it later.
Step 6: Download and Configure WordPress
Navigate to the /tmp
directory and download the latest WordPress package:
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
Move the WordPress files to your Apache web directory:
sudo rsync -avP wordpress/ /var/www/html/
Set the correct permissions:
sudo chown -R www-data:www-data /var/www/html/
sudo find /var/www/html/ -type d -exec chmod 755 {} \;
sudo find /var/www/html/ -type f -exec chmod 644 {} \;
Copy the sample config file:
cd /var/www/html
sudo cp wp-config-sample.php wp-config.php
Edit the wp-config.php
file:
sudo nano wp-config.php
Find the following lines and update them with your database details:
define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wpuser' );
define( 'DB_PASSWORD', 'strong_password_here' );
define( 'DB_HOST', 'localhost' );
Also, to enhance security, you should add authentication keys and salts. You can generate them at:
https://api.wordpress.org/secret-key/1.1/salt/
Copy the generated keys and replace the corresponding placeholder lines in wp-config.php
.
Step 7: Configure Apache for WordPress
Create a new virtual host file for your WordPress site:
sudo nano /etc/apache2/sites-available/wordpress.conf
Paste the following configuration (replace your_domain_or_ip
accordingly):
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName your_domain_or_ip
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save and exit the file, then enable the configuration:
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
Step 8: Enable the Site and Restart Apache
Disable the default site if necessary:
sudo a2dissite 000-default.conf
Restart Apache to apply all changes:
sudo systemctl restart apache2
Step 9: Complete WordPress Installation via Web Browser
Open your web browser and navigate to:
http://your_domain_or_ip
You should see the WordPress installation page. Follow the on-screen instructions:
- Select your language.
- Enter your site title, admin username, password, and email.
- Click “Install WordPress.”
Once completed, you can log in to the admin panel at:
http://your_domain_or_ip/wp-login.php
Conclusion
Congratulations! You’ve successfully installed and configured a WordPress site on Debian 12 Bookworm using Apache. With Apache serving your web content, PHP handling the server-side logic, and MariaDB managing your data, you now have a full LAMP stack tailored for WordPress.
From here, you can install themes, configure plugins, and start publishing your content. To improve your setup further, consider enabling HTTPS with Let’s Encrypt, setting up scheduled backups, and optimizing your server for performance.
Running your own WordPress instance on Debian gives you full control over your website’s environment — and with the stability and performance of Debian, it’s a great foundation for long-term projects.
If you run into any issues or want to expand your setup (e.g., adding SSL or using a reverse proxy), there’s a rich ecosystem of tools and tutorials to help guide you. Enjoy your new WordPress-powered website!
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.