Setup own php5/fcgi @DH?

software development

#1

[code]hi,

i’ve built my own php5 cgi/fcgi instannce.

cd /mnt/local/home/USERNAME/public_html/cgi-bin
./php-cgi -v
PHP 5.2.7-dev (cgi-fcgi) (built: Jun 11 2008 17:28:49)
Copyright © 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright © 1998-2008 Zend Technologies

i’m trying to get it to run under FCGI @ DH …

reading here,

http://wiki.dreamhost.com/index.php/PHP_FastCGI
http://wiki.dreamhost.com/FCGI#My_FastCGI_Isn.27t_working

i’ve,

cat > $HOME/public_html/cgi-bin/php5-wrapper.fcgi << EOF
#-------------------------#
#!/bin/bash
export PHP_FCGI_CHILDREN=3
exec /cgi-bin/php-cgi
EOF
#-------------------------#

and,

chmod 0750 $HOME/public_html/cgi-bin/php5-wrapper.fcgi

also, in “~/public_html/.htacess”,


Options +ExecCGI
AddHandler fastcgi-script fcg fcgi fpl
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php5-wrapper.fcgi

for testing,

cat ~/public_html/admin/info.php

<?php phpinfo (); ?>

then, browse to:

http://MYDOMAIN.com/info.php

@ BROWSER, i get:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to
complete your request.

Please contact the server administrator, webmaster@edge.USERNAME.net and inform
them of the time the error occurred, and anything you might have done that may
have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an
ErrorDocument to handle the request.

and @ APACHE ERROR LOG:

[Thu Jun 12 11:12:20 2008] [error] [client #.#.#.#] FastCGI: comm with (dynamic)
server “/mnt/local/home/USERNAME/public_html/cgi-bin/php5-wrapper.fcgi” aborted:
(first read) idle timeout (60 sec)
[Thu Jun 12 11:12:20 2008] [error] [client #.#.#.#] FastCGI: incomplete headers
(0 bytes) received from server
"/mnt/local/home/USERNAME/public_html/cgi-bin/php5-wrapper.fcgi"
[Thu Jun 12 11:12:20 2008] [error] [client #.#.#.#] File does not exist:
/mnt/local/home/USERNAME/public_html/internal_error.html

i’m ‘close’, but clearly something’s not right …

any hints?
[/code]


#2

[code]self-built php5 as fcgi now works.

for ref, here’s the current setup:

cp -f $HOME/bin/php-cgi $HOME/public_html/cgi-bin/php5.cgi
strip -sv $HOME/public_html/cgi-bin/php5.cgi
ls -al $HOME/public_html/cgi-bin/php5.cgi
-rwxr-xr-x 1 USER GROUP 2790944 2008-06-12 17:47 /home/USER/public_html/cgi-bin/php5.cgi

the key was to use FULL PATH to php5.cgi,

cat > $HOME/public_html/cgi-bin/dispatch.fcgi << EOF
#!/bin/bash
export PHPRC=/home/USER/etc/php5
export PHP_FCGI_CHILDREN=3
exec /home/USER/public_html/cgi-bin/php5.cgi
EOF

set up indiv php*.ini’s for CLI & CGI/FCGI

ls -al ~/conf/php5/*.ini
-rw-r–r-- 1 USER GROUP 7273 2008-06-12 18:06 php-cgi-fcgi.ini
-rw-r–r-- 1 USER GROUP 7273 2008-06-12 10:32 php-cli.ini

set file perms,

chmod 0644 $HOME/public_html/.htaccess
chmod 0755 $HOME/public_html/cgi-bin/dispatch.fcgi
chmod 0755 $HOME/public_html/cgi-bin/php5.fcgi

and in $HOME/public_html/.htaccess,


RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(.+.php)$ /cgi-bin/dispatch.fcgi/$1 [L]

Options +FollowSymLinks +ExecCGI
AddHandler fastcgi-script .fcgi
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/dispatch.fcgi

[/code]


#3

Dreamhost does not use public_html folders. Therefore if you wish to create such a folder and have it work as you expect then your htaccess file will need a redirect or a mod rewrite.
Otherwise you would have to type in the browsers url address bar:
http://MYDOMAIN.com/public_html/admin/info.php
or move the info.php to your home folder (the folder that matches your domain name) for it to show up at:
http://MYDOMAIN.com/info.php
Hope this help,
Silk

My website


#4

Actually, while that is true by default for newly created accounts, it was not always the case. There are still accounts on DreamHost that have their website document root as “public_html”. :wink:

In fact, since a user can name the base directory for each website, it can actually be anything at all (including public_html). What’s important is that the part of the path that is being described here must match whatever the user has defined as the base directory when they set up the domain, and they can confirm that by looking at their domain setup (click the “Edit” button under the “Web HOSTING” column on the row that contains the domain name in the “Domains -> Manage Domains” screen).

–rlparker
–DreamHost Tech Support


#5

you did find a typo above –

"browse to

http://MYDOMAIN.com/info.php"

should be

"browse to

http://MYDOMAIN.com/admin/info.php"

As rlparker points out, a domain’s “public web folder” can be arbitrarily named/assigned in your DH panel.

Here, I’ve simply chosen “public_html”.

It now works without any issues.


#6

I didn’t know that. Thats interesting though.

Yeah I forgot that you can change the folder name in the control panel. Guess that’s what happen when you don’t create new domain all the time, lol.
Silk

My website


#7

[code]for reference, i did a not quite apples-to-apples comparison of my self-built php5

php-cgi -v
PHP 5.2.7-dev (cgi-fcgi) (built: Jun 11 2008 17:28:49)
Copyright © 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright © 1998-2008 Zend Technologies
with eAccelerator v0.9.6-dev, Copyright © 2004-2007 eAccelerator, by eAccelerator
with Xdebug v2.0.3, Copyright © 2002-2007, by Derick Rethans

running as php/FastCGI versus the ‘standard’ DH-installed php/CGI.

i know i looked for such benchmarks; though someone here might find them of interest.

tests were done on a standard phpinfo() page. my php has a bunch more modules
included in my custom php.ini – hence the “61546 bytes” vs “45823 bytes” diff
in Doc Length.

i ran a simple apache benchmark,

ab -c 10 -n 5000 http://MYDOMAIN.com/info.php

@ ‘my’ php/FCGI

Document Path: /info.php
Document Length: 61546 bytes

Concurrency Level: 10
Time taken for tests: 9.949 seconds
Complete requests: 5000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 309228354 bytes
HTML transferred: 307762768 bytes
Requests per second: 502.56 [#/sec] (mean)
Time per request: 19.90 [ms] (mean)
Time per request: 1.99 [ms] (mean, across all concurrent requests)
Transfer rate: 31081.35 [Kbytes/sec] received

Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 2
Processing: 5 19 45.2 13 684
Waiting: 5 19 45.2 13 684
Total: 5 19 45.2 13 684

@ ‘standard’ DH php/CGI

Document Path: /info.php
Document Length: 45823 bytes

Concurrency Level: 10
Time taken for tests: 165.932 seconds
Complete requests: 5000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 230607949 bytes
HTML transferred: 229237058 bytes
Requests per second: 30.13 [#/sec] (mean)
Time per request: 331.86 [ms] (mean)
Time per request: 33.19 [ms] (mean, across all concurrent requests)
Transfer rate: 1389.77 [Kbytes/sec] received

Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 8.6 0 124
Processing: 65 328 178.0 289 1781
Waiting: 0 320 179.3 284 1777
Total: 65 329 178.3 290 1781

note also that php@DG uses ZendOptimizer, and i’ve installed eAccelerator.

like i said, NOT apples-to-apples, and, ymmv.

[/code]