How to generate propel ORM objects on virtual host with no include_path?
Question
I have a dev server with several virtual hosts on it. Each one needs to be able to run the command: propel-gen ./ creole That script executes some php that reverse-engineers the database... BUT the php it executes needs to be included to do so.
There is no include_path set in the php.ini because it would be global to all virtual hosts. I need the include_path to be unique for each vhost.
How can I have this work on the command-line? (note: htaccess won't work, because command-line doesn't go through apache).
Is there another way around this problem? Perhaps passing a command-line param to set an include path? Perhaps setting something in .bashrc? :(
P.S. - The script works fine on my mac, which has a hard-coded include path
Solution
When running PHP from the command line, you can use the -d
switch to define configuration options, that would normally be defined in php.ini
For more informations about what can be done when running PHP in CLI, you can take a look at Using PHP from the command line
In your case, suppose you are running this, which only displays the current include_path
:
$ php -r 'var_dump(get_include_path());'
Default output would be like this (on my machine, btw) :
string(20) ".:/usr/local/lib/php"
Now, using -d
to override include_path
, this way :
$ php -dinclude_path='.:/usr/local/lib/php:/var/my/directory/lib' -r 'var_dump(get_include_path());'
You're getting :
string(42) ".:/usr/local/lib/php:/var/my/directory/lib"
I admit, this is pretty boring/long to type, and you will sometimes forget the -dblahblah
stuff...
So, you can define an alias, a bit like this :
$ alias myphp='php -dinclude_path=".:/usr/local/lib/php:/var/my/directory/lib"'
And now, if you are using myphp
command instead of php
, you don't need to specify the include_path
anymore :
$ myphp -r 'var_dump(get_include_path());'
string(42) ".:/usr/local/lib/php:/var/my/directory/lib"
This won't persist between shell sessions... So you could put the alias
command at the end of your ~/.bashrc
, so it's executed each time you log in :-)