Welcome! Log In Create A New Profile

Advanced

here is an example of config for php-fpm, apache, mod_fastcgi, and a virtual host

Posted by Randy Syring 
I spent half the day trying to figure out how to get php-fpm working
with apache and fastcgi for a virtual host, here is what I came up
with:

<VirtualHost *:80>
ServerName www.example.com
ServerAdmin sysadmin@example.com

DocumentRoot /home/webuser/domains/www.example.com/public_html/

FastCGIExternalServer /home/webuser/domains/www.example.com/
public_html/php-fpm -host 127.0.0.1:9000
AddType application/x-httpd-fastphp .php
Action application/x-httpd-fastphp /php-fpm

<Directory /home/racktables/>
AllowOverride None
</Directory>
<Directory /home/webuser/domains/www.example.com/public_html/>
Options Indexes -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
allow from all
</Directory>

ErrorLog /var/log/apache2/example_com_error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/example_com_access.log combined
</VirtualHost>

I am on ubuntu Lucid and got php-fpm by using this PPA:

https://launchpad.net/~brianmercer/+archive/php
ok I've hit a snag...

If I use what the Randy specified I'm able to browse http://site.com/
and index.php is used.
As soon as I add the follow mod_rewrite rules it all turns to shit

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

so I found this

FastCgiExternalServer /home/bob/public_html -host 127.0.0.1:9000
AddHandler php-fastcgi .php
Action php-fastcgi /virtualhtml
Alias /virtualhtml /home/bob/public_html

which works great with the mod_rewrite rules however when I go to
http://site.com/ i get "No input file specified." however going to
http://site.com/index.php works just fine.

any ideas on how to get the mod_rewrite rules to work with http://site.com/
so i don't need to use http://site.com/index.php ?

Thanks

On Aug 15, 3:13 pm, Randy Syring <rsyr...@gmail.com> wrote:
> I spent half the day trying to figure out how to get php-fpm working
> with apache and fastcgi for a virtual host, here is what I came up
> with:
>
> <VirtualHost *:80>
>         ServerNamewww.example.com
>         ServerAdmin sysad...@example.com
>
>         DocumentRoot /home/webuser/domains/www.example.com/public_html/
>
>         FastCGIExternalServer /home/webuser/domains/www.example.com/
> public_html/php-fpm -host 127.0.0.1:9000
>         AddType application/x-httpd-fastphp .php
>         Action application/x-httpd-fastphp /php-fpm
>
>         <Directory /home/racktables/>
>                 AllowOverride None
>         </Directory>
>         <Directory /home/webuser/domains/www.example.com/public_html/>
>                 Options Indexes -MultiViews +SymLinksIfOwnerMatch
>                 Order allow,deny
>                 allow from all
>         </Directory>
>
>         ErrorLog /var/log/apache2/example_com_error.log
>
>         # Possible values include: debug, info, notice, warn, error, crit,
>         # alert, emerg.
>         LogLevel warn
>
>         CustomLog /var/log/apache2/example_com_access.log combined
> </VirtualHost>
>
> I am on ubuntu Lucid and got php-fpm by using this PPA:
>
> https://launchpad.net/~brianmercer/+archive/php
actually done more testing and the config I found is bogus - every request
goes through php-fpm including static files...

so now I just need to figure out how to adapt the rewrite rules to be used
with fastcgi...

On Tue, Aug 17, 2010 at 3:13 AM, Nicholas <nicholas.orr@zxgen.net> wrote:

> ok I've hit a snag...
>
> If I use what the Randy specified I'm able to browse http://site.com/
> and index.php is used.
> As soon as I add the follow mod_rewrite rules it all turns to shit
>
> RewriteEngine On
> RewriteBase /
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
>
> so I found this
>
> FastCgiExternalServer /home/bob/public_html -host 127.0.0.1:9000
> AddHandler php-fastcgi .php
> Action php-fastcgi /virtualhtml
> Alias /virtualhtml /home/bob/public_html
>
> which works great with the mod_rewrite rules however when I go to
> http://site.com/ i get "No input file specified." however going to
> http://site.com/index.php works just fine.
>
> any ideas on how to get the mod_rewrite rules to work with
> http://site.com/
> so i don't need to use http://site.com/index.php ?
>
> Thanks
>
> On Aug 15, 3:13 pm, Randy Syring <rsyr...@gmail.com> wrote:
> > I spent half the day trying to figure out how to get php-fpm working
> > with apache and fastcgi for a virtual host, here is what I came up
> > with:
> >
> > <VirtualHost *:80>
> > ServerNamewww.example.com
> > ServerAdmin sysad...@example.com
> >
> > DocumentRoot /home/webuser/domains/www.example.com/public_html/
> >
> > FastCGIExternalServer /home/webuser/domains/www.example.com/
> > public_html/php-fpm -host 127.0.0.1:9000
> > AddType application/x-httpd-fastphp .php
> > Action application/x-httpd-fastphp /php-fpm
> >
> > <Directory /home/racktables/>
> > AllowOverride None
> > </Directory>
> > <Directory /home/webuser/domains/www.example.com/public_html/>
> > Options Indexes -MultiViews +SymLinksIfOwnerMatch
> > Order allow,deny
> > allow from all
> > </Directory>
> >
> > ErrorLog /var/log/apache2/example_com_error.log
> >
> > # Possible values include: debug, info, notice, warn, error,
> crit,
> > # alert, emerg.
> > LogLevel warn
> >
> > CustomLog /var/log/apache2/example_com_access.log combined
> > </VirtualHost>
> >
> > I am on ubuntu Lucid and got php-fpm by using this PPA:
> >
> > https://launchpad.net/~brianmercer/+archive/php
>
stuff it going back to nginx :)

turns out why I was trying to use apache was stupid anyway - apache is doing
the wrong thing and the developer of the php is basing work on a bug, thus
ensuring code only works with apache. fixed the code and it works on nginx.
nginx FTW

nick

On Tue, Aug 17, 2010 at 3:45 AM, Nicholas Orr <nicholas.orr@zxgen.net>wrote:

> actually done more testing and the config I found is bogus - every request
> goes through php-fpm including static files...
>
> so now I just need to figure out how to adapt the rewrite rules to be used
> with fastcgi...
>
>
> On Tue, Aug 17, 2010 at 3:13 AM, Nicholas <nicholas.orr@zxgen.net> wrote:
>
>> ok I've hit a snag...
>>
>> If I use what the Randy specified I'm able to browse http://site.com/
>> and index.php is used.
>> As soon as I add the follow mod_rewrite rules it all turns to shit
>>
>> RewriteEngine On
>> RewriteBase /
>> RewriteCond %{REQUEST_FILENAME} !-d
>> RewriteCond %{REQUEST_FILENAME} !-f
>> RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
>>
>> so I found this
>>
>> FastCgiExternalServer /home/bob/public_html -host 127.0.0.1:9000
>> AddHandler php-fastcgi .php
>> Action php-fastcgi /virtualhtml
>> Alias /virtualhtml /home/bob/public_html
>>
>> which works great with the mod_rewrite rules however when I go to
>> http://site.com/ i get "No input file specified." however going to
>> http://site.com/index.php works just fine.
>>
>> any ideas on how to get the mod_rewrite rules to work with
>> http://site.com/
>> so i don't need to use http://site.com/index.php ?
>>
>> Thanks
>>
>> On Aug 15, 3:13 pm, Randy Syring <rsyr...@gmail.com> wrote:
>> > I spent half the day trying to figure out how to get php-fpm working
>> > with apache and fastcgi for a virtual host, here is what I came up
>> > with:
>> >
>> > <VirtualHost *:80>
>> > ServerNamewww.example.com
>> > ServerAdmin sysad...@example.com
>> >
>> > DocumentRoot /home/webuser/domains/www.example.com/public_html/
>> >
>> > FastCGIExternalServer /home/webuser/domains/www.example.com/
>> > public_html/php-fpm -host 127.0.0.1:9000
>> > AddType application/x-httpd-fastphp .php
>> > Action application/x-httpd-fastphp /php-fpm
>> >
>> > <Directory /home/racktables/>
>> > AllowOverride None
>> > </Directory>
>> > <Directory /home/webuser/domains/www.example.com/public_html/>
>> > Options Indexes -MultiViews +SymLinksIfOwnerMatch
>> > Order allow,deny
>> > allow from all
>> > </Directory>
>> >
>> > ErrorLog /var/log/apache2/example_com_error.log
>> >
>> > # Possible values include: debug, info, notice, warn, error,
>> crit,
>> > # alert, emerg.
>> > LogLevel warn
>> >
>> > CustomLog /var/log/apache2/example_com_access.log combined
>> > </VirtualHost>
>> >
>> > I am on ubuntu Lucid and got php-fpm by using this PPA:
>> >
>> > https://launchpad.net/~brianmercer/+archive/php
>>
>
>
Nicholas,

just add a "Rewrite ^php-fpm - [L]" as your first rewrite rule and you are done.

If anyone is aware of a more elegant way, please shot ;).

cheers,
NIkolas
Great, thanks for sharing that NIkolas, will come in handy for the next
person :)

Server is setup for nginx I only installed apache cause this php code
wouldn't work properly, fixed the code so it works properly rather than
relying on bug in apache.

Searching Google for php-fpm apache fastcgi is not very helpful, so
hopefully now it will show up :)

On Tue, Aug 17, 2010 at 6:26 PM, Nikolas Hagelstein <
nikolas.hagelstein@googlemail.com> wrote:

> Nicholas,
>
> just add a "Rewrite ^php-fpm - [L]" as your first rewrite rule and you are
> done.
>
> If anyone is aware of a more elegant way, please shot ;).
>
> cheers,
> NIkolas
>
Hi,

well, got a good coffee so i decided to play arround a little.

That way you do not need to exclude the fake handler from your rewrite
rules manually...:).

Globaly:
//We want to have all sockets within this directory
FastCgiIpcDir /var/lib/apache2/fastcgi2

//Register a cumstom handler to .php .php5 scripts
AddHandler php-fastcgi .php .php5

//Point this handler to /php5/php-fpm
Action php-fastcgi /php5/php-fpm

//Set the register fastcgi-script handler + whatever you want for
every fpm request.
<Location /php5/php-fpm>
SetHandler fastcgi-script
Options +ExecCGI
</Location>

//Set mime type
AddType application/x-httpd-php .php .php5


Per vhost:

//Alias /php5/ to /var/www/fcgi/www.example.com/ (should be in place
since this enables you to easily switch back to FastCgiServer)
ScriptAlias /php5/ /var/www/fcgi/www.example.com/

//Pickup request and forward it to the particular fpm socket.
FastCGIExternalServer /var/www/fcgi/www.example.com/php-fpm -socket
www.example.com


Cheers,
NIkolas
I just thought I'd chime in with a slightly different, but still
effective Apache configuration example:

Globally:
<IfModule mod_fastcgi.c>

# Directory where the PHP-FPM fastcgi sockets exist
FastCgiIpcDir /usr/local/var/run/fastcgi

# All files ending in .php will be handled by php-fpm
<FilesMatch \.php$>
SetHandler php5-fcgi
</FilesMatch>

# Fake directory that handles php-fpm requests.
# Directory can be anything, it should not exist and will
# not be visible to the end-user
# Each virtual host will alias this to a PHP-FPM socket
<Location "/fastcgiphp">
Order Deny,Allow
Deny from All
# Prevent accessing this path directly
Allow from env=REDIRECT_STATUS
</Location>

# Direct all PHP requests to the /fastcgiphp fake directory
# Each virtual host will alias this to a PHP-FPM socket
Action php5-fcgi /fastcgiphp
</IfModule>


Per php-fpm socket (this may be per virtual host, per user, per server,
etc):
<IfModule mod_fastcgi.c>
# Reference to external PHP-FPM socket
# The path (/usr/local/bin) must exist but the filename (bob-php-fpm)
# does not have to exist. The socket file (bob-php-fpm.sock) should
exist
# in the directory specified by the FastCgiIpcDir directive
(/usr/local/var/run/fastcgi)
FastCgiExternalServer /usr/local/bin/bob-php-fpm -socket bob-php-fpm.sock
</IfModule>

Per virtual host:
<VirtualHost *:80>
ServerName ...
...
<IfModule mod_fastcgi.c>
# Alias php requests to our PHP-FPM socket
Alias /fastcgiphp /usr/local/bin/bob-php-fpm
</IfModule>
</VirtualHost>

Brandon

On 8/17/10 6:13 AM, Nikolas Hagelstein wrote:
> Hi,
>
> well, got a good coffee so i decided to play arround a little.
>
> That way you do not need to exclude the fake handler from your rewrite
> rules manually...:).
>
> Globaly:
> //We want to have all sockets within this directory
> FastCgiIpcDir /var/lib/apache2/fastcgi2
>
> //Register a cumstom handler to .php .php5 scripts
> AddHandler php-fastcgi .php .php5
>
> //Point this handler to /php5/php-fpm
> Action php-fastcgi /php5/php-fpm
>
> //Set the register fastcgi-script handler + whatever you want for
> every fpm request.
> <Location /php5/php-fpm>
> SetHandler fastcgi-script
> Options +ExecCGI
> </Location>
>
> //Set mime type
> AddType application/x-httpd-php .php .php5
>
>
> Per vhost:
>
> //Alias /php5/ to /var/www/fcgi/www.example.com/ (should be in place
> since this enables you to easily switch back to FastCgiServer)
> ScriptAlias /php5/ /var/www/fcgi/www.example.com/
>
> //Pickup request and forward it to the particular fpm socket.
> FastCGIExternalServer /var/www/fcgi/www.example.com/php-fpm -socket
> www.example.com
>
>
> Cheers,
> NIkolas
Hi Brandon,

Nice, thanks for sharing :).

Could you point out why, you used <FilesMatch \.php$> over AddHandler ?
Cheers,
Nikolas
On 8/17/10 11:25 AM, Nikolas Hagelstein wrote:
> Could you point out why, you used<FilesMatch \.php$> over AddHandler ?

Apache's AddHandler configuration directive is triggered if the filename
*contains* the extension rather than *ends with* the extension. So a file
mycode.php.html
will be parsed as a PHP file when AddHandler is used, but not when the
FilesMatch directive is used.

See:
http://httpd.apache.org/docs/2.2/mod/mod_mime.html#multipleext


Of course, I cannot remember why this mattered to me ;)
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 113
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready