v.01
How to solve best a step by step change to migrate from a working single VPS #hosting environment to a multi domain VPS hosting:
Step one
Create a new directory for the existing working domain in /var/www/
:
rootname@VPShosting:~# mkdir /var/www/domainorg/
Create a copy of the working installation from /var/www/html/
in the new /var/www/domainorg/
directory:
rootname@VPShosting:~# cp -R /var/www/html/ /var/www/domainorg/
Check ownership of /domainorg/ itself and folders in /domainorg/
rootname@VPShosting:~# ls -l /var/www/
rootname@VPShosting:~# ls -l /var/www/domainorg/
Create a domain registry file on the VPS server in /etc/apache2/sites-available/
for the domain:
rootname@VPShosting:~# nano /etc/apache2/sites-available/domainorg.conf
¡ OR ?
rootname@VPShosting:~# ¡ nano /etc/apache2/sites-available/domain.org.conf
?
Create the following content in that domain.org.conf file and safe it:
<VirtualHost *:80>
ServerAdmin badmin@domain.org
ServerName domain.org
DocumentRoot /var/www/domainorg
DirectoryIndex index.html
ErrorLog ${APACHE_LOG_DIR}/domainorg_error.log
CustomLog ${APACHE_LOG_DIR}/domainorg_access.log combined
</VirtualHost>
Check domain IP redirect settings by the domain registry!
Restart the Apache webserver to apply the configuration changes:
rootname@VPShosting:~# systemctl restart apache2
If the changes created were correct, the domain will start running from within the newly created directory tree. To check that this is true you can create a test index.html for that purpose while renaming the actual index.html to index_old.html in the old folder tree. If your site is still up and running after the following changes and not displaying the newly created test index.html, that means that it is served by the new folder structure.
Rename the existing index.html:
rootname@VPShosting:~# mv /var/www/html/index.html /var/www/html/index_old.html
Create a index.html test file for testing of the applied changes:
rootname@VPShosting:~# nano /var/www/html/index.html
Copy the following content into it and save it:
<html>
<title>name-based virtual hosting setup</title>
<h1>Welcome to the /html/ index.html fall back file.</h1>
<p>This is a test file for a name-based virtual hosting setup</p>
</html>
Step two
Create a subdomain test site:
rootname@VPShosting:~# mkdir /var/www/castdomainorg/
Create a index.html file to test the new subdomain.
rootname@VPShosting:~# nano /var/www/html/castdomainorg/index.html
<html>
<title>castdomainorg</title>
<h1>Welcome to cast.domain.org Website</h1>
<p>This is the first test subdomain site hosted with name-based virtual hosting</p>
</html>
Create ownership for the user www-data
for files and folders in /castdomainorg/
rootname@VPShosting:~# chown -R www-data:www-data /var/www/castdomainorg/
Create a domain registry file on the VPS server in /etc/apache2/sites-available/
for the subdomain:
rootname@VPShosting:~# nano /etc/apache2/sites-available/castdomainorg.conf
¡ OR ?
¡ rootname@VPShosting:~# nano /etc/apache2/sites-available/cast.domain.org.conf
?
Create the following content in that cast.domain.org.conf file and safe it:
<VirtualHost *:80>
ServerAdmin badmin@cast.domain.org
ServerName cast.domain.org
DocumentRoot /var/www/castdomainorg
DirectoryIndex index.html
ErrorLog ${APACHE_LOG_DIR}/castdomainorg_error.log
CustomLog ${APACHE_LOG_DIR}/castdomainorg_access.log combined
</VirtualHost>
Restart the Apache webserver to apply the configuration changes:
rootname@VPShosting:~# systemctl restart apache2
Set the subdomain IP redirect settings at the domain registry to the single VPS IP.
Depending on specific settings of the IP update routine, these changes can take up to a day to take effect and your subdomain index.html file should show up.
Once you are sure that everything worked out as intended you can delete the old /var/www/html/
files and folders and leave only the fall back index file in place. To do so you might first change the folder name, than recreate the folder, move the index.html fall back file to the new empty /html/ folder and than delete the old folder tree and it's content:
rootname@VPShosting:~# mv /var/www/html/ /var/www/html_old/
rootname@VPShosting:~# make /var/www/html/
rootname@VPShosting:~# mv /var/www/html_old/index.html /var/www/html/index.html
rootname@VPShosting:~# rm -r /var/www/html_old/