In this tutorial, we will learn how to set up WordPress and how to host multiple WordPress websites on a single DigitalOcean droplet using Apache2.
In this guide, we will be using Ubuntu 20.04.
Before we start
- Create a new droplet on DigitalOcean
- Set up two domains with DigitalOcean. This tutorial will help you to set domains on DigitalOcean
- Install LAMP stack on Ubuntu using this guide
Installing WordPress
Our first step would be to install WordPress, write the following commands in the terminal to install WordPress.
wget http://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
Creating WordPress Database and Users
The next step involves creating a database and users for WordPress by using MySQL for individual sites.
Log into MySQL using the administrator account you configured during the MySQL installation:
mysql -u root -p
Enter the password and you will enter into MySQL prompt.
Creating Databases
Now we will create databases for our individual websites.
CREATE DATABASE DatabaseOne;
CREATE DATABASE DatabaseTwo;
Creating Users
We then create Users for our MySQL database.
Note(There is a difference between the MySQL Users and Linux users).
We are creating users for our MySQL database and UserOne
has no access to UserTwo
details.
CREATE USER UserOne@localhost;
CREATE USER UserTwo@localhost;
Setting up Passwords
SET PASSWORD FOR 'UserOne'@'localhost' = 'PasswordOne';
SET PASSWORD FOR 'UserTwo'@'localhost' = 'PasswordTwo';
Giving Privileges
GRANT ALL ON DatabaseOne.* TO 'UserOne'@'localhost';
GRANT ALL ON DatabaseTwo.* TO 'UserTwo'@'localhost';
Refresh MySQL's privilege information to implement the changes
FLUSH PRIVILEGES;
exit MySQL
exit
Site Root Directories Configuration
Now, we will be creating separate directories for each site.
Change the directory to /var/www/
cd /var/www
Create a directory for each site:
sudo mkdir SiteOne
sudo mkdir SiteTwo
Copy the sample configuration before we move the web contents into our folders:
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
Now, we will copy the WordPress files to our both directories:
There are many ways you can put WordPress files in your Websites folder.
First method is to put WordPress files into GitHub and clone it in your Websites folder.
Second method is to use
Rsync
. This tutorial will help you to learn more about Rsync
In our case, we will be using Rsync
.
udo rsync -avP ~/wordpress/ /var/www/SiteOne/
sudo rsync -avP ~/wordpress/ /var/www/SiteTwo/
It's time to give ownership of directories to Apache
sudo chown www-data:www-data * -R
Now add Linux username to web group:
sudo usermod -a -G www-data your_linux_user_name
(Make sure to use your Linux username at the end of the above command)
WordPress Configuration
We already have copied WordPress files to each of our website directories.
Now, we will configure WordPress.
Change your directories to /var/www
cd /var/www
First website Configuration
Go to your first site:
cd SiteOne
Open WordPress Configuration file:
sudo nano wp-config.php
Find the section that contains the fields below and substitute the database, username, and password for your first site:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'DataBaseOne');
/** MySQL database username */
define('DB_USER', 'UserOne');
/** MySQL database password */
define('DB_PASSWORD', 'PasswordOne');
Save this file and exit.
Now, we will configure the second file.
Second website Configuration
Go to second site folder:
cd SiteTwo
Open WordPress Configuration file:
sudo nano wp-config.php
Find the section that contains the fields below and substitute the database, username, and password for your first site:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'DataBaseTWo');
/** MySQL database username */
define('DB_USER', 'UserTwo');
/** MySQL database password */
define('DB_PASSWORD', 'PasswordTwo');
Save this file and exit.
Apache Virtual Host Configuration
Go to etc/apache2/sites-available
cd /etc/apache2/sites-available
Create a new virtual host configuration file for each website:
cat > SiteOne.conf
cat > SiteTwo.conf
Open first configuration file:
sudo nano SiteOne.conf
Change the info. as you need:
<VirtualHost *:80>
ServerAdmin admin@SiteOne
ServerName SiteOne.com
ServerAlias www.SiteOne.com
DocumentRoot /var/www/SiteOne
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/SiteOne>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Open second configuration file:
sudo nano SiteTwo.conf
Change the info. as you need:
<VirtualHost *:80>
ServerAdmin admin@SiteTwo
ServerName SiteTwo.com
ServerAlias www.SiteTwo.com
DocumentRoot /var/www/SiteTwo
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/SiteTwo>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Enabling configuration file
sudo a2ensite SiteOne.conf
sudo a2ensite SiteTwo.conf
Reloading Apache to save configuration:
sudo service apache2 reload
Now, you have successfully installed two WordPress sites on a single DigitalOcean Droplet.
If you have not made any mistake, you will see WordPress Welcome pages on both of your domains.
You can access the WordPress admin page by writing yoursitename.com/wp-admin
.
I hope this article was very helpful. If you have any questions feel free to ask in the comments.
If you have some suggestions, feel free to share.
Thank you!!
Top comments (0)