Using PHP5-FPM With Apache2 On OpenSUSE 12.1 - Page 2

6 Configuring Apache

To make Apache work with PHP-FPM, we need the following configuration:

        <IfModule mod_fastcgi.c>
                <Directory "/usr/lib/cgi-bin">
                        AllowOverride None
                        Options +ExecCGI -Includes
                        SetHandler fastcgi-script
                        Order allow,deny
                        Allow from all
                </Directory>
                DirectoryIndex index.html index.shtml index.cgi index.php
                AddHandler php5-fcgi .php
                Action php5-fcgi /php5-fcgi
                Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
                FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
        </IfModule>

(To learn more about the FastCgiExternalServer directive, take a look at http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiExternalServer.)

You can put it in the global Apache configuration (so it's enabled for all vhosts), for example in /etc/apache2/conf.d/mod_fastcgi.conf, or you can place it in each vhost that should use PHP-FPM. I want to use PHP-FPM with all vhosts so I open /etc/apache2/conf.d/mod_fastcgi.conf...

vi /etc/apache2/conf.d/mod_fastcgi.conf

... and put the following section at the end:

[...]
        <IfModule mod_fastcgi.c>
                <Directory "/usr/lib/cgi-bin">
                        AllowOverride None
                        Options +ExecCGI -Includes
                        SetHandler fastcgi-script
                        Order allow,deny
                        Allow from all
                </Directory>
                DirectoryIndex index.html index.shtml index.cgi index.php
                AddHandler php5-fcgi .php
                Action php5-fcgi /php5-fcgi
                Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
                FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
        </IfModule>

The /usr/lib/cgi-bin/ directory must exist, so we create it as follows:

mkdir /usr/lib/cgi-bin/

Restart Apache afterwards:

systemctl restart apache2.service

Now create the following PHP file in the document root /srv/www/htdocs of the default Apache vhost:

vi /srv/www/htdocs/info.php
<?php
phpinfo();
?>

Now we call that file in a browser (e.g. http://192.168.0.100/info.php):

As you see, PHP5 is working, and it's working through FPM/FastCGI, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don't have MySQL support in PHP5 yet.

 

7 Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php5-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications:

yast2 -i php5-mysql php5-bcmath php5-bz2 php5-calendar php5-ctype php5-curl php5-dom php5-ftp php5-gd php5-gettext php5-gmp php5-iconv php5-imap php5-ldap php5-mbstring php5-mcrypt php5-odbc php5-openssl php5-pcntl php5-pgsql php5-posix php5-shmop php5-snmp php5-soap php5-sockets php5-sqlite php5-sysvsem php5-tokenizer php5-wddx php5-xmlrpc php5-xsl php5-zlib php5-exif php5-fastcgi php5-pear php5-sysvmsg php5-sysvshm

Now reload PHP-FPM:

systemctl reload php-fpm.service

Now reload http://192.168.0.100/info.php in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module:

 

8 phpMyAdmin

phpMyAdmin is a web interface through which you can manage your MySQL databases.

phpMyAdmin can be installed as follows:

yast2 -i phpMyAdmin

To make sure that we can access phpMyAdmin from all websites created through ISPConfig later on by using /phpmyadmin (e.g. http://www.example.com/phpmyadmin) and /phpMyAdmin (e.g. http://www.example.com/phpMyAdmin), open /etc/apache2/conf.d/phpMyAdmin.conf...

vi /etc/apache2/conf.d/phpMyAdmin.conf

... and add the following two aliases right at the beginning:

Alias /phpMyAdmin /srv/www/htdocs/phpMyAdmin
Alias /phpmyadmin /srv/www/htdocs/phpMyAdmin
[...]

Restart Apache and reload PHP-FPM:

systemctl restart apache2.service
systemctl reload php-fpm.service

Afterwards, you can access phpMyAdmin under http://192.168.0.100/phpMyAdmin/:

 

9 Making PHP-FPM Use A Unix Socket

By default PHP-FPM is listening on port 9000 on 127.0.0.1. It is also possible to make PHP-FPM use a Unix socket which avoids the TCP overhead. To do this, open /etc/php5/fpm/php-fpm.conf...

vi /etc/php5/fpm/php-fpm.conf

... and make the listen line look as follows:

[...]
;listen = 127.0.0.1:9000
listen = /tmp/php5-fpm.sock
[...]

Also set the owner, group, and permissions of the socket as follows:

[...]
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
;                 mode is set to 0666
listen.owner = nobody
listen.group = nobody
listen.mode = 0666
[...]

Then reload PHP-FPM:

systemctl reload php-fpm.service

Next go through your Apache configuration and all your vhosts and change the lineFastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization to FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /tmp/php5-fpm.sock -pass-header Authorization, e.g. like this:

vi /etc/apache2/conf.d/mod_fastcgi.conf
[...]
        <IfModule mod_fastcgi.c>
                <Directory "/usr/lib/cgi-bin">
                        AllowOverride None
                        Options +ExecCGI -Includes
                        SetHandler fastcgi-script
                        Order allow,deny
                        Allow from all
                </Directory>
                DirectoryIndex index.html index.shtml index.cgi index.php
                AddHandler php5-fcgi .php
                Action php5-fcgi /php5-fcgi
                Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
                FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /tmp/php5-fpm.sock -pass-header Authorization
        </IfModule>

Finally reload Apache:

systemctl reload apache2.service

 

Share this page:

0 Comment(s)