Twilight SEO

Standing at the border line. Beautiful color spectrum of Search Engine Optimization. White, Gray, Black Hat SEO learning by doing.

Migrating from Apache2 to Lighttpd: Part 1 - Installing FastCGI, PHP5, Zend, eaccelerator

Posted in php4, php5, server, zend by ruru on the April 5th, 2009

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

Code:
mkdir -p /root/INSTALL
cd /root/INSTALL

Step 2)

Install FastCGI

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

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

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

Code:
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….

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

Code:
locate eaccelerator.so

Find the location of your php.ini

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

Code:
vi /usr/local/Zend/etc/php.ini

and add / modify this line…

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

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

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

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

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

Posted in kohanaphp, php5, zend by ruru on the December 14th, 2008

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/.

PHP:
  1. /**
  2. * Zend Framework Loader
  3. *
  4. * Put the 'Zend' folder (unpacked from the Zend Framework package, under 'Library/')
  5. * in Kohana installation's 'application/vendors/Zend' folder
  6. * You can put it elsewhere but remember to alter the script accordingly
  7. *
  8. * Usage:
  9. *   Zend::instance('Zend/Package/Name');
  10. *   Zend::instance('Zend/Service/Yahoo');
  11. *
  12. * * the second usage is useful for autoloading the Zend Framework library
  13. * * Zend/Package/Name does not need the '.php' at the end
  14. */
  15. class Zend
  16. {
  17. /**
  18. * Returns a singleton instance of URI.
  19. *
  20. * @return  object
  21. */
  22. public static function instance($class = NULL)
  23. {
  24. static $instance;
  25.  
  26. // Create the singleton
  27. if ($instance == NULL)
  28. {
  29. // Initialize the URI instance
  30. $instance = new Zend($class);
  31. } else
  32. {
  33. $instance-&gt;load($class);
  34. }
  35.  
  36. return $instance;
  37. }
  38.  
  39. /**
  40. * Constructor
  41. *
  42. * @param    string $class class name
  43. */
  44. function __construct($class = NULL)
  45. {
  46. // include path for Zend Framework
  47. // alter it accordingly if you have put the 'Zend' folder elsewhere
  48. ini_set('include_path',
  49. ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'vendors');
  50.  
  51. if ($class)
  52. {
  53. require_once (string) $class . EXT;
  54. //Log::add('debug', "Zend Class $class Loaded");
  55. }
  56. else
  57. {
  58. //Log::add('debug', "Zend Class Initialized");
  59. }
  60. }
  61.  
  62. /**
  63. * Zend Class Loader
  64. *
  65. * @param    string $class class name
  66. */
  67. function load($class)
  68. {
  69. require_once (string) $class . EXT;
  70. //Log::add('debug', "Zend Class $class Loaded");
  71. }
  72.  
  73. }

Do you have trouble figuring out how to use it?
See an example below, you'll get a nice grab just within seconds:

PHP:
  1. class Welcome_Controller extends Controller {
  2.  
  3. public function index()
  4. {
  5. $zend = Zend::instance('Zend/Service/Yahoo');
  6. $yahoo = new Zend_Service_Yahoo('zendtesting');
  7. $keywords = "kitty";
  8. $results = $yahoo-&gt;imageSearch($keywords, array("results" =&gt; 5));
  9.  
  10. if ($results-&gt;totalResults()&gt; 0) {
  11. <p id="image">';
  12. <h2>Image Search Results</h2>
  13. ';
  14. foreach ($results as $result) {
  15. echo "<a href="http://php.fallenray.com/wp-admin/%7B$result-%3EClickUrl%7D" title="$result-&gt;Title"><img src="http://php.fallenray.com/wp-admin/%7B$result-%3EThumbnail-%3EUrl-%3EgetUri%28%29%7D" /></a>";
  16. }
  17. ';
  18. }
  19. }
  20.  
  21. }

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.




Cannot find your answer here?
Feel free to get in touch and ask PHP-ist anything, just anything :)