Setting up WordPress on a Linux server involves configuring the LAMP stack (Linux, Apache, MySQL, PHP), downloading WordPress, and configuring it for your website. Here’s a step-by-step guide to help you set up WordPress on a Linux server:
You need to have Apache (web server), MySQL (database), and PHP (server-side language) installed on your Linux server.
First, ensure your package list is up-to-date:
sudo apt update && sudo apt upgrade
sudo apt install apache2
After installation, start Apache and enable it to start automatically at boot:
sudo systemctl start apache2
sudo systemctl enable apache2
Install MySQL for managing your WordPress database:
sudo apt install mysql-server
Secure the MySQL installation:
sudo mysql_secure_installation
Follow the prompts to set up a root password and enhance security.
Install PHP and required modules:
sudo apt install php libapache2-mod-php php-mysql php-curl php-xml php-gd php-mbstring php-zip
Restart Apache to ensure PHP integrates with Apache:
sudo systemctl restart apache2
Log into MySQL as root:
sudo mysql -u root -p
Create a new MySQL database for your WordPress site:
CREATE DATABASE wordpress;
Create a new MySQL user and grant it privileges on the wordpress database:
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Navigate to the web root directory (usually /var/www/html) and download the latest WordPress files:
cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xvzf latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz
WordPress requires a configuration file. Rename wp-config-sample.php to wp-config.php:
sudo mv wp-config-sample.php wp-config.php
Edit the wp-config.php file to add your database details:
sudo nano wp-config.php
Find the following lines and update them with your database information:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost');
Make sure the web server (Apache) has the right permissions:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
Open a web browser and navigate to your server’s IP address (or domain):
http://your_server_ip/
Follow the WordPress installation prompts:
Once completed, you can log in to your WordPress dashboard at:
http://your_server_ip/wp-admin
Enable a Firewall (UFW)
You can use UFW (Uncomplicated Firewall) to allow only necessary traffic:
sudo ufw allow 'Apache Full'
sudo ufw enable
Secure MySQL
You can further configure MySQL security using the mysql_secure_installation command if not done already.
Enable HTTPS (SSL)
You can use Let’s Encrypt for free SSL certificates:
sudo apt install certbot python3-certbot-apache
sudo certbot --apache
Follow the prompts to configure SSL for your domain.
To manage your WordPress database more easily, install phpMyAdmin:
sudo apt install phpmyadmin
Select Apache during the setup process. You can access phpMyAdmin at:
http://your_server_ip/phpmyadmin
chown -R www-data:www-data folder/
cd folder/
find . -type d -exec chmod 755 {} \; && find . -type f -exec chmod 644 {} \;