To install WordPress on a Linux server with Apache2, follow these steps:
1. Update System Packages
Start by updating your system’s package index:
sudo apt update && sudo apt upgrade -y
2. Install Apache2, MySQL, and PHP
You’ll need Apache2, MySQL (or MariaDB), and PHP with the necessary extensions to run WordPress:
sudo apt install apache2 mysql-server php php-mysqli php-gd php-curl php-xml php-mbstring php-zip unzip -y
3. Configure MySQL Database for WordPress
Create a database and user for WordPress in MySQL:
sudo mysql -u root -p
After logging into MySQL, run the following commands:
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
4. Download and Configure WordPress
Go to the /var/www/html
directory (default web root for Apache):
cd /var/www/html
Download the latest version of WordPress:
sudo wget https://wordpress.org/latest.tar.gz
Extract the WordPress archive:
sudo tar -xzvf latest.tar.gz
Move the WordPress files into the web root:
sudo mv wordpress/* ./
Remove the extracted folder and tar file:
sudo rm -rf wordpress latest.tar.gz
5. Set Permissions
Set the correct file permissions for the web server:
sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/
6. Configure WordPress Settings
Rename the wp-config-sample.php
file to wp-config.php
:
sudo mv wp-config-sample.php wp-config.php
Edit wp-config.php
to configure the database:
sudo nano wp-config.php
Modify the following lines to match your MySQL settings:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpressuser');
define('DB_PASSWORD', 'yourpassword');
define('DB_HOST', 'localhost');
7. Restart Apache2
Restart Apache to apply the changes:
sudo systemctl restart apache2
8. Complete the Installation in the Web Browser
Open your web browser and go to your server’s IP address or domain name:
http://your-server-ip/
Follow the on-screen instructions to complete the WordPress setup, such as selecting the language, setting up the site title, and creating an admin account.
That’s it! Your WordPress site should now be up and running on Apache2.