Configure and deploy multiple website in DigitalOcean droplet (cPanel and WHM on CentOS)

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:

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]

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/html  
cd /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?

  1. go to /etc and edit hosts file
    vi /etc/hosts




    You will see your main domain already hosted. To host multiple website you can copy the main domain and then add subdomain to it. All three are same except first one is main domain, second and third are subdomain created. You can name anything you want. 
  2. Now make directories for each sub-domain
    mkdir -p /var/www/college
    mkdir -p /var/www/student


  3. You can put your project inside the folders you created
  4. Change context reference 
    chcon -R --reference=/var/www/html /var/www 
  5. Reset the security context for directory
    restorecon -R /var/www
  6. 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
  7. 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 
  8. Now you have to edit httpd.conf. Go to /etc/apache2/conf
    cd /etc/apache2/conf
    vi httpd.conf
  9. 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.

  10. check syntax you have wrote in httpd
    httpd -t
  11. Now reload httpd
    systemctl reload httpd
  12. Now if all things goes right. Open your browser and check your subdomains.

Post a Comment

Previous Post Next Post