Where to put Apache vhost configuration (httpd-vhosts.conf or httpd.conf)? - apache

I just to ask a simple question. I am studying the vhost configuration but I am confused where should I properly put my vhosts configuration?
I have a file that has a name httpd-vhosts.conf and httpd.conf
I try to put my configuration in these 2 files but different web projects. And after I restarted my Wampserver I can access them. Is it fine if I place all my vhost entries in the file httpd-vhosts.conf ? Or should I place it in httpd.conf

There is no right or wrong. Apache has one global config file, which typically is the default or specified in the startup script.
This file then uses one or more secondary config files and directories. Different Linux distributions use different default include directories.
On CentOS I think for example you would put a file (named like your domain but can be anything) in /etc/httpd/conf.d/example-com.conf: http://wiki.centos.org/TipsAndTricks/ApacheVhostDir

Related

Apache URI path recognition / mapping?

I have a website for all intents and purposes is called.
www.foobar.com
Which in my server path is /var/www/
I tried to create a new folder in /var/ called "analytics", with the hope that if I typed www.foobar.com/analytics I could access that folder.
However that does not work because it is actually looking for /var/www/analytics instead of /var/analytics
So how can I have multiple directories mapped to a URI?
For phpmyadmin I can access www.foobar.com/phpmyadmin with the phpadmin folder is in a completely different directory. So it must be possible.
However I tried googling but could not find any answers so I guess I do not have the right description of what this functionality is on Apache webservers.
Any help would be appreciated.
You have to create virtual directories in Apache.
If you are using Apache2, then can you go to the directories
/etc/apache2/sites-available and /etc/apache2/sites-enabled.
You have probably only the default virtual directory enabled.
You can make a copy of a virtual directory in the map /sites-available.
A virtual directory starts with specifying what the root directory is.
Then can you use the commands a2ensite and a2dissite in order to enable or disable the virtual directories respectively.
After a change in enabled/disabled virtual directories do you need to restart/reload the apache server.
If you use .htaccess file, do not forget to set AllowAccess (in the tag Directory) to at least FileInfo or .htaccess will be ignored.
If you want to make those directories different hosts, then can you make aliases in /etc/hosts.
On my home computer have I aliases for the ip addresses 27.0.0.1 and 27.0.1.1.
That gives me the possibility to have two different sites at the same time.

Changing var/www to something else

I've installed Ubuntu on a Oracle VM Virtual box, and installed Apache etc.
How do I change the var/www folder that Apache uses, to something else? Can I simply rename it? I'm, trying to change it to nordy/core, in place of var/www.
Can I create a separate folder called nordy/core and place my html files there? One of the reasons I did not do this it because I noticed that var/ has several other folders that will not be created if I simply create a new folder. So, I'm guessing the site wont work.
I'd like to store my html and php files in a folder nordy/core so Apache can use it from there. Can I simply create a folder nordy/core and point Apache to it in Apache's configuration?
How do I do this?
You need to change the value of the DocumentRoot directive of your apache2.conf file. You may find this file at /etc/apache2/apache2.conf.
DocumentRoot "/nordy/core"
Then restart your apache process.
sudo service apache2 restart

Apache - virtualhosts and global apache config

I have an apache server configured with multiple NameVirtualHosts running on the same IP. This all works fine.
However, because of the "include conf.d/*" directive, apache also picks up config for cacti and phpmyadmin, which add in aliases for /cacti and /phpmyadmin, and those aliases appear to be valid for all virtualhosts. That is to say, I can go to http://firstvirtualhost/cacti and also http://secondvirtualhost/cacti, and I get the same page.
In my case, the default namevirtualhost is publicly visible, and I do not want tools like phpmyadmin or cacti to be visible under that URL
In fact, I don't want any random package to be able to make itself visible across all virtualhosts simply by creating a file for itself in conf.d.
You have to delete the line include conf.d from the global Apache configuration file, and optionally add it to your own private virtual host configuration file.

Difference between httpd.conf, php.ini and .htaccess

I am about to start learning Apache. All resources I am looking into, mention either php.ini, or .htaccess or httpd.conf files for setting configurations and stuff. But none of them are clear on the difference between these 3 files. Can anyone explain the difference and their usage?
httpd.conf (it can actually be named differently on some platforms, but that's the default) is the master configuration file for Apache. You can use Include statements to pull in external configuration files. httpd.conf is read in when Apache starts or if you run a 'reload'.
.htaccss is a per-directory configuration file for Apache. You can enable or disable the use of .htaccess files in your httpd.conf file. Where possible its been recommended to me to turn .htaccess use off, as Apache will check the file every time a request causes it to read the directory.
PHP is, as you probably know, separate from Apache, although often used with it. php.ini is the configuration file for the PHP engine.
Every daemon or application has it's own configuration files. On linux these are often located in the /etc directory. You will have to learn to edit each one according to the program. the /etc/php5/php.ini is different from the /etc/apache2/httpd.conf and so on.
Think of them like different types of files. a Word document is not the same as a JPEG Image or a AVI video.
The PHP.ini controls PHP's settings
The .htaccess controls apache settings for a given folder (and all child folders)
The httpd.conf controls apache's settings.
php.ini is a configuration file where you specify options for things
related specifically to php, for instance CURL
.htaccess is where you specify options for URI routing and folders
options on your server
httpd.conf is a configuration file where you specify options for
things related specifically to apache

My httpd.conf is empty

I recently installed apache2 on ubuntu but I have a problem, my httpd.conf is empty. Can someone give me a clean copy of httpd.conf for apache2 on ubuntu?
Thanks!
Edit: I saw your answers but on wampserver httpd.conf is not empty and as you mentioned it is for user options. SO what should I do?
Edit2 : That's what I got on my apache2.conf, how I add modules, enable gzip and all of that?
[Deleted the contents, as they render the question unreadable and are useless, because that were the default Apache2 configuration under Ubuntu.]
The /etc/apache2/httpd.conf is empty in Ubuntu, because the Apache configuration resides in /etc/apache2/apache2.conf!
“httpd.conf is for user options.” No it isn't, it's there for historic reasons.
Using Apache server, all user options should go into a new *.conf-file inside /etc/apache2/conf.d/. This method should be "update-safe", as httpd.conf or apache2.conf may get overwritten on the next server update.
Inside /etc/apache2/apache2.conf, you will find the following line, which includes those files:
# Include generic snippets of statements
Include conf.d/
As of Apache 2.4+ the user configuration directory is /etc/apache2/conf-available/. Use a2enconf FILENAME_WITHOUT_SUFFIX to enable the new configuration file or manually create a symlink in /etc/apache2/conf-enabled/. Be aware that as of Apache 2.4 the configuration files must have the suffix .conf (e.g. conf-available/my-settings.conf);
It's empty by default. You'll find a bunch of settings in /etc/apache2/apache2.conf.
In there it does this:
# Include all the user configurations:
Include httpd.conf
OK - what you're missing is that its designed to be more industrial and serve many sites, so the config you want is probably:
/etc/apache2/sites-available/default
which on my system is linked to from /etc/apache2/sites-enabled/
if you want to have different sites with different options, copy the file and then change those...
It seems to me, that it is by design that this file is empty.
A similar question has been asked here:
https://stackoverflow.com/questions/2567432/ubuntu-apache-httpd-conf-or-apache2-conf
So, you should have a look for /etc/apache2/apache2.conf