Virtual Host For ubuntu

 

Create the Virtual Host File

1.  sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf

 In the above step at the place of example.com you can put your project name  like ex- projectname.local or project.com


2. Open the new file in your editor (we’re using nano below) with root privileges

sudo nano /etc/apache2/sites-available/example.com.conf

In the above step at the place of example.com put your project name

3. We will customize this file for our own domain.

/etc/apache2/sites-available/projectname.conf
<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
 

4. Enable the New Virtual Host Files

sudo a2ensite example.com.conf(add your file name )
 
 

Next, disable the default site defined in 000-default.conf:

  • sudo a2dissite 000-default.conf 
sudo systemctl restart apache2

 

 

 

 


 

 

Comments