Migrating from Apache2 to Lighttpd: Part 1 - Installing FastCGI, PHP5, Zend, eaccelerator
Okay guys,
Before migrating to Lighttpd,
we need to recompile PHP to support FastCGI.
Folow the guide step by step.
It won’t take five minutes.
Promise 
In case you messed up somewhere.
DON’T WORRY, it’s just one email / comment away
Step 1)
Prepare location for installer
mkdir -p /root/INSTALL cd /root/INSTALL
Step 2)
Install FastCGI
wget http://www.fastcgi.com/dist/fcgi.tar.gz tar -zxvf fcgi-2.4.0.tar.gz cd fcgi-2.4.0 ./configure make make install cd ..
Step 3)
Rebuild PHP to support FastCGI
wget http://files.directadmin.com/services/customapache/php-5.2.9.tar.gz wget http://files.directadmin.com/services/customapache/php-5.2.9-mail-header.patch tar -zxvf php-5.2.9.tar.gz patch -p0 < php-5.2.9-mail-header.patch cd php-5.2.9 ./configure --enable-soap --with-libxml-dir=/usr/include/libxml2 \ --with-curl=/usr/local/lib --with-gd \ --enable-gd-native-ttf --with-ttf --with-gettext \ --with-jpeg-dir=/usr/local/lib \ --with-freetype-dir=/usr/local/lib --with-kerberos \ --with-openssl --with-mcrypt --with-mhash \ --with-mysql=/usr/bin/mysql --with-mysqli=/usr/bin/mysql_config \ --with-pdo-mysql=/usr/bin/mysql \ --with-pear --with-png-dir=/usr/local/lib \ --with-zlib --with-zlib-dir=/usr/local/lib --enable-zip --with-iconv=/usr/local \ --enable-bcmath --enable-calendar --enable-ftp --enable-magic-quotes --enable-sockets \ --enable-mbstring --with-curlwrappers --enable-shared --enable-static \ --enable-fastcgi --enable-force-cgi-redirect make make install cd ..
Step 4)
Install Zend Optimizer
wget http://files.directadmin.com/services/customapache/ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz tar -zxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz cd ZendOptimizer-3.3.3-linux-glibc23-i386 ./install.sh ENTER ENTER ENTER ENTER ENTER ENTER ENTER ENTER ENTER ENTER ENTER ENTER ENTER ENTER cd ..
Step 5)
Install eaccelerator
wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2 tar -xjvf eaccelerator-0.9.5.3.tar.bz2 cd eaccelerator-0.9.5.3 make clean export PHP_PREFIX="/usr/local" $PHP_PREFIX/bin/phpize ./configure \ --enable-eaccelerator=shared \ --with-php-config=$PHP_PREFIX/bin/php-config make clean make make install cd ..
Remember the location….
| [root@server eaccelerator-0.9.5.3]# make install
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/ |
If you forgot the location of your eaccelerator,
find it using this command:
locate eaccelerator.so
Find the location of your php.ini
php -r "phpinfo();" | grep php.ini Configuration File (php.ini) Path => /usr/local/lib Loaded Configuration File => /usr/local/Zend/etc/php.ini
Now, edit php.ini
vi /usr/local/Zend/etc/php.ini
and add / modify this line…
| [Zend] zend_extension=”/usr/local/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so” zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.3 zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.3 zend_optimizer.version=3.3.3 zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so zend_extension_ts=/usr/local/Zend/lib/ZendExtensionManager_TS.so eaccelerator.shm_size=”16″ eaccelerator.cache_dir=”/tmp/eaccelerator“ eaccelerator.enable=”1″ eaccelerator.optimizer=”1″ eaccelerator.check_mtime=”1″ eaccelerator.debug=”0″ eaccelerator.filter=”" eaccelerator.shm_max=”0″ eaccelerator.shm_ttl=”0″ eaccelerator.shm_prune_period=”0″ eaccelerator.shm_only=”0″ eaccelerator.compress=”1″ eaccelerator.compress_level=”9″ |
Create cache directory for eaccelerator
mkdir /tmp/eaccelerator chmod 0777 /tmp/eaccelerator
Step 6)
Check your php version
Make sure all work fine before we restart apache.
DO NOT restart apache before passing this step.
eaccelerator and Zend must be loaded properly…
| [root@server eaccelerator-0.9.5.3]# php -v PHP 5.2.9 (cli) (built: Mar 23 2009 12:19:57) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend Technologies |
php-cgi was compiled as fastcgi —> cgi-fcgi
| [root@server eaccelerator-0.9.5.3]# php-cgi -v PHP 5.2.9 (cgi-fcgi) (built: Mar 23 2009 12:19:24) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend Technologies |
Step 7)
Restart apache
service httpd restart
Step 8 9 10 ….
Troubleshooting 
and take a break.
Next … installing Lighttpd
Kohana and Zend, Killer Combo! The best PHP5 framework and library in one package.
My current favorite php framework is kohana. After several weeks playing with it, i feel that KohanaPhp far exceed CakePHP and CodeIgniter. Now i want to buid a *secret* site, after taking a look around i found that Zend framework has a neat library providing many classes that i need. Take a look of this list, you'll get the idea:
- Zend_Acl
- Zend_Captcha
- Zend_Feed
- Zend_Gdata
- Zend_Http
- Zend_OpenId
- Zend_Pdf
- Zend_Rest
- Zend_Service_Akismet
- Zend_Service_Amazon
- Zend_Service_Audioscrobbler
- Zend_Service_Delicious
- Zend_Service_Flickr
- Zend_Service_Nirvanix
- Zend_Service_ReCaptcha
- Zend_Service_Simpy
- Zend_Service_SlideShare
- Zend_Service_StrikeIron
- Zend_Service_Technorati
- Zend_Service_Twitter
- Zend_Service_Yahoo
I really love it, but i don't like zend framework itself. So i search around and found this cool tutorial.
It gives cool trick but doesn't work well, so i modify a bit.
Put the 'Zend' folder (unpacked from the Zend Framework package, under 'Library/') in Kohana installation's 'application/vendors/Zend' folder
Copy code below and paste it to a new file called Zend.php in application/libraries/.
-
/**
-
* Zend Framework Loader
-
*
-
* Put the 'Zend' folder (unpacked from the Zend Framework package, under 'Library/')
-
* in Kohana installation's 'application/vendors/Zend' folder
-
* You can put it elsewhere but remember to alter the script accordingly
-
*
-
* Usage:
-
* Zend::instance('Zend/Package/Name');
-
* Zend::instance('Zend/Service/Yahoo');
-
*
-
* * the second usage is useful for autoloading the Zend Framework library
-
* * Zend/Package/Name does not need the '.php' at the end
-
*/
-
class Zend
-
{
-
/**
-
* Returns a singleton instance of URI.
-
*
-
* @return object
-
*/
-
{
-
static $instance;
-
-
// Create the singleton
-
if ($instance == NULL)
-
{
-
// Initialize the URI instance
-
$instance = new Zend($class);
-
} else
-
{
-
$instance->load($class);
-
}
-
-
return $instance;
-
}
-
-
/**
-
* Constructor
-
*
-
* @param string $class class name
-
*/
-
function __construct($class = NULL)
-
{
-
// include path for Zend Framework
-
// alter it accordingly if you have put the 'Zend' folder elsewhere
-
-
if ($class)
-
{
-
require_once (string) $class . EXT;
-
//Log::add('debug', "Zend Class $class Loaded");
-
}
-
else
-
{
-
//Log::add('debug', "Zend Class Initialized");
-
}
-
}
-
-
/**
-
* Zend Class Loader
-
*
-
* @param string $class class name
-
*/
-
function load($class)
-
{
-
require_once (string) $class . EXT;
-
//Log::add('debug', "Zend Class $class Loaded");
-
}
-
-
}
Do you have trouble figuring out how to use it?
See an example below, you'll get a nice grab just within seconds:
-
class Welcome_Controller extends Controller {
-
-
public function index()
-
{
-
$zend = Zend::instance('Zend/Service/Yahoo');
-
$yahoo = new Zend_Service_Yahoo('zendtesting');
-
$keywords = "kitty";
-
-
if ($results->totalResults()> 0) {
-
echo '
-
<p id="image">';
-
echo '
-
<h2>Image Search Results</h2>
-
';
-
foreach ($results as $result) {
-
echo "<a href="http://php.fallenray.com/wp-admin/%7B$result-%3EClickUrl%7D" title="$result->Title"><img src="http://php.fallenray.com/wp-admin/%7B$result-%3EThumbnail-%3EUrl-%3EgetUri%28%29%7D" /></a>";
-
}
-
echo '
-
';
-
}
-
}
-
-
}
Another way to do this also posted as an updated tutorial. Things are getting much simpler now. I still liked my own twisted approach though :p
Also you might want to check out the official tutorial.
Happy ending, i can use the best PHP5 frameworks along with the best PHP5 library. It cannot get better than this. Try it, if you miss this you'll be sorry.