Apache is divided into units that can be customized and configured individually. These sections are called virtual hosts.<\/p>\n
Virtual hosts allow the administrator to use one server to host many domains using a single IP. This is useful for anyone who wants to host more than one website on the same VPS, never indicating that the same server is also hosting other sites. This process can be repeated without limit, depending on the load that your server can handle.<\/p>\n
In order to work through these steps, you will need to have:<\/p>\n
My configuration will make virtual hosts for\u00a0 The document root will be set to individual directories under the\u00a0 The directories that you have created are owned by the root user. You have to change the ownership for the regular user to be able to modify files.\u00a0 You should also modify permissions to the general web directory and all of the files and folders within it.<\/p>\n Make an\u00a0 In this HTML file, you can place simple content just to indicate that your your configuration works. For example, my file looks like this.<\/p>\n Save and close the file when you are finished.<\/p>\n Now copy this file to the second site.<\/p>\n You can then open and modify it.<\/p>\n Save and close this file when you are finished.<\/p>\n Virtual host files specify the configuration of our virtual hosts and dictate how the Apache web server will respond to different domain requests.<\/p>\n Apache comes with a default virtual host file,\u00a0 The file will look like this (without comments):<\/p>\n Change the\u00a0 The virtual host file should resemble the following.<\/p>\n Save and close the file.<\/p>\n You can do the same with the second domain.<\/p>\n You now need to modify it to reference your second domain.<\/p>\n Save and close the file when you are finished.<\/p>\n The\u00a0 When you are finished, you need to restart Apache to make these changes take effect:<\/p>\n If you receive this message:<\/p>\n … don’t worry, that does not affect our sites.<\/p>\n Now that you have your virtual hosts configured, you can test them by going to the domains that you configured in your web browser:<\/p>\n If both of these sites work, you’ve successfully configured two virtual hosts on the same server.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","manualknowledgebasecat":[109,242],"manual_kb_tag":[488],"_links":{"self":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2993"}],"collection":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/comments?post=2993"}],"version-history":[{"count":1,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2993\/revisions"}],"predecessor-version":[{"id":2994,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2993\/revisions\/2994"}],"wp:attachment":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/media?parent=2993"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manualknowledgebasecat?post=2993"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb_tag?post=2993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}test1.com<\/code>\u00a0and\u00a0
test2.com<\/code>. You should substitute these with your own domains.<\/p>\n
Create the directories<\/h3>\n
\/var\/www<\/code>\u00a0folder. Create a directory here for both of the virtual hosts, like this:<\/p>\n
sudo mkdir \/var\/www\/test1\r\nsudo mkdir \/var\/www\/test2\r\n<\/code><\/pre>\n
Permissions<\/h3>\n
$USER<\/code>\u00a0is the user in which you are currently logged in.<\/p>\n
sudo chown -R $USER:$USER \/var\/www\/test1\r\nsudo chown -R $USER:$USER \/var\/www\/test2\r\n<\/code><\/pre>\n
sudo chmod -R 755 \/var\/www\r\n<\/code><\/pre>\n
Create pages for each virtual host<\/h3>\n
index.html<\/code>\u00a0page for each site.<\/p>\n
nano \/var\/www\/test1\/index.html\r\n<\/code><\/pre>\n
<html>\r\n <head>\r\n <title>test1<\/title>\r\n <\/head>\r\n <body>\r\n <h1>test1.com virtual host !<\/h1>\r\n <\/body>\r\n<\/html>\r\n<\/code><\/pre>\n
cp \/var\/www\/test1\/index.html \/var\/www\/test2\/index.html\r\n<\/code><\/pre>\n
nano \/var\/www\/test2\/index.html\r\n\r\n<html>\r\n <head>\r\n <title>test2<\/title>\r\n <\/head>\r\n <body>\r\n <h1>test2.com virtual host !<\/h1>\r\n <\/body>\r\n<\/html>\r\n<\/code><\/pre>\n
Create virtual host files<\/h3>\n
000-default.conf<\/code>. Copy this file and modify it for the first domain.<\/p>\n
sudo cp \/etc\/apache2\/sites-available\/000-default.conf \/etc\/apache2\/sites-available\/test1.conf\r\n\r\nsudo nano \/etc\/apache2\/sites-available\/test1.conf\r\n<\/code><\/pre>\n
<VirtualHost *:80>\r\n ServerAdmin webmaster@localhost\r\n DocumentRoot \/var\/www\/html\r\n<\/VirtualHost>\r\n<\/code><\/pre>\n
ServerAdmin<\/code>\u00a0directive to the email that the site administrator can receive emails through. Then, you need to add three directives:<\/p>\n
\n
<VirtualHost *:80>\r\n ServerAdmin admin@test1.com\r\n ServerName test1.com\r\n ServerAlias www.test1.com\r\n DocumentRoot \/var\/www\/test1\r\n<\/VirtualHost>\r\n<\/code><\/pre>\n
sudo cp \/etc\/apache2\/sites-available\/test1.conf \/etc\/apache2\/sites-available\/test2.conf\r\n\r\nsudo nano \/etc\/apache2\/sites-available\/test2.conf\r\n<\/code><\/pre>\n
<VirtualHost *:80>\r\n ServerAdmin admin@test2.com\r\n ServerName test2.com\r\n ServerAlias www.test2.com\r\n DocumentRoot \/var\/www\/test2\r\n<\/VirtualHost>\r\n<\/code><\/pre>\n
Enable the virtual host files<\/h3>\n
a2ensite<\/code>\u00a0tool can be used to enable each of our sites like this:<\/p>\n
sudo a2ensite test1.conf\r\nsudo a2ensite test2.conf\r\n<\/code><\/pre>\n
sudo service apache2 restart\r\n<\/code><\/pre>\n
*Restarting web server apache2\r\nAH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set >the 'ServerName' directive globally to suppress this message\r\n<\/code><\/pre>\n
Final steps<\/h3>\n
\n