Thursday, April 23

Custom Virtual Host in Apache2 in Ubuntu

cd ~
mkdir public_html
Now for each domain create a folder with following template
mkdir -p public_html/{public,private,log,cgi-bin,backup}

NameVirtualHost *:80
Listen 80
Make sure this setting is set either in ports.conf or apache2.conf or httpd.conf or in sites-available/default
Now create the vhost file for in /etc/apache2/sites-available/

with the following settings

<VirtualHost *:80>

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html
  DocumentRoot /home/username/public_html/

  # Custom log file locations
  LogLevel warn
  ErrorLog  /home/username/public_html/
  CustomLog /home/username/public_html/ combined

Now to enable the site in sites-enabled
sudo a2ensite
and then restart the apache2 server
sudo service apache2 restart
Modify the host file '/etc/hosts'    localhost
 Now set the owner permissions

~/public_html/$ sudo chown -R username:www-data cgi-bin log public
~/public_html/$ sudo find ./public -type d -exec chmod 775 {} \;
~/public_html/$ sudo find ./public -type f -exec chmod 774 {} \;

likewise for log and cgi-bin


1. Apache Virtual Hosts
2. Permissions for /var/www/html 
3. Chmod only to folders and its subfolders 

No comments:

Post a Comment