Forbidden error in apache virtual host setup - apache

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!

Related

Local website not working

I'm having a lot of trouble setting up a local website that I need to do some work on.
I have 2 local sites: "first_training" and "resus_skills"
The former, first_training, works. I have it set up that first_training.loc/ takes me to the local site. resus_skills is set up in the exact same way, but when I try to access resus_skills.loc/ all I get is:
Here are the details of my setup, as well as some screenshots of it:
/etc/apache2/sites-available/resus_skills.conf :
<VirtualHost *:80>
ServerName resus_skills.loc
ServerAlias www.resus_skills.loc
DocumentRoot "/var/www/resus_skills"
<Directory "/var/www/resus_skills">
Options Indexes FollowSymLinks MultiViews
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I made sure to enable it with sudo a2ensite resus_skills.conf and have confirmed that it's symlink is present in ``/etc/apache2/sites-enabled`
I've made sure my apache server is running:
and I've run apachectl -S to get this result:
I am able to reach first_training.loc/ with no issues, but cannot reach resus_skills.loc/.
I'm unsure how to troubleshoot this - the apache error.log isn't showing me anything.
Before anyone points out what an idiot I've been - I never updated the /etc/hosts file, which was the only missing step.

vhosts dont appear to be working on OS X Mavericks Apache installation

I am trying to set up the Apache server which comes with OS X Mavericks with vhosts so that a domain name resolves to my user level document webroot. I have followed this tutorial which guided me through setting up the apache server with php:
http://coolestguidesontheplanet.com/get-apache-mysql-php-phpmyadmin-working-osx-10-9-mavericks/
as well as this one which guided me through setting up the vhosts:
http://coolestguidesontheplanet.com/set-virtual-hosts-apache-mac-osx-10-9-mavericks-osx-10-8-mountain-lion/
Following these tutorials, if I type localhost in my browser it correctly resolves to the system level root (/Library/WebServer/Documents/ folder). If I use localhost/~myusername it correctly resolves to my user level root (/users/myusername/Sites/).
However, whenever I navigate to my domain, I get redirected to the system level root rather than my user level root.
My vhosts file reads as follows:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
</VirtualHost>
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot "/Users/myusername/Sites/mydomain"
<Directory "/Users/myusername/Sites/mydomain">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Any ideas?
Have you enabled Virtualhosts?
NameVirtualHost *:80
And included your vhosts directory
Include <path>/vhosts/*
On a Macbook, you may need to include /private/ at the beginning of any absolute path, so that Apache can read it correctly off the file system.
For others who have the same problem...
It was frustratingly simple - I had missed the "" around the localhost directory.
How annoying!
Try starting apache manually with the -S option to see what the problem might be:
/usr/sbin/httpd -S

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

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.

“Warning: DocumentRoot [/var/www/vhosts] does not exist” although I've created /var/www/vhosts?

I've installed apache and config my virtual host on my CentOS 6.4.
But when i restart apache ( using this command : sudo service httpd restart ) it's warning me that "Warning: DocumentRoot [/var/www/vhosts] does not exist". I've check the directory /var/www/vhosts, it already created and permission is 0777. What wrong i did? any help please...
-> this is my virtual hosts configuration.
DocumentRoot /var/www/vhosts
ServerName trien.cba
ServerAlias trien.cba
ErrorLog /var/log/httpd/trien.cba.error.log
CustomLog /var/log/httpd/trien.cba.access.log common
AllowOverride All
Order allow,deny
Allow from all
Options -Indexes
....
-> and this is the warning:
[root#test-cba ~]#sudo service httpd restart
Stopping httpd: [ OK ]
Starting httpd: Warning: DocumentRoot [/var/www/vhosts] does not exist
Warning: DocumentRoot [/var/www/vhosts] does not exist
I think you are probably running with SELinux enabled. This requires additional steps to make resources accessible (which is good for security).
These questions have guidelines on how to enable your DocumentRoot:
https://serverfault.com/questions/293866/apache-says-documentroot-doesnt-exist-when-it-does
https://serverfault.com/questions/323511/selinux-on-rhel6-httpd-config-documentroot-path-does-exist-does-not-exist
If you don't want to work with SELinux, you can disable it by setting SELINUX=disabled in /etc/selinux/config. The following links might help if you want to learn more.
http://wiki.centos.org/HowTos/SELinux
http://fedoraproject.org/wiki/SELinux
Try moving your vhosts folder inside the html folder and change the SELinux security context by running
chcon -R --reference=/var/www/html /var/www/html/vhosts

Virtual host showing apache test page and everything else in doc root is forbidden

I am using a new CentOS 6.3 minimal install with fresh httpd installed
When I go to my virtual host it is showing me the apache test page, and then if I go to mydomain.co.uk/index.html (That I have just set up to test with) it says forbidden. All the usual answers to this don't seem to be working and I have honestly looked through tons of forums and other people questions/answers and nothing seems to be working for me.
I have created a group called 'www' that I have added the user 'apache' to.. This is my root directory in httpd.conf file, I have left it pretty open just for testing:
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from All
</Directory>
This is my vhosts file:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html/
</VirtualHost>
<VirtualHost *:80>
ServerName domain.co.uk
ServerAlias www.domain.co.uk
DocumentRoot /home/domain/public_html
<Directory "/home/domain/public_html">
Options Indexes FollowSymLinks ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
From /home/ onwards I have set the group to www
When ls -lA on home folder I get
drwxrwsr-x. 5 root www 4096 Feb 5 20:57 home
The error I am getting in my logs file is a permission one:
[Wed Feb 06 10:24:42 2013] [error] [client 62.254.7.226] (13)Permission denied: access to /index.html denied (filesystem path '/home/domain/public_html/index.html') because search permissions are missing on a component of the path
As is everything else in that folder. I really don't know what to try next. I have come to the point of needing to ask for my specific setup as following other tutorials or answers has not worked for me. Any help is greatly appreciated!
Error 13 means that the user/group specified in your apache configuration (httpd.conf) didn't have permission to access the files. The files, and all the directories above them, need to have permission that allow for that user and group.
One of the trickier bits can be extended permissions. If you are running selinux, the server user could be denied because of the extended permissions on the file. To check for this, run (from the command line):
setenforce 0
If the problem goes away (i.e. the page is visible) then your extended permissions are blocking access.
See http://wiki.apache.org/httpd/13PermissionDenied for details.
Selinux is not expecting the http server to access files under /home/domain since it is not a standard path.
You can change it with following command:
chcon -R --type=httpd_sys_rw_content_t /home/domain/public_html/