linux - 当 php 安装为 apache 模块时,从命令行运行 php 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1242146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
linux - running php script from command line when php is installed as apache module
提问by David
Normally when I want to run a php script from the command line I just create a php page, add a shebang pointing to the php binary, then ./file.php to run it. Since I have php installed as an apache module, I'm not even sure what my shebang should look like. Any ideas?
通常,当我想从命令行运行 php 脚本时,我只是创建一个 php 页面,添加一个指向 php 二进制文件的 shebang,然后 ./file.php 来运行它。由于我已将 php 安装为 apache 模块,因此我什至不确定我的 shebang 应该是什么样子。有任何想法吗?
采纳答案by David Wolever
If it's just an Apache module, I don't think you can do it… At least, not without using a script like this:
如果它只是一个 Apache 模块,我认为你做不到……至少,如果不使用这样的脚本:
$ cat run_php_with_apache
#!/bin/sh
cp "" /var/www/
curl "http://localhost/`basename ""`"
rm "/var/www/`basename ""`"
回答by Peer Allan
The CLI version of PHP had been part of the default installation since 4.3 and has to be explicitly turned off when PHP is being built. If you have access to the command line try
PHP 的 CLI 版本自 4.3 以来一直是默认安装的一部分,并且在构建 PHP 时必须明确关闭。如果您有权访问命令行,请尝试
$ php -v
If you don't get a command not found error then you should be ready to go.
如果您没有收到未找到命令的错误,那么您应该准备好了。
To actually run a php file from the command line do this:
要从命令行实际运行 php 文件,请执行以下操作:
$ php -f file.php

