If you are using both PHP CLI and PHP GTK on the same desktop machine, you may run into certain errors if you launch PHP CLI program from command line logged as another user.

PHP Fatal error: php-gtk: Could not open display in Unknown on line 0
Could not startup.

If you have logged in as one user, you cannot run standard PHP CLI commands as another user from command shell because that user has no access to your desktop environment. If you have to test php scripts which are designed to be used by other users, then you can solve this very easily. Make a copy of /etc/php5/cli

sudo mkdir /etc/php5/cli_gtk
sudo cp /etc/php5/cli/php.ini /etc/php5/cli_gtk/
sudo ln -s /etc/php5/conf.d /etc/php5/cli/conf.d

Now remove from /etc/php5/cli/php.ini those dynamic extension lines for php_gtk and cairo, and same the file. When you run standard PHP CLI, you can launch them with

php myprogram.php

But when you want to run PHP GTK programs, you can launch them with

php -c /etc/php5/cli_gtk/ myprogram.php

extra parameter tells php interpreter to use php.ini in directory /etc/php5/cli_gtk.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

  • Enter your email address to follow this blog and receive notifications of new posts by email.

    Join 105 other followers

%d bloggers like this: