Step 1: Update your server
Before installing anything, update your server’s package list and upgrade existing packages.
bash
Copy code
sudo apt update
sudo apt upgrade -y
Step 2: Install CURL
CURL helps retrieve files from the internet and will be necessary for downloading WordPress.
bash
Copy code
sudo apt install curl -y
Step 3: Install Apache
Apache will serve your WordPress website. Let’s install, start, and enable it to run on boot.
bash
Copy code
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
Step 4: Install MySQL
MySQL is the database WordPress uses to store data. Let’s install it and secure your installation.
bash
Copy code
sudo apt install mysql-server -y
sudo mysql_secure_installation
For the secure installation:
- Type “yes” for all prompts.
- Choose option “2” for strong password validation.
After securing MySQL, log in as the root user:
bash
Copy code
sudo mysql -u root -p
Step 5: Create a database and user for WordPress
Run these commands in the MySQL command line to set up the WordPress database and user. Replace ‘YourPasswordHere’ with a secure password.
sql
Copy code
CREATE DATABASE wordpress_db;
CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'YourPasswordHere';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 6: Install PHP
WordPress requires PHP to run dynamic content. We will install PHP along with the necessary modules.
bash
Copy code
sudo apt install php libapache2-mod-php php-mysql php-cli php-curl php-xml php-mbstring php-zip -y
sudo systemctl restart apache2
Step 7: Download and set up WordPress
- Go to the /tmp directory and download WordPress.
bash
Copy code
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
- Extract the downloaded archive and move it to Apache’s root directory.
bash
Copy code
tar xzvf latest.tar.gz
sudo mv wordpress /var/www/html/
- Set the correct permissions for WordPress files.
bash
Copy code
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress
Step 8: Configure Apache for WordPress
- Create a configuration file for your WordPress site.
bash
Copy code
sudo vi /etc/apache2/sites-available/wordpress.conf
- Add the following configuration. Replace example.com with your domain or server IP.
apache
Copy code
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/wordpress
ServerName example.com
<Directory /var/www/html/wordpress/>
Options FollowSymlinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
- Enable the WordPress site and rewrite the module.
bash
Copy code
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
Step 9: Configure WordPress
- Navigate to the WordPress directory.
bash
Copy code
cd /var/www/html/wordpress
- Rename the sample configuration file.
bash
Copy code
sudo mv wp-config-sample.php wp-config.php
- Edit the wp-config.php file to set your database details.
bash
Copy code
sudo vi wp-config.php
- Find and modify the following lines to match the database name, user, and password you set up:
php
Copy code
define( 'DB_NAME', 'wordpress_db' );
define( 'DB_USER', 'wordpress_user' );
define( 'DB_PASSWORD', 'YourPasswordHere' );
Step 10: Complete WordPress setup
Open your web browser and navigate to http://your_server_ip/wordpress. You should see the WordPress setup page. Follow the on-screen instructions to complete your setup.