PHP CLI - something like $PATH
I want to ask you if there is something like UNIX $PATH for PHP CLI.
Eg., I want to use
php a2addvhost.php example.com
instead of
php /usr/share/php/a2addvhost.php example.com
I tried to change inclu开发者_如何学编程de_path and $PATH but either work.
If you're doing
php a2addvhost.php example.com
You're still in Unix. So the a2addvhost.php
file must be in the current directory for it to work.
The first argument must be the exact pathname. However, you can make a start script (as root):
$ echo -e '#!/bin/sh\nexec php /usr/share/php/a2addvhost.php "$@"\n' \
> /usr/bin/a2addvhost
$ # And then start with ...
$ a2addvhost example.com
Alternatively, make a2addvhost.php
executable by prepending it as follows:
#!/usr/bin/env php
<?php
/* php code goes here */
and making it executable:
$ chmod a+x /usr/share/php/a2addvhost.php
Now, if PATH contains /usr/share/php/
, you can start your script with
$ /usr/share/php/a2addvhost.php example.com
Add /usr/share/php/
to your PATH, give it the executable flag, then simply run
a2addvhost.php example.com
you may need to add the shebang at the beginning of the file.
精彩评论