Monday 24 December 2012

PHP Zend Issue with Virtual Hosting

 If you have to create a virtual host where you have lots of php application are running:

Step1: Include the "php_value include_path"
Example:
if you have the virtual dir is "amit" under "document root" then the zend path.

<VirtualHost *:80>
<IfModule mod_php5.c>
  php_value include_path ".:/usr/share/php:/var/www/amit/<zend_path>/thirdparty"
  php_admin_flag engine on
</IfModule>
DocumentRoot /var/www/amit    # -> this is where your virtual host code is there
ServerName amit.amitmund.com    # -> you need to have this "serverName" Because few code look for ServerName
#Alias /amit /var/www/amit    # -> Alias will not work if you have code that is using ServerName as base DocumentRoot
<DirectoryMatch /var/www/amit>
      Options FollowSymLinks
      DirectoryIndex index.html
      Order Allow,Deny
      Allow From All
</DirectoryMatch>

</VirtualHost>



PHP_Zend_include_file_apache_virtualHosting
PHP Fatal error:  Cannot redeclare class Zend_Loader in /var/www/<VHDomain>/<path_to>/Zend/Loader.php

Because of the following type of settings:

cat /etc/php5/apache2/php.ini inculude path:
include_path = ".:/usr/share/php:/var/www:/var/www/qa1/example/thirdparty:/var/www/amitmund.dev.example.com"

So following is the way to resolve the above issue. [ define the php value inside the virtual hosting itself ]

ISSUE:

 1. When I have a virtual hosting [ named based ] and using a php web services and if it is using Zend, then for a single environment, we can use "php.ini" file to define the include_path for the Zend. For ubuntu the path is " /etc/php5/apache2/php.ini [ search for include_path ]

 2. But at the virtual hosting environment the code points to its own Zend directory [ some time absolute and some time relative ] and for that I can't use multiple Zend path at the original php.ini "include_path" directory.

 3. So to resolve this issue, we can have a virtual hosting definition having the details of of php_value inside.

Example:

[ ubuntu OS ]

cat /etc/apache2/sites-available/amitmund.dev.example.com
<VirtualHost *:80>
<IfModule mod_php5.c>
  php_value include_path ".:/usr/share/php:/var/www:/var/www/amitmund.dev.example.com/example/thirdparty"
  php_admin_flag engine on
</IfModule>
 DocumentRoot /var/www/amitmund.dev.example.com
 ServerName amitmund.dev.example.com
</VirtualHost>

For more information: External link:
http://lmgtfy.com/?q=php+admin+values+apache
http://php.net/manual/en/configuration.changes.php

When using PHP as an Apache module, you can also change the configuration settings using directives in Apache configuration files (e.g. httpd.conf) and .htaccess files. You will need "AllowOverride Options" or "AllowOverride All" privileges to do so.

There are several Apache directives that allow you to change the PHP configuration from within the Apache configuration files. For a listing of which directives are PHP_INI_ALL, PHP_INI_PERDIR, or PHP_INI_SYSTEM, have a look at the List of php.ini directives appendix.

<IfModule mod_php5.c>
  php_value include_path ".:/usr/local/lib/php"
  php_admin_flag engine on
</IfModule>
<IfModule mod_php4.c>
  php_value include_path ".:/usr/local/lib/php"
  php_admin_flag engine on
</IfModule>

No comments:

Post a Comment