How to Install WordPress on DigitalOcean

How to Install WordPress on DigitalOcean
How to Install WordPress on DigitalOcean

Introduction

Install WordPress on DigitalOcean provides a simple and cost-effective way to host WordPress sites. By following the steps outlined in this guide, you can quickly set up WordPress on your DigitalOcean droplet.

Prerequisites

Before we get started with the installation, make sure you have the following:

A DigitalOcean Account

If you don’t have a DigitalOcean account yet, sign up for one at DigitalOcean.com.

A Droplet

Log in to your DigitalOcean control panel and create a droplet. You can choose the specifications according to your requirements.

A Domain Name (optional)

If you want your WordPress site to have a custom domain, ensure that you have registered it and mapped it to your droplet’s IP address.

Install WordPress

Now that you have everything ready let’s begin with the installation of WordPress on your DigitalOcean droplet.

Step 1: Connect to Your Droplet

Access your droplet by logging in through SSH or use the web-based console provided by DigitalOcean.

Step 2: Update the System

Before installing WordPress, ensure that your system is updated. To do so, run the following command:

sudo apt update && sudo apt upgrade

Step 3: Install LAMP Stack

WordPress requires a web server, PHP, and a database to work. Therefore, we need to install a LAMP stack on our droplet.

Install Apache

Run the following command to install Apache web server:

sudo apt install apache2

Install MySQL

Run the following command to install MySQL server version 8.0:

sudo apt install mysql-server-8.0

Install PHP

Run the following command to install PHP and its dependencies:

sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-xmlrpc php-mbstring php-xml

Step 4: Configure MySQL Database

Now that we have installed MySQL, we need to configure it to work with WordPress.

Create a Database

Log in to your MySQL server with the following command:

sudo mysql -u root -p

Enter the root password, and create a new database for your WordPress site:

CREATE DATABASE database_name;

Create a User

Create a new user for your WordPress site with the following command:

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';

Replace ‘username’ and ‘password’ with the desired values.

Grant Permissions to User

Grant the required permissions to the user with the following command:

GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';

Flush Privileges and Exit

After granting the necessary privileges, run the following command to flush them:

FLUSH PRIVILEGES;

Exit from the MySQL prompt by running the following command:

EXIT;

Step 5: Download and Install WordPress

By this point, you have everything set up to install WordPress on your droplet. Download and install WordPress with the following steps:

Download WordPress

Download the latest version of WordPress using the following command:

wget https://wordpress.org/latest.tar.gz

Extract and Move WordPress

Extract the downloaded file using the following command:

tar -xzf latest.tar.gz

Move the extracted WordPress directory to the Apache document root directory with the following command:

sudo mv wordpress/* /var/www/html/

Configure WordPress

Copy the default WordPress configuration file to create a new one:

sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

Open the new configuration file with a text editor:

sudo nano /var/www/html/wp-config.php

Add the following lines, replacing the placeholders with your database credentials:

define('DB_NAME', 'database_name');
define('DB_USER', 'username');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');

Save and exit the file.

Step 6: Configure Apache

Finally, we need to configure Apache to work with WordPress.

Configure Virtual Host

Create a new virtual host configuration file with the following command:

sudo nano /etc/apache2/sites-available/wordpress.conf

Add the following lines to the file, replacing the placeholders with your domain name:

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html
	ServerName your_domain_name.com
	ServerAlias www.your_domain_name.com
	<Directory /var/www/html>
		Options FollowSymLinks
		AllowOverride All
		Require all granted
	</Directory>
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save and close the file.

Enable Virtual Host

Enable the newly created virtual host with the following command:

sudo a2ensite wordpress.conf

Restart Apache

Restart the Apache webserver with the following command:

sudo systemctl restart apache2

Conclusion

You have successfully installed WordPress on your DigitalOcean droplet. Now you can access your WordPress site by visiting your domain name or IP address in a web browser. Enjoy creating How to Install WordPress on DigitalOcean website!

Published
Categorized as learning

Leave a comment

Your email address will not be published. Required fields are marked *