Apache doesn't use DocumentRoot after upgrading to Ubuntu 13.10 (Uses default page that says "It works!") - apache

I have various virtual hosts for my web development work, including
cnm. The
sites-available/cnm
my file says very simply:
<VirtualHost *:80>
ServerName cnm
DocumentRoot /var/www/cnm/public_html
</VirtualHost>
I upgraded to Ubuntu 13.10, and when I point my browser to cnm/, I see the
/var/www/index.html file that seems to be indicated in the default file
sites-available/000-default.conf
which says (among other things):
<VirtualHost *:80>
DocumentRoot /var/www
What do I need to do to get Apache to read my cnm document root when I browse to cnm/ ?
NOTES:
I already tried renaming my sites-available/cnm file to sites-available/cnm.conf and enabling it with a2ensite cnm and service apache2 reload. That is a good thing, but it changes nothing.
I already tried changing <VirtualHost *:80> to <VirtualHost cnm.localhost> or to <VirtualHost cnm>. That did nothing.

Ubuntu 13.10 uses apache 2.4, you should check all your apache configuration. But for this present case you should note that a2ensite and a2dissite commands won't be able to see your files in /etc/apache2/sites-available if it does not end with .conf, so rename it to sites-available/cnm.conf and run a2ensite cnm.
Then your Virtualhost definition is certainly better with *:80, it means this virtualhost is activated for all IP interfaces (*) on port 80. cnm.localhost or cnm are not valid values here, only IP numbers (Ip of your apache server) or * for all, and a port number.
Then check how you configuration is read by apache, running theses commands:
# load apache env
# be careful, there is a dot and a space
. /etc/apache2/envvars
# Check apache Virtualhosts config
apache2 -S
You should get something like:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server something (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost something (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost cnm (/etc/apache2/sites-enabled/cnm.conf:4)
If it is ok, and if you have the right Ip in your hosts file for cnm, and you can test that with a ping, then using http://cnm/ should use the Virtualhost having cnm in the ServerName.
If you have an answer from the default Virtualhost then it means apache is not finding the name used in your Host header in the list of ServerName and ServerAlias available for that IP/port and fallbacks to the default Virtualhost. If you are really stuck (and you did not forgot to restart) you can always remove the default Virtualhost and keep only the one you are working on.

I found the answer to my issue. I needed to delete the files in /etc/apache2/sites-enabled.
Delete files in /etc/apache2/sites-enabled
Rename config files in /etc/apache2/sites-available to have a .conf ending
For each file in sites-available, run sudo a2ensite mysite.
Run sudo service apache2 reload

I couldn't find any step by step tutorial on how to make it work on my side. I gathered bits and pieces here and there, so for those who need all the steps to follow, here there are:
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/local-mydefault.conf
$ sudo gedit /etc/apache2/sites-available/local-mydefault.conf
Paste the following into the local-mydefault.conf file (Change the path '/your/full/path' to where you want to have your files. And change username to your own username):
# ------------------------------------------------------
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /your/full/path
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /your/full/path>
DirectoryIndex index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
User username
Group username
# ------------------------------------------------------
Then type the following commands
$ cd /etc/apache2/sites-available/
$ sudo a2ensite local-mydefault.conf
$ sudo a2dissite 000-default.conf
$ sudo /etc/init.d/apache2 restart

I found the answer to this issue:
When upgrading to Ubuntu 13.10, the DocumentRoot does not seem to make a difference.
This is because Apache 2.4 moved the Directory configuration somewhere else. Your old .conf files still have these lines:
DocumentRoot "/var/www/myVhost"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/myVhost">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Remove (or comment out) the <Directory> directives so you only have:
DocumentRoot "/var/www/myVhost"
Now reload your settings: service apache2 reload and DocumentRoot is back. :)

Rename the file configuration "cnm" with the extension .conf
mv sites-available/cnm sites-available/cnm.conf
a2ensite sites-available/cnm.conf
And ready!
service apache2 reload

I have the same issue
on way is to disable 000-default and reload apache ,but this isn't the solution becuase you must have just one vhost at a same time :(
sudo a2dissite 000-default.conf
sudo service apache2 reload

I ran into a similar issue. My server name and my FQDN were the same to the default was running into the /var/www/html directory. I disabled the default configuration and my site worked like a breeze. Thanks #regilero.
sudo a2dissite 000-default.conf
fixed it for me.

Related

What did i do wrong while creating virtual host on ubuntu?

I have created apache virtual host as in the link:
[set up apache virtual hosts ][1]
https://www.youtube.com/watch?v=Vd2aLTZDLQg
But i am not able access the web page from google . I tried out following link also but it also didnt worked
[how to create virtual host on apache][1]
https://www.youtube.com/watch?v=PaEs4-3Rrok
Please suggest what i do wrong why the virtual host not working
I'm trying to help you by giving a resume of steps you need to do to make your virtual host working. Make your own changes to adapt it with your project (name, location...etc)
I suppose that you have a running website which you can access it using http://127.0.0.1/example.com
I suppose that you want to create a virtual host to access it using http://example.dev
I suppose that the folder "example.com" is under "/var/www/"
I suppose that you are working on Ubuntu (or using a Windows 10 Ubuntu Bash)
Step 1
sudo nano etc/apache2/sites-available/example.com.conf
Copy/paste the following content inside it:
<VirtualHost *:80>
ServerName www.example.dev
ServerAlias example.dev
ServerAdmin changeThisWithYourEmail
DocumentRoot /var/www/example.com/
DirectoryIndex index.php
<Directory "/var/www/dev">
Options Multiviews FollowSymLinks
MultiviewsMatch Any
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example_error.log
CustomLog ${APACHE_LOG_DIR}/example_access.log combined
</VirtualHost>
Step 2
sudo a2ensite example.com.conf
Step 3
sudo nano /etc/hosts
and then add this line at the end of the file:
127.0.1.1 example.dev
Step 4
sudo service apache2 restart
Step 5
Check if http://example.dev is showing the same result as http://example.com

How to route all *.dev to subfolders on vagrant box

I want that every *.dev Host will be routed to my vagrant machine to /var/www/vhosts/*.dev/public, for example my local development environment project1.dev is located in /var/www/vhosts/project1.dev/public
So when I add a new (sub)project into my box, I do not need to change my config.yaml (Vagrant installed via puphpet.com) and reload the machine.
On my computer, I added the following to the hosts file in /private/etc:
192.168.56.101 *.dev
On my VM, I changed my 10-default_vhosts80.conf in /etc/apache2/sites-enabled to:
# ************************************
# Vhost template in module puppetlabs-apache
# Managed by Puppet
# ************************************
<VirtualHost *:80>
ServerName default
## Vhost docroot
DocumentRoot "/var/www/default"
## Directories, there should at least be a declaration for /var/www/default
<Directory "/var/www/default">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
## Load additional static includes
## Logging
ErrorLog "/var/log/apache2/default_vhost_80_error.log"
ServerSignature Off
CustomLog "/var/log/apache2/default_vhost_80_access.log" combined
## Custom fragment
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/default/$1
</VirtualHost>
<VirtualHost *.dev:80>
ServerName dev
VirtualDocumentRoot /var/www/vhosts/%0
</VirtualHost>
Unfortunately, this doesn't work. Any ideas? I am a beginner in this subject.
I use a proxy auto configuration file. This works on Windows, MacOS and Linux. Easy, flexible and no additional software required. The following example routes all *.dev traffic to your vagrant box:
function FindProxyForURL(url, host) {
if (dnsDomainIs(host, ".dev")) {
return "PROXY 127.0.0.1:8080";
}
return 'DIRECT';
}
When needed, replace 127.0.0.1:8080 with the IP and webserver port of your vagrant box. Store this file somewhere. You can store it locally or let the webserver on your Vagrant-box host the file.
Windows: See here how to use the PAC file on Windows.
MacOS: See here how to use the PAC file on MacOS. You can link to the file using file:///Users/username/path/to/proxy.pac.
Linux: For linux it depends, but I'm sure linux users will be able to Google for their specific situation.
Unfortunately hosts files do not support using wildcards. You have to manually define each and every host to redirect.
Also, your hosts file is at /etc/hosts
In the end, I use dnsmasq to route all .localdev Domains to 127.0.0.1. Note that I am using .localdev instead of just .dev or .local as this seems to cause problem (OS X 10.10) because .dev is a proposed gTLD and .local is used by Apple's Bonjour.
Then I configured Apache by creating and enabling this site:
<VirtualHost *:80>
ServerAlias localhost *.localdev #wildcard catch all
VirtualDocumentRoot /hosts/%1/public
UseCanonicalName Off
<Directory "hosts">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
(from: http://brunodbo.ca/blog/2013/04/26/setting-up-wildcard-apache-virtual-host-wildcard-dns)

How to setup virtual host for Apache 2.4/ubuntu 13.10 and above?

I ma having difficulty setting virtual host after updating ubuntu to 13.10!!
this is what i tried:
Fire up the terminal and type:
sudo a2enmod vhost_alias
If you did not get any error messages and your return looks like below, you are on the right track.
Enabling module vhost_alias.
Run '/etc/init.d/apache2 restart' to activate new configuration!
Next thing to do is to go to sites-available directory by typing
cd /etc/apache2/sites-available/
OK, now we are in apaches directory where all the definition files for virtual hosts are. We want to copy the default template one, cryptically named default
sudo cp default our-test-site
This will create a copy of the default template named our-test-site (you of course should substitute this with anything you wish). Let’s edit it, type
sudo gedit our-test-site
This will open up the file in the editor, below are the contents of default vhost file (as usual YMMV if you did some customization)
ServerAdmin webmaster#localhost
DocumentRoot /var/www
Options FollowSymLinks
AllowOverride None
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
We need to add one line and edit two lines.
Add ServerName our-test-site.local just above the DocumentRoot directive (in front of line 4).
Edit DocumentRoot /var/www path on line 4 and set it to /path-to-the-test-site-WITHOUT-trailing-slash. It should look something like this
DocumentRoot /path-to-the-test-site-WITHOUT-trailing-slash
In case you did not notice my subtle hints, there should NOT be a trailing slash at the end of the path.
Edit path on line 9 and set it to /path-to-the-test-site-WITH-trailing-slash/. It should look something like this
DocumentRoot /path-to-the-test-site-WITHOUT-trailing-slash
In case you did not notice my subtle hints, there SHOULD be a trailing slash at the end of the path.
And there you have it, almost done, the virtual host file is setup. Enable it by typing
sudo a2ensite our-test-site
The response should look like this
Enabling site our-test-site.
Run '/etc/init.d/apache2 reload' to activate new configuration!
At this point the virtual host setup is done, all that is left is to tell the server that our-test-site.local should be resloved to 127.0.0.1. We do that by typing
sudo gedit /etc/hosts
and adding 127.0.0.1 our-test-site.local after the localhost (line 1).
The entire hosts file should look like
127.0.0.1 localhost
127.0.0.1 our-test-site.local
127.0.1.1 ubuntu-vm
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
Save it, close the editor and finally type
sudo /etc/init.d/apache2 restart
or
sudo apache2ctl restart
So there you go, your virtual host is setup, open the browser and type http://our-test-site.local and enjoy.
Update: In case you encounter problems accessing the content of the localhost, you should add the ServerName localhost into your default virtual host (as described above for the new virtual host). Then disable and enable site, and restart the apache
sudo a2dissite default
sudo a2ensite default
sudo /etc/init.d/apache2 restart
Update 2: In your new virtual host file you should change your
AllowOverride None
to
AllowOverride All
for your first two directory nodes (the / one and the one with the path to your site). That will allow all the .htaccess files to work properly and allow redirection.
And of course do not forget to
sudo a2dissite our-test-site
sudo a2ensite our-test-site
sudo /etc/init.d/apache2 restart
The problem was that with Apache 2.4/ubuntu 13.10 and above the sites-available files are like name.conf instead of
sudo cp default our-test-siteof
I did it like so
sudo cp default.conf our-test-site.conf
And so on.

How do you set the default website to serve when your IP address is entered as URL?

I have a server with multiple websites hosted and distinguishable using name-based virtual hosting of apache.
How do I set it so that a specific website is hosted when the ip of my server is entered in the address bar?
What you want to use is the _default_ VirtualHost.
<VirtualHost _default_:80>
DocumentRoot /www/default80
# ...
</VirtualHost>
It's described here. Basically if nothing else match the request the _default_ host will be used.
EDIT
This could also be written as:
<VirtualHost *>
DocumentRoot /www/default
# ...
</VirtualHost>
Is is important that this is the first VirtualHost in the configuration since Apache will start matching them from top to bottom, selecting the one that fit the best based on ServerName and ServerAlias.
This post might also be of interest:
Apache default VirtualHost
just find the Include sites-enabled/ line in your apache2.conf file and add the path to the conf file you want to be site default above it. from:
Include sites-enabled/
to
Include sites-enabled/mydefault.conf
Include sites-enabled/
When you first install apache2, there is a site configuration file named 000-default.conf. This is going to be the default because it is very likely to appear first in the list of files under /etc/apache2/sites-enabled.
To have your own file as the default, you can either replace the file under /etc/apache2/sites-available/000-default.conf with your own, or replace the link like so:
sudo rm /etc/apache2/sites-enabled/000-default.conf
sudo ln -s ../sites-available/my-site-setup.conf /etc/apache2/sites-enabled/000-default.conf
Then restart apache2 (or just reload).
The _default_ as mentioned by the other answer is for defining a virtual host which can be found with the default IP address. It's not the default virtual host.
<VirtualHost _default_:80>
...
is equivalent to
<VirtualHost *:80>
...
The * is a globing pattern which matches any IP addresses.
Note:
Replacing the 000-default.conf file is okay, but in most cases the installation package is going to view that as a modified file and manage it in some weird way which is why I think it's cleaner to only change the soft link.
Keep it clean, don't delete or edit anything in /etc/apache2/sites-available/.
Create all new site configurations in /etc/apache2/sites-available/. Copy whatever site configuration you want enabled to /etc/apache2/sites-enabled/. Only make sure /etc/apache2/sites-enabled/ has only one configuration file.
Sample format for new apache site configurations in Ubuntu 20.04 LTS is
<VirtualHost *:80>
ServerName http://localhost
ServerAdmin admin#mysite.com
DocumentRoot /var/www/html/mysiteroot/public
<Directory /var/www/html/mysiteroot>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Notice that 000-default.conf is by default in both directories mentioned above and should only be replaced by your new configuration in /etc/apache2/sites-enabled/ so that it can be restored anytime you need it.
Restart Apache2 service after you make any configuration changes.

Forbidden error in apache virtual host setup

Hello I have been looking through internet articles forums to solve my issue and so far it has been to no avail. I am trying to set up an Apache virtual host for my FuelPHP development on localhost but I keep getting slammed with the error 403 message. Here is my current setup.
#/etc/apache2/sites-enabled/000-default
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#example.com
DocumentRoot "/home/supercomputer/Desktop/PHP/fuelProject/public"
ServerName localhost.home
<Directory "/home/supercomputer/Desktop/PHP/fuelProject/public" >
Options Indexes FollowSymLinks MultiViews Includes ExecCGI
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
I have pointed my Docroot to the public folder inside my fuelProject. Also to make sure Apache had access to the server files, I set the permissions for all of the files recursively to read, write, and execute just to be a 100% safe. Any clues as to what else could be going wrong?
PS: I am running ubuntu raring (13.04)
PSS: And I am trying to visit localhost.home and localhost.home/index.php. I also get the following warnings upon restarting the server
* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri May 03 15:46:58 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri May 03 15:46:59 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
Here is the correct way of adding Vhost for fuelphp application or any other php application
<VirtualHost *:80>
ServerName localhost.home
DocumentRoot /home/supercomputer/Desktop/PHP/fuelProject/public
ServerAdmin webmaster#localhost
<Directory /home/supercomputer/Desktop/PHP/fuelProject/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And also the below line is not required I dont know why you have added
NameVirtualHost *:80
After doing all above add a host entry to your machine to do that
sudo vi /etc/hosts
add an entry of the virtual host
127.0.0.1 localhost.home
After doing all these things
restart Apache by running
sudo /etc/init.d/apache2 restart
And just load http://localhost.home in your browser you should be able to see your site up and running .
If you still get forbidden error .you need to give permissions to your whole application folder
follow run these commands to do so
sudo chown -R www-data:www-data /home/supercomputer/Desktop/PHP
sudo chmod -R 775 /home/supercomputer/Desktop/PHP
At last add yourself to www-data group
sudo adduser yourUserName www-data
The configuration I posted were working. The problem was with permissions. I had set only my containing fuel project folder to permission 777 but for some reason apache wanted access to almost all the folders containing it. Weird I know but setting all the permissions to 777, it worked. Reading the darn apache log sure helped. If you are having a similar problem, I suggest find the apache log and ACTUALLY READ IT
Testeed on Ubuntu 14.04: I did everything above but I didn't work. I missed to allow access to the directory in my apache2.conf. This is needed if you don't use a standard directory like /var/www or /usr/share/.
<Directory /usr/local/vufind>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
This was mentioned on the4 default PHP site. It's worth reading it!