Installing PHP5

Our web-based file browser is a PHP application. Therefore, our next task is to install PHP5 and PHP-FPM. PHP-FPM is a daemon process that runs a FastCGI server on port 9000. The init script for this application is stored at /etc/init.d/php5-fpm/php.ini.

To install these two programs, enter the following command:

apt-get install php5-fpm php5

Configuring Lighttpd and PHP5

To enable PHP5 in Lighttpd, we must modify /etc/php5/fpm/php.ini and uncomment the line cgi.fix_pathinfo=1:

;http://php.net/cgi.fix-pathinfo
;cgi.fix_pathinfo=1

Remove the semicolon present at the beginning of the previous line.

The Lighttpd configuration file for PHP /etc/lighttpd/conf-available/15-fastcgi-php.conf is suitable for use with spawn-fcgi. However, we want to use PHP-FPM; therefore, we create a backup of the file (named 15-fastcgi-php-spawnfcgi.conf) and modify 15-fastcgi-php.conf, as follows:

  1. cd /etc/lighttpd/conf-available/
  2. cp 15-fastcgi-php.conf 15-fastcgi-php-spawnfcgi.conf
  3. nano 15-fastcgi-php.conf

We then add the following code to the config file:

# /usr/share/doc/lighttpd/fastcgi.txt.gz
# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:Configuration Options#mod_fastcgi-fastcgi
## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server += ( ".php" =>
        ((
                "socket" => "/var/run/php5-fpm.sock",
                "broken-scriptfilename" => "enable"
        ))
)

Lighttpd has a number of different modules that can be enabled by running the lighttpd-enable-mod <module> command.

To enable the fastcgi configuration, run the following command:

lighttpd-enable-mod fastcgi

As a result of running the command, the following messages are displayed in the terminal:

Available modules: auth accesslog cgi evasive evhost expire fastcgi flv-streaming no-www proxy rrdtool simple-vhost ssi ssl status userdir usertrack fastcgi-php-spawnfcgi fastcgi-php debian-doc
Already enabled modules:
Enabling fastcgi: ok
Run /etc/init.d/lighttpd force-reload to enable changes

We proceed further by running the following command:

lighttpd-enable-mod fastcgi-php

The messages displayed in the terminal will look like the following:

Available modules: auth accesslog cgi evasive evhost expire fastcgi flv-streaming no-www proxy rrdtool simple-vhost ssi ssl status userdir usertrack fastcgi-php-spawnfcgi fastcgi-php debian-doc
Already enabled modules: fastcgi
Enabling fastcgi-php: ok

This creates the symlinks /etc/lighttpd/conf-enabled/10-fastcgi.conf, which points to /etc/lighttpd/conf-available/10-fastcgi.conf, and /etc/lighttpd/conf-enabled/15-fastcgi-php.conf, which points to /etc/lighttpd/conf-available/15-fastcgi-php.conf.

Now, enter the following command:

cd /etc/lighttpd/conf-enabled
ls –l

You will see the following messages in the terminal:

10-fastcgi.conf -> ../conf-available/10-fastcgi.conf

fastcgi-php.conf -> ../conf-available/15-fastcgi-php.conf

We then force a reload, as follows:

root@beaglebone: /etc/init.d/lighttpd force-reload

This causes the terminal to display the following:

* Reloading web server configuration lighttpd [ OK ]

Testing PHP5

The document root of the default website is /var/www. We will now create a small PHP file (info.php) in this directory and call it in a browser:

nano Info.php
<?php
phpinfo();
?>

The following screenshot shows how Info.php looks in a browser:

Testing PHP5

The file will display lots of useful details about our PHP installation, such as the installed PHP version, as shown here:

Testing PHP5

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

Setting up 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. You can search for available PHP5 modules as follows:

root@beaglebone:/apt-cache search php5

You will see the following messages being displayed:

php5-curl - CURL module for php5
php5-dbg - Debug symbols for PHP5
php5-dev - Files for PHP5 module development
php5-gd - GD module for php5
php5-gmp - GMP module for php5
php5-ldap - LDAP module for php5
php5-mysql - MySQL module for php5
php5-odbc - ODBC module for php5

Pick the modules you need and install them. These are the ones that I installed:

apt-get install php5-mysql php5-curl

Xcache is a PHP opcode cacher for caching and optimizing PHP intermediate code. Xcache can be installed as follows:

apt-get install php5-xcache

Reload the PHP-FPM service:

/etc/init.d/php5-fpm reload

Now, reload http://192.168.10.127/info.php in your browser and scroll down to the modules section again.

You should now find lots of new modules here, including the mysql module:

Setting up MySQL support in PHP5
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.162.49