Installing WordPress on Debian
This is our walkthrough on installing WordPress on a Debian server. WordPress is a powerful, open-source content management system (CMS) that powers a significant portion of the web. It's renowned for its flexibility and ease of use, making it an excellent choice for bloggers, businesses, and everyone in between. Debian, with its reputation for stability and reliability, provides a robust platform for hosting WordPress websites.
In this tutorial, we'll cover every step, from setting up your Debian server to customizing your WordPress installation.
Prerequisites
Before we dive in, ensure you have the following:.
- A Debian server with root access or a user with
sudo
privileges. - A domain name pointed to your server's IP address.
- Basic knowledge of the command line interface (CLI).
Step 1: Updating Your Server
First things first, let's make sure your server's package list and installed packages are up to date. This is akin to cleaning and organizing your workspace before starting a new project.
sudo apt update && sudo apt upgrade
My Output : After running the command, you'll see a list of packages that can be upgraded. Confirm the upgrade, and wait for the process to complete.
Step 2: Installing LAMP Stack
WordPress requires a LAMP stack (Linux, Apache, MySQL, PHP). Let's install these components.
Apache
Install Apache with the following command:.
sudo apt install apache2
What to Watch Out For : Ensure Apache is running correctly by visiting your server's IP address in a web browser. You should see the default Apache2 Debian page.
MySQL
Next, install MySQL:.
sudo apt install mysql-server
After installation, secure your MySQL installation by running:.
sudo mysql_secure_installation
Follow the prompts to set a root password, remove anonymous users, disallow root login remotely, remove the test database, and reload privilege tables.
PHP
Install PHP and its required extensions:.
sudo apt install php php-mysql libapache2-mod-php php-imagick php-mbstring php-curl php-xmlrpc php-gd php-intl php-soap php-zip
My Output : The terminal will show the installation progress and confirm once completed.
Step 3: Configuring Apache for WordPress
We need to configure Apache to handle WordPress URL rewrites properly.
sudo a2enmod rewrite
sudo systemctl restart apache2
Now, create a new Apache configuration file for your domain:.
sudo nano /etc/apache2/sites-available/yourdomain.com.conf
Add the following configuration, replacing yourdomain.com
with your actual domain and /path/to/wordpress
with the path where you will install WordPress:.
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /path/to/wordpress
<Directory /path/to/wordpress/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/yourdomain.com_error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain.com_access.log combined
</VirtualHost>
Enable the site and reload Apache:.
sudo a2ensite yourdomain.com.conf
sudo systemctl restart apache2
My Output : Apache should now be serving your domain, and visiting it should give you a 404 error since we haven't installed WordPress yet.
Step 4: Setting Up the Database
Log in to MySQL:.
sudo mysql -u root -p
Create a database and user for WordPress:.
CREATE DATABASE wordpressdb;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace wordpressdb
, wpuser
, and strongpassword
with your chosen database name, username, and password.
Step 5: Installing WordPress
Download the latest WordPress version:.
cd /tmp
wget https://wordpress.org/latest.tar.gz
Extract the files:.
tar xzf latest.tar.gz
Copy the WordPress files to your web root:.
sudo cp -a /tmp/wordpress/* /path/to/wordpress
Set the correct permissions:.
sudo chown -R www-data:www-data /path/to/wordpress
sudo find /path/to/wordpress -type d -exec chmod 750 {} \;
sudo find /path/to/wordpress -type f -exec chmod 640 {} \;
My Output : The WordPress files are now in place, and the web server has the necessary permissions to manage them.
Step 6: Configuring WordPress
Rename the wp-config-sample.php
file to wp-config.php
and edit it:.
cd /path/to/wordpress
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php
Update the database details with the credentials you created earlier:.
define('DB_NAME', 'wordpressdb');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'strongpassword');
define('DB_HOST', 'localhost');
Save and close the file.
Step 7: Completing the Installation
Open your web browser and navigate to your domain. You should be greeted by the WordPress installation wizard. Follow the on-screen instructions to complete the installation, which includes setting up your site title, admin username, and password.
My Output : After completing the wizard, you should see the WordPress admin dashboard, indicating a successful installation.
Step 8: Securing Your WordPress Site
- SSL Certificate: Use Let's Encrypt to obtain a free SSL certificate and configure Apache to redirect HTTP traffic to HTTPS.
- Firewall: Set up a firewall using
ufw
or a similar tool to protect your server. - WordPress Security Plugins: Install security plugins like Wordfence or Sucuri to enhance your site's security.
Step 9: Maintenance and Updates
Regularly update your WordPress core, themes, and plugins to keep your site secure. You can do this from the WordPress dashboard or by using WP-CLI, a command-line interface for WordPress.
Hopefully you've successfully installed WordPress on your Debian server. With your new WordPress site, the possibilities are endless.