Tuesday, October 31, 2017

virtualhost - Configuring virtual host on apache



I have a development machine with lamp setup. Now to add virtual hosts this is what I do currently:




  1. add a virtual host file ... in the /etc/apache2/sites-available

  2. add the virtual host using sudo a2ensite


  3. sudo service apache2 restart



This works fine and I get the desired site up and running on my localhost.



Now the problem is that every time I have to make some change to the configuration file for a site, I have to sudo to edit the configuration file.



What I was wondering is if it is possible to specify some directory in my home folder where apache can look for configuration files for the sites instead of the default sites-enabled directory.


Answer



You can create a directory wherever you want and make the permissions to fit like you want.




In Apache conf (/etc/apache2/apache2.conf) you can include the config files in that directory



Include /path/to/dir/*.conf



Apache will have to be restarted when a configuration change has occured even if you choose this solution.



Also note, that the files in there will be included when apache is restarted - there is no need for a2ensite, and nor can you disable the config files with a2dissite. The way to disable a config file included this way would be to remove or change the extension to something else than .conf.



Remember to take the possible risks into account. You will need to give sudo access, but you can give sudo access to "/etc/init.d/apache2 reload" - the reload parameter will do a configtest before restarting the httpd. If the configtest fails, it will not restart Apache.




I am assuming you run Debian or Ubunbu.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...