Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

my system is:

wx3# uname -a
FreeBSD wx3 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:46:30 UTC 2012     root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
wx3# 

packages installed:

wx3# pkg_info | grep -Ei '^apache|^ap22-mod_fastcgi|^php5-5.3|^spawn-fcgi'
ap22-mod_fastcgi-2.4.6_2 A fast-cgi module for Apache
apache-2.2.21       Version 2.2.x of Apache web server with prefork MPM.
php5-5.3.8          PHP Scripting Language
spawn-fcgi-1.6.3    spawn-fcgi is used to spawn fastcgi applications
wx3# 

apache's configuration files:

wx3# cat mod_fastcgi.conf
LoadModule fastcgi_module     libexec/apache22/mod_fastcgi.so

<IfModule mod_fastcgi.c>
    AddHandler php5-fastcgi .php
    FastCgiExternalServer /usr/local/www/apache22/data/php -socket /var/run/spawn_fcgi.sock
</IfModule>
wx3# 

this is me trying to hit phpinfo.php file from a remote

mbp:~ alexus$ curl -I X.X.X.X/php/phpinfo.php
HTTP/1.1 200 OK
Date: Tue, 13 Mar 2012 01:28:14 GMT
Server: Apache/2.2.21 (FreeBSD) mod_ssl/2.2.21 OpenSSL/0.9.8q DAV/2 mod_python/3.3.1 Python/2.7.2 mod_fastcgi/2.4.6
X-Powered-By: PHP/5.3.8
Content-Type: text/html

mbp:~ alexus$ 

now, I'm trying to create a virtualhost, so I copying already working fastcgi to get php to work:

wx3# cat X.conf 
<VirtualHost *:*>
    ServerName X.X.X
    DocumentRoot /home/X/X/htdocs/
    <IfModule mod_fastcgi.c>
        AddHandler php5-fastcgi .php
        FastCgiExternalServer /home/X/X/htdocs/php -socket /var/run/spawn_fcgi.sock
    </IfModule>
    LogLevel debug
    CustomLog /home/X/X/logs/access_log combined
    ErrorLog /home/X/X/logs/error_log
</VirtualHost>
wx3# 

hitting same phpscript

mbp:~ alexus$ curl -I X.X.X/php/phpinfo.php
HTTP/1.1 200 OK
Date: Tue, 13 Mar 2012 01:31:33 GMT
Server: Apache/2.2.21 (FreeBSD) mod_ssl/2.2.21 OpenSSL/0.9.8q DAV/2 mod_python/3.3.1 Python/2.7.2 mod_fastcgi/2.4.6
Last-Modified: Mon, 12 Mar 2012 21:08:11 GMT
ETag: "97c8ef-14-4bb1223c8a4c0"
Accept-Ranges: bytes
Content-Length: 20
Content-Type: application/x-httpd-php

mbp:~ alexus$ 

What am I missing? Why would it work for default host and won't work it for virtualhost even though I pretty much copy and paste a working configuration from default host and just change a directory?

share|improve this question
add comment

1 Answer

It seems you have bad definition of <VirtualHost *:*>, because your server have loaded mod_fastcgi (as you can see in the Server: header in answer), but it don't know, that .php have to be done via php5-fastcgi handler.

Have you defined directive NameVirtualHost? Does your computer know, that it's IP have name X.X.X (use /etc/hosts file, if there is not a DNS record)?

share|improve this answer
    
"VirtualHost" defined just fine, they're both works as expected, the only thing that isn't working is a PHP scripts –  alexus Mar 13 '12 at 14:36
    
@alexus And what if you change config to remove IfModule directive and only remain AddHandler and FastCgiExternalServer? –  Jan Marek Mar 13 '12 at 15:13
    
if I remove "IfModule" directive it will perform exactly the same, this directive there just in case if mod_fastcgi isn't present yet apache will start anyway (website will work just in degraded state) and other websites will work fine as well. –  alexus Mar 13 '12 at 20:33
    
actually the problem is in FastCgiExternalServer (fastcgi.com/mod_fastcgi/docs/…) and not in apache's configuration, basically that directive works across ALL hosts, how would use share that across multiple virtualhosts (especially knowing that it requires path to files w/ php script)? –  alexus Mar 13 '12 at 20:36
    
@alexus I'm sorry, but is /home/X/X/htdocs/php executable and has apache rights to exec it? –  Jan Marek Mar 14 '12 at 5:34
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.