We need well config & running a single server for hosting multiple websites.
I am using LINODE hosting for my all website & i have not facing any issue from this.
If you haven't hosting server or you mind to change your hosting provider, please refer below link.
Referral URL : https://www.linode.com/?r=74338d15b376adb3cf1e4d38f777fd7251d58d7d
Referral Code : 74338d15b376adb3cf1e4d38f777fd7251d58d7d
For hosting we are going to user Name Based Virtual Hosting (NBVH).
NBVH is commonly used for host multiple websites on same IP address or same server.
To host two or more websites on a single server follow below steps :
Step 1 : Create a website directory
Create a directory for website :
Use below command for create new directory.
mkdir /var/www/website-example.com
Step 2 : Put files in directory
Now put your code in this directory or create an index.html page with following command.
nano /var/www/website-example.com/index.html
Step 3 : Change directory permission
Next, change the ownership of website-example.com directory to www-data:
chown -R www-data:www-data /var/www/website-example.com
Step 4 : Create a virtual host configuration file
Now, you will need to create an apache virtual host configuration file to run two or more websites.
Create a virtual host config file for website-example.com.
Below command will create new file & open for editing.
nano /etc/apache2/sites-available/website-example.com.conf
Add the following lines in opened file, Save and close after editing.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/website-example.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/website-example.com/>
AllowOverride All
</Directory>
ServerName website-example.com
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.website-example.com [OR]
RewriteCond %{SERVER_NAME} =website-example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Step 5 : Enable new site config
Enable the new created virtual host configuration file with the following commands :
a2ensite website-example.com
Step 6 : Restart apache server
Restart apache for new changes.
systemctl restart apache2
Step 7 : Run new website
Now, open your preferred browser and run URL http://website-example.com.
That's all done here.