How to Install WordPress on a Debian Server
In my previous article, I explained how I launch a Debian server on AWS, secure it, and test it with Apache. Now, I’ll take it a step further and show you how I install WordPress on that server.
WordPress is one of the most popular website platforms, and with a few simple steps, you can get it running on your own instance.
1. Install the Required Packages
WordPress needs a web server, database, and PHP to run. Since we already have Apache, let’s install MySQL and PHP:
sudo apt update
sudo apt install -y mysql-server php php-mysql libapache2-mod-php php-cli unzip curl
This gives us everything WordPress needs to talk to the database and serve dynamic pages.
2. Secure MySQL and Create a Database
Set up MySQL securely with:
sudo mysql_secure_installation
Then log into MySQL:
sudo mysql -u root -p
Inside the MySQL shell, create a database and user for WordPress:
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
3. Download and Configure WordPress
Grab the latest WordPress release:
cd /tmp
curl -O https://wordpress.org/latest.zip
unzip latest.zip
Move it into the web directory:
sudo mv wordpress /var/www/html/
sudo chown -R www-data:www-data /var/www/html/wordpress
4. Configure Apache
Create a new site config:
sudo nano /etc/apache2/sites-available/wordpress.conf
Add:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/wordpress
ServerName yourdomain.com
<Directory /var/www/html/wordpress/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable it:
sudo a2ensite wordpress
sudo a2enmod rewrite
sudo systemctl reload apache2
5. Connect WordPress to the Database
Copy the sample config file:
cd /var/www/html/wordpress
cp wp-config-sample.php wp-config.php
nano wp-config.php
Edit these lines:
define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wpuser' );
define( 'DB_PASSWORD', 'strongpassword' );
Save and exit.
6. Complete Installation in the Browser
Now go to http://yourdomain.com
in your browser. You should see the WordPress setup screen where you can:
- Choose your site title
- Create the admin username/password
- Log into your new WordPress dashboard 🎉
Conclusion
With just a few commands, you now have WordPress running on your Debian server. From here, you can install themes, add plugins, and start building your site.