0
  • Ubuntu 12.04
  • Apache 2.2.22
  • PHP 5.3.10 [running as libapache2-mod-fcgid]

[trying to match a development server vs. my web host]

I managed to get fcgi to work using a wrapper and have registered the necessary handlers to have .html files parsed as php. Now I'm trying to figure out why my scripts don't run with the php.ini files in each directory, which is reportedly the default behaviour.

from phpinfo(), running from http://127.0.0.1/NEW/poop.html

Server API                               CGI/FastCGI
Virtual Directory Support                disabled
Configuration File (php.ini) Path        /etc/php5/cgi
Loaded Configuration File                /var/www/johnny/public_html/php.ini
Scan this dir for additional .ini files  /etc/php5/cgi/conf.d

it appears to be reading config from [/etc/php5/cgi/php.ini] just fine, and also from the web root, which I had to define in the wrapper script in order for it to read the php.ini there

[/var/www/php-fcgi-scripts/johnny/php-fcgi-starter]

#!/bin/sh
PHPRC=/etc/php5/cgi/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
exec /usr/lib/cgi-bin/php -c /var/www/johnny/public_html

I pulled together from two web tutorials to get this FastCGI + VirtualHost working, and have been learning piecemeal how it all works. Here's my VirtualHost setup:

[/etc/apache2/sites-available/johnny.conf]

<VirtualHost _default_:80>
  ServerName johnny.10.128.0.2.xip.io
  ServerAlias my.dev.server.public.IP
  DocumentRoot /var/www/johnny/public_html/

  <IfModule mod_fcgid.c>
    SuexecUserGroup johnny johnny
    <Directory /var/www/johnny/public_html/>
      Options +ExecCGI -Indexes +FollowSymLinks +MultiViews
      AllowOverride All
      AddHandler fcgid-script .php .htm .html
      FCGIWrapper /var/www/php-fcgi-scripts/johnny/php-fcgi-starter .php
      FCGIWrapper /var/www/php-fcgi-scripts/johnny/php-fcgi-starter .htm
      FCGIWrapper /var/www/php-fcgi-scripts/johnny/php-fcgi-starter .html
      Order allow,deny
      Allow from all
    </Directory>
  </IfModule>

  ErrorLog /var/log/apache2/johnny-error.log
  CustomLog /var/log/apache2/johnny-access.log combined
  LogLevel warn
  ServerSignature Off
</VirtualHost>

but it will not load anything from [/var/www/johnny/public_html/NEW/php.ini]

check this pastebin for a look at all I've done to this server... I had to retcon some of this stuff to reflect troubleshooting that I did later, so I hope I didn't miss anything. I haven't tried running thru this list from scratch (yet...). I'm also unsure if there are any significant lines to append, as I've been tooling around for a while today, mostly editing then reverting files.

1 Answer 1

0

I think I figured it out.

I started fresh and stepped thru each line of my pastebin, only using the necessary parts for PHP as FastCGI, and researched exactly how each little piece works. Then I tried many things that failed, then there was only thing left to try, and maybe this isn't the "right way", but...

create a new <Directory> block in /etc/apache2/sites-available/johnny.conf and copy the directives, but with a few changes

<Directory /var/www/johnny/public_html/new>
  Options +ExecCGI -Indexes +FollowSymLinks +MultiViews
  AllowOverride All
  AddHandler fcgid-script .php .htm .html
  FCGIWrapper /var/www/php-fcgi-scripts/johnny/php-fcgi-starter_new .php
  FCGIWrapper /var/www/php-fcgi-scripts/johnny/php-fcgi-starter_new .htm
  FCGIWrapper /var/www/php-fcgi-scripts/johnny/php-fcgi-starter_new .html
  Order allow,deny
  Allow from all
</Directory>

then, create a separate fcgi starter script /var/www/php-fcgi-scripts/johnny/php-fcgi-starter_new

#!/bin/sh
#PHPRC=/var/www/johnny/new
#export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
exec /usr/lib/cgi-bin/php -c /var/www/johnny/public_html/new

I found that PHPRC= didn't work in this case, but the -c parameter does! That's it. It's a PITA but it works well enough for my purposes.

1
  • Somehow I feel like there must be a dynamic way to reference the "working directory" of a page hit, but I googled the hell out of this, and you'd think I would have found something that awesome by now. something here is broken, in my opinion. I'm quite convinced that our web host's FastCGI environment works "properly", tho I haven't messed around with the code yet... obviously I'd rather have a sandbox for that.
    – clarence
    May 13, 2016 at 23:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .