Kyle Piontek Kyle Piontek - 1 year ago 93
PHP Question

Running PHP script from command line

So I'm working with a designer on a website in PHP/MySQL and there are a few scripts that he would like to have to make life easier for him. He is pretty comfortable using the command line for stuff like git, SASS, node, etc. I would like him to be able to run my scripts like he would run a program, instead of running it through PHP.

So instead of this:

php /path/to/file/create_module.php module_name

I would like to do this:

myscript create_module module_name

Is it possible to do this with PHP on an Apache server? I know I will most likely have to modify the server to interpret it properly, which is fine. I just don't even know where to begin, and couldn't find what I needed on Google.

Answer Source

Your best bet would to be to create an alias.

So an alias of myscript would actually point to the command: php /path/to/file/create_module.php and then any extra arguments will be passed as typed.

In command line, do the following:

cd /etc/
nano bash.bashrc

At the very bottom of the file, add this line of text:

alias "myscript=php /path/to/file/create_module.php"

BASHRC is a script that is run on user login, so the alias will be recreated every time the user logs into the system.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download