Installing Lighttpd With PHP5 (PHP-FPM) And MySQL Support On OpenSUSE 12.2 - Page 2

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Sun, 2012-09-30 17:58. ::

5 Configuring Lighttpd And PHP5

To enable PHP5 in Lighttpd, we must modify two files, /etc/lighttpd/modules.conf and /etc/lighttpd/conf.d/fastcgi.conf.

Open /etc/lighttpd/modules.conf and uncomment the line include "conf.d/fastcgi.conf":

vi /etc/lighttpd/modules.conf

[...]
##
## FastCGI (mod_fastcgi)
##
include "conf.d/fastcgi.conf"
[...]

Then we open /etc/lighttpd/conf.d/fastcgi.conf and make sure that it contains the line server.modules += ( "mod_fastcgi" ):

vi /etc/lighttpd/conf.d/fastcgi.conf

#######################################################################
##
##  FastCGI Module
## ---------------
##
## http://www.lighttpd.net/documentation/fastcgi.html
##
server.modules += ( "mod_fastcgi" )
[...]

Then, further down the file, there's a fastcgi.server stanza - leave it commented and add your own fastcgi.server stanza as follows:

[...]
##
## PHP Example
## For PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini.
##
## The number of php processes you will get can be easily calculated:
##
## num-procs = max-procs * ( 1 + PHP_FCGI_CHILDREN )
##
## for the php-num-procs example it means you will get 17*5 = 85 php
## processes. you always should need this high number for your very
## busy sites. And if you have a lot of RAM. :)
##


fastcgi.server += ( ".php" =>
        ((
                "host" => "127.0.0.1",
                "port" => "9000",
                "broken-scriptfilename" => "enable"
        ))
)

#fastcgi.server = ( ".php" =>
#                   ( "php-local" =>
#                     (
#                       "socket" => socket_dir + "/php-fastcgi-1.socket",
#                       "bin-path" => server_root + "/cgi-bin/php5",
#                       "max-procs" => 1,
#                       "broken-scriptfilename" => "enable",
#                     )
#                   ),
[...]

Then we restart Lighttpd:

systemctl restart lighttpd.service

 

6 Testing PHP5 / Getting Details About Your PHP5 Installation

The document root of the default web site is /srv/www/htdocs. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

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 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:

zypper install 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-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 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 open Lighttpd's PHP configuration file /etc/lighttpd/conf.d/fastcgi.conf and replace the host and port lines with "socket" => "/tmp/php5-fpm.sock":

vi /etc/lighttpd/conf.d/fastcgi.conf

[...]
fastcgi.server += ( ".php" =>
        ((
                "socket" => "/tmp/php5-fpm.sock",
                "broken-scriptfilename" => "enable"
        ))
)
[...9

Finally restart Lighttpd:

systemctl restart lighttpd.service

 

9 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.