从命令行运行PHP脚本(Running PHP script from command line)

编程入门 行业动态 更新时间:2024-10-25 22:28:55
命令行运行PHP脚本(Running PHP script from command line)

因此,我正在与PHP / MySQL网站上的设计师合作,他希望有一些脚本可以让他的生活更轻松。 他非常适合使用git,SASS,node等东西的命令行。我希望他能像运行程序一样运行我的脚本,而不是通过PHP运行它。

所以不是这样的:

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

我想这样做:

myscript create_module module_name

是否可以在Apache服务器上使用PHP执行此操作? 我知道我很可能必须修改服务器才能正确解释它,这很好。 我甚至不知道从哪里开始,也无法在Google上找到我需要的东西。

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.

最满意答案

你最好的选择是创建一个alias 。

所以myscript的别名实际上会指向命令: php /path/to/file/create_module.php然后任何额外的参数将作为类型传递。

在命令行中,执行以下操作:

cd /etc/ nano bash.bashrc

在文件的最底部,添加以下文本行:

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

BASHRC是一个在用户登录时运行的脚本,因此每次用户登录系统时都会重新创建别名。

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.

更多推荐

本文发布于:2023-07-24 10:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1244937.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令行   脚本   PHP   Running   command

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!