Here is the very simple method how to host multi websites on ubuntu

 

  1. Open SSH or FTP using root login
  2. Type: cd /var/www/
  3. Add your first domain Use This Command: Sudo mkdir -p /var/www/example1.com/public_html
  4. to add more websites you can add your other domain in the same way. Command mkdir -p /var/www/example2.com/public_html
  5. Give Full Permission to these Website directory Command: sudo chown -R www-data: /var/www/example1.com
  6. do same with other domains Command: sudo chown -R www-data: /var/www/dexample2.com

 

Creating Virtual Hosts On Ubuntu systems, Apache Virtual Hosts configuration files are located in 

/etc/apache2/sites-available directory.

They can be enabled by creating symbolic links to the 

/etc/apache2/sites-enabled directory,

which Apache read during the startup.

Open your text editor of choice and create the following basic Virtual Host configuration file:

/etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
    ServerName domain1.com
    ServerAlias www.domain1.com
    ServerAdmin [email protected]
    DocumentRoot /var/www/domain1.com/public_html

    <Directory /var/www/domain1.com/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/domain1.com-error.log
    CustomLog ${APACHE_LOG_DIR}/domain1.com-access.log combined
</VirtualHost>

  • ServerName: The domain that should match for this virtual host configuration. This should be your domain name.
  • ServerAlias: All other domains or subdomains that should match for this virtual host such as the www subdomain.
  • DocumentRoot: The directory from which Apache will serve the domain files.

 

To enable the new virtual host file, use the a2ensite helper script which creates a symbolic link from the virtual host file to the sites-enabled directory:

sudo a2ensite domain1.com


The other option is to manually create a symlink as shown below:
sudo ln -s /etc/apache2/sites-available/domain1.com.conf /etc/apache2/sites-enabled/

Once done, test the configuration for any syntax errors with:

sudo apachectl configtest

If there are no errors, you will see the following output:

Syntax OK

Restart the Apache service for the changes to take effect:

sudo systemctl restart apache2

Finally, to verify that everything is working as expected, open http://example1.com in your browser. 

Was this answer helpful? 28 Users Found This Useful (164 Votes)