How To Install WordPress On Debian Linux
Here’s an article on how to install WordPress on a Linux server, whether you’re using Ubuntu, Debian, or similar distributions. This guide assumes you’re installing WordPress on a local server or a VPS and want to use Apache, MySQL (or MariaDB), and PHP (known as the LAMP stack).
Step 1: Update System Packages
Open your terminal and run:
sudo apt update && sudo apt upgrade -y
Step 2: Install Apache Web Server
sudo apt install apache2 -y
Verify Apache is working:
sudo systemctl status apache2
Test in your browser:
Visit http://localhost/ or your server’s IP.
Step 3: Install MySQL Server (or MariaDB)
Install MySQL:
sudo apt install mysql-server -y
Secure MySQL installation:
sudo mysql_secure_installation
During this:
- Set a root password.
- Answer prompts to remove anonymous users, test DB, etc.
Step 4: Install PHP and Required Extensions
sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip -y
Check PHP version:
php -v
Step 5: Restart Apache to Enable PHP
sudo systemctl restart apache2
Step 6: Create a MySQL Database for WordPress
- Log into MySQL:
sudo mysql -u root -p
- Create a database:
CREATE DATABASE wordpress_db DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
- Create a user and grant privileges:
CREATE USER ‘wp_user’@’localhost’ IDENTIFIED BY ‘your_strong_password’;
GRANT ALL PRIVILEGES ON wordpress_db.* TO ‘wp_user’@’localhost’;
FLUSH PRIVILEGES;
EXIT;
Step 7: Download WordPress
Navigate to /tmp, download and extract:
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
Step 8: Move WordPress Files to Web Directory
sudo mv wordpress /var/www/html/
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress
Step 9: Configure Apache for WordPress
Create a new virtual host:
sudo nano /etc/apache2/sites-available/wordpress.conf
Paste the following:
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/wordpress
ServerName example.com
<Directory /var/www/html/wordpress/>
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 (Ctrl+O, then Ctrl+X).
Enable the site and .htaccess overrides:
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl reload apache2
Step 10: Configure WordPress
Copy sample config and edit:
cd /var/www/html/wordpress
cp wp-config-sample.php wp-config.php
nano wp-config.php
Update these values:
define( ‘DB_NAME’, ‘wordpress_db’ );
define( ‘DB_USER’, ‘wp_user’ );
define( ‘DB_PASSWORD’, ‘your_strong_password’ );
define( ‘DB_HOST’, ‘localhost’ );
Save and exit.
Step 11: Complete Installation in Browser
- Open your browser.
- Visit:
http://localhost/wordpress or http://your-server-ip/wordpress - Follow the setup:
- Select language
- Set site title, admin username, password, and email
- Finish installation
Post-Installation Tips:
- Delete wp-config-sample.php
- Set file permissions carefully (avoid 777)
- Secure /wp-admin/ with .htaccess or fail2ban
- Consider installing a firewall (e.g., ufw)