Note: This blog does not teach you about how to create a DigitalOcean droplet
To create a DigitalOcean cPanel and WHM droplet you can follow below links:
- https://docs.cpanel.net/knowledge-base/web-services/how-to-install-cpanel-on-digitalocean/
- https://marketplace.digitalocean.com/apps/cpanel-whm
These link will guide you to successfully create and deploy cPanel and WHM
droplet in DigitalOcean.
Prerequisite:
- you should have ssh access to your DigitalOcean droplet
If you don't know how to create you can follow the above links.
Let's get started:
Login to your remote connection
ssh [USER]@[IP_ADDRESS]
ssh [USER]@[IP_ADDRESS]
You will be prompted to enter password. Enter your password you have set while creating ssh key.
If all goes right then you will be connected to your DigitalOcean droplet.
Now go to /var/www/htmlcd /var/www/html
You have to put your project inside html folder. To check if that works you can create a index.html or edit if there already exists and go to the ip address you were provided.
How to deploy multiple website?
- go to /etc and edit hosts file
vi /etc/hosts - Now make directories for each sub-domain
mkdir -p /var/www/college
mkdir -p /var/www/student - You can put your project inside the folders you created
- Change context reference
chcon -R --reference=/var/www/html /var/www - Reset the security context for directory
restorecon -R /var/www - Now you have to assign the port, before that check the ports available
semanage port -l|grep -i http_port_T
netstat -tunlp|grep httpd - Normally you don't have to assign a port. By default port 80 is assigned. If you want to assign a port different from that or eg. 81 you can do that too.
semanage port -at http_port_t -p tcp 81 - Now you have to edit httpd.conf. Go to /etc/apache2/conf
cd /etc/apache2/conf
vi httpd.conf - Now add virtual host in httpd.conf<VirtualHost [IP_ADDRESS]:80>DocumentRoot /var/www/college
ServerName [SUBDOMAIN.MAIN_DOMAIN]
ServerAlias [MAIN_DOMAIN]
ServerAdmin [USER]@[IP_ADDRESS]</VirtualHost><Directory "/var/www/college">require all granted</Directory>
Note: in ServerName take reference from step-1, similarly you can add multiple hosts as you required. - check syntax you have wrote in httpd
httpd -t - Now reload httpd
systemctl reload httpd - Now if all things goes right. Open your browser and check your subdomains.