LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-06-2013, 09:39 PM   #1
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Rep: Reputation: 32
RedHat Apache VirtualHost issues


I am running CentOS and using it to host a website with Apache httpd server. I was about to create other pages with virtualhosting. The default site that is stored in "/var/www/html" is working fine. But I added the vhost.conf file in the "/etc/httpd/conf.d/" directory and added the following lines.
Code:
<VirtualHost *:80>
ServerName wordpress.baronobeefdip.josh
DocumentRoot /var/wordpress/html
</VirtualHost>
I restarted the service and I get the 403 forbidden page and says that the / directory isn't accessible by apache. I have no knowledge of making that my document root directory so what is going on here. I have enabled name based virtual hosting and the address is already in my DNS zone file. I want to know why this is happening. Coincidentally when I try to access the default page I get the same error. When I remove the virtualhost or comment it out in the vhost.conf file everything starts working again. I don't understand why and I have been creating virtualhosts like this for years (but up to now just on debian based distros)
 
Old 06-07-2013, 01:38 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
Copy the <Directory>- tag of the existing configuration (with a specified directory = document root) to your virtual host config and replace the directory path.
By default all directories are not visible for the web user.
 
Old 06-08-2013, 04:18 PM   #3
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
You mean like this?
Code:
<Directory /var/joomla>
<VirtualHost *:80>
DocumentRoot /var/joomla
ServerName joomla.baronobeefdip.josh
</VirtualHost>
</Directory>
This what I have gathered from your post.

I just tried the lines of code that I specified above in my vhost.conf file and apache came back with an error, can you give me an example of what you mean.

Last edited by baronobeefdip; 06-08-2013 at 04:21 PM.
 
Old 06-08-2013, 04:34 PM   #4
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
just tried it like this
Code:
<Directory "/var/drupal/html>
Allowoverride None
</Directory>
<VirtualHost *:80>
ServerName drupal.baronobeefdip.josh
DocumentRoot /var/drupal/html
</VirtualHost>
Then I restarted, the server restarted fine as far as it knew there weren't any syntax errors. Then tried to go to the site. The default host worked fine but the drupal one (There was a DNS record of it already) would give me the forbidden error for the / directory. I am really confused when it comes to redhat. The method that I started this thread with using has always worked in my lab environment. But in those instances I was using Fedora 14. In this case I am usign CentOS 6. I didn't see any significant differences but this is starting to become very frustrating since all the sites for centos say the same thing. simply add virtualhost but obviously that isn't working. What is the problem here?
 
Old 06-09-2013, 03:03 AM   #5
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
I think the directory tag should reside within the virtualHost tag but I don't know whether that's the reason. Maybe drupal needs some options like AllowOverride if it is working with htaccess files...

<VirtualHost *:80>
ServerName drupal.baronobeefdip.josh
DocumentRoot /var/drupal/html
<Directory /var/drupal/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

Last edited by j-ray; 06-09-2013 at 03:04 AM.
 
Old 06-09-2013, 01:23 PM   #6
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
see the current Apache documentation for vhost
http://httpd.apache.org/docs/2.4/vhosts/

or the older Apache 2.2 docs
http://httpd.apache.org/docs/2.2/vhosts/
 
Old 06-09-2013, 02:20 PM   #7
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
Still didn't work I want the default host to still be accessible when you simply type in the IP address but I get the / directory again. Plus it's still forbidden. I have been trying to access both the default and the local hosts and none of them are working. Here's my vhost.conf file again
Code:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName joomla.baronobeefdip.josh
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/localhost.crt
SSLCertificateKeyFile /etc/httpd/ssl/localhost.key
</VirtualHost>
</IfModule>

<VirtualHost *:80>
ServerName drupal.baronobeefdip.josh
DocumentRoot /var/drupal/html
<Directory /var/drupal/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
 
Old 06-09-2013, 03:59 PM   #8
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
this might be a problem
Quote:
<Directory /var/drupal/html>
move the second site to say here
Code:
/var/www/drupal/html
the /var/www folder should have the correct file permissions and SE context

also for DEBUGGING set SE to permissive
READ the errors ( if any ), fix them then set it BACK to Enforcing

Last edited by John VV; 06-09-2013 at 04:00 PM.
 
Old 06-10-2013, 07:06 AM   #9
TommyC7
Member
 
Registered: Mar 2012
Distribution: Slackware, CentOS, OpenBSD, FreeBSD
Posts: 530

Rep: Reputation: Disabled
Sounds like SELinux is preventing access. Notice the security context type for /var/www/html is "httpd_sys_content_t" whereas for /var it's just "var_t".

By creating that "wordpress" directory under /var that directory is also given the security context type "var_t" instead of "httpd_sys_content_t" and therefore httpd is not permitted to access the contents of that directory.

Try:
Code:
chcon -R --reference /var/www/html -t httpd_sys_content_t /var/wordpress
You might want to use semanage to make sure /var/wordpress stays that way when you use restorecon or something.

Edit: There might be some sebooleans you need to set to make it work too (forgot about those).

Last edited by TommyC7; 06-10-2013 at 07:11 AM.
 
Old 06-11-2013, 03:14 PM   #10
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
I am just disabling SELINUX, I just remembers that in the lab environment that I am in all the time we would disable selinux on all the machines that were running redhat. I just needed a memory refresher. I'll get back to you and tell you what happens.
 
Old 06-11-2013, 03:25 PM   #11
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
I just diabled SELINUX like I remember doing in the past. Rebooting the computer and making the vhost file look like this
Code:
<VirtualHost *:80>
ServerName drupal.baronobeefdip.josh
DocumentRoot /var/drupal
</VirtualHost>
The I restarted apache and the browser still shows me the same message. What else is there to do.
 
Old 06-11-2013, 03:31 PM   #12
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
is the folder " /var/drupal" owned by "apache" like /var/www is
 
Old 06-11-2013, 03:47 PM   #13
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
Quote:
Originally Posted by baronobeefdip View Post
I just diabled SELINUX like I remember doing in the past. Rebooting the computer and making the vhost file look like this
Code:
<VirtualHost *:80>
ServerName drupal.baronobeefdip.josh
DocumentRoot /var/drupal
</VirtualHost>
The I restarted apache and the browser still shows me the same message. What else is there to do.
you STILL havn't added the
Code:
<Directory /var/drupal/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
without that section, nothing is going to work since you havn't told apache anything about what to do with the directory
 
Old 06-11-2013, 05:58 PM   #14
TommyC7
Member
 
Registered: Mar 2012
Distribution: Slackware, CentOS, OpenBSD, FreeBSD
Posts: 530

Rep: Reputation: Disabled
Alongside what else has been said, you haven't told us how you turned off SELinux (I recommend keeping it on by the way except for debugging purposes).

If you used:
Code:
setenforce 0
That's not going to survive a reboot.

Also, there's no need to reboot the entire machine if all you're going to do is restart a service or just change the permissions of a directory.

For future reference, use
Code:
sestatus
To see if SELinux is set to enforcing/permissive/disabled.
 
Old 06-11-2013, 06:04 PM   #15
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
set SE to "permissive" for testing
this will tell "SElinuxTroubleShooter" about problems that will stop something from running IF it were in "enforcing" mode

then set back to enforcing after things are fixed
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Apache virtualhost issues Hmail Linux - Server 7 09-19-2012 03:46 AM
Apache VirtualHost's Dreft Linux - Server 1 12-16-2010 02:55 PM
[SOLVED] Apache VirtualHost Help Chris1989 Linux - Server 6 11-08-2009 05:30 PM
Apache virtualhost with 2 ip's djroy Linux - Newbie 2 10-12-2009 01:48 PM
Apache -VirtualHost davidhk Debian 7 08-19-2005 12:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration