Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which parts of the apache sites-available file are necessary?

I noticed that the default sites-available file (/etc/apache2/sites-available/default) contained many "directory" tags with various options.

<Directory />, <Directory /var/www/>, <Directory "/usr/lib/cgi-bin">, and <Directory "/usr/share/doc/">

Do I need any of those, or can I safely remove them?

like image 560
zargot Avatar asked Jun 15 '11 19:06

zargot


People also ask

What are sites available Apache?

The /etc/apache2/sites-available directory holds configuration files for Apache Virtual Hosts. Virtual Hosts allow Apache to be configured for multiple sites that have separate configurations.

What is the difference between sites available and sites enabled in apache2?

The difference is that virtual sites listed in the sites-enabled directory are served by Apache. In the sites-available directory there are the virtual sites that exist on your server, but people can't access them because they are not enabled yet.

Where is sites available in Ubuntu?

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.


2 Answers

Don't start adjusting the default site, it will just become a mess and you won't be able to figure out what directive does what.
I would recommend you write your own virtual host configuration, this way you actually know what your site does. Here is a little bare bones configuration to get you started.

<VirtualHost *:80>
    ServerName www.mywebsite.com
    DocumentRoot /home/www/public_html/
    <Directory /home/www/public_html/>
        Options None
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

Just put it in sites-available and then run a2ensite mywebsite (mywebsite being the filename of the vhost configuration), then reload the server configuration with /etc/init.d/apache2 reload.
An explanation for all the directives I used can be found in the apache documentation (I am assuming you run version 2.2).

Oh, and of course you need to disable the default site (a2dissite default) if the ServerNames are conflicting.

like image 72
andsens Avatar answered Oct 07 '22 18:10

andsens


I couldn't have said that better. I have been struggling with this too and this is right on. You can also use service apache2 restart and service apache2 reload instead of /etc/init.d/apache2 reload. It does the same thing and may be easier to remember although I think some setups need the above. Apache is a tricky setup, no doubt. I just started using Ubuntu 13.04 and they have a really great manual that will help you on the entire setup, different options, etc but again, the above is spot on. Good luck and just keep at it. It will get easier and start to make sense. The manual is here: https://help.ubuntu.com/13.04/serverguide/serverguide.pdf

Update: this is another one I use.

<VirtualHost xx.xxx.xxx.xx:80>
     ServerAdmin [email protected]
     ServerName domain.com
     ServerAlias www.domain.com
     DocumentRoot /var/www/domain.com/html/drupal
     ErrorLog /var/www/domain.com/logs/error.log
     CustomLog /var/www/domain.com/logs/access.log combined
</VirtualHost>
like image 22
Chris McAndrew Avatar answered Oct 07 '22 19:10

Chris McAndrew