LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   RedHat Apache VirtualHost issues (https://www.linuxquestions.org/questions/linux-server-73/redhat-apache-virtualhost-issues-4175465059/)

baronobeefdip 06-06-2013 09:39 PM

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)

j-ray 06-07-2013 01:38 AM

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.

baronobeefdip 06-08-2013 04:18 PM

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.

baronobeefdip 06-08-2013 04:34 PM

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?

j-ray 06-09-2013 03:03 AM

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>

John VV 06-09-2013 01:23 PM

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/

baronobeefdip 06-09-2013 02:20 PM

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>


John VV 06-09-2013 03:59 PM

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

TommyC7 06-10-2013 07:06 AM

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).

baronobeefdip 06-11-2013 03:14 PM

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.

baronobeefdip 06-11-2013 03:25 PM

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.

John VV 06-11-2013 03:31 PM

is the folder " /var/drupal" owned by "apache" like /var/www is

frieza 06-11-2013 03:47 PM

Quote:

Originally Posted by baronobeefdip (Post 4969826)
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

TommyC7 06-11-2013 05:58 PM

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.

John VV 06-11-2013 06:04 PM

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


All times are GMT -5. The time now is 07:29 PM.