Yawd website

jun16

Scan additional PHP 5 .ini files in Eclipse PDT

Although Windows systems seem to load all PHP 5 variables & extensions from a single php.ini file, there might be system configurations -especially Linux systems (Ubuntu in my case)- that use multiple .ini files. In such systems, PHP configuration is usually located inside the /etc/php5 directory: When running in cli mode, /etc/php5/cli/php.ini gets loaded along with all .ini files located in the /var/php5/cli/conf.d directory.. When using Apache, /etc/php5/apache2/php.ini and /etc/php5/apache2/conf.d/*.ini files are all loaded. The same is true for php-cgi. To load the additional .ini files, either a PHP_INI_SCAN_DIR environmental variable or the --with-config-file-path option can be used. So far so good.

When it comes to Eclipse PDT, it seems that the additional .ini files are not loaded when PHP runs as script. After hours of searching, I came across an Eclipse bug indicating that this is not a PHP 5 issue nor a system mis-configuration. Eclipse just needs a single php.ini file that contains all your PHP configuration (Note that when the project runs as 'PHP Web Page' it should work at the first place because it uses your web server's runtime). To overcome this problem, first use the following command:

shell
sudo paste -s -d "\n" cgi/php.ini conf.d/*.ini > ~/php.ini

We have just created a single php.ini file in our home directory that contains the php-cgi configuration. Now open Eclipse and visit Preferences->PHP->PHP Executables screen. Edit your PHP-CGI executable record -or select 'Add..' if it does not exist. Set the 'Additional PHP ini file' field as shown in Figure 1. Replace 'ppetrid' with your actual username.

PHP executable configuration

This will skip the default php.ini file configured for php-cgi and load our own .ini file instead. At this stage you should ignore the output of phpinfo() claiming that /etc/php5/cgi/php.ini is used. Eclipse uses a copy of the provided php.ini file, placed under your /tmp directory. To confirm it works, right click your index.php file, select Run as->PHP script and there you go! Of course do not forget to do the same for your PHP CLI executable :)!

Hope this helps, make sure to leave a comment or contact me if you have any questions.

Comments powered by Disqus