如何在linux控制台运行php程序,就像运行shell脚本一样

2025-04-25 16:04:01
推荐回答(1个)
回答1:

如果只是单独测试一个PHP文件,可以不用建立站点,不用配置apache的虚拟配置文件,使用php的命令行模式可以直接调式:

如测试:/home/usrname/mysite/test.php


function greeting(){

print "this page is writen in the Vi!";
echo "
";
echo "another web page!";
echo "
";
print "this is edited by Vim!";
echo "
";

}
greeting();
?>

可以使用下列命令:

php -f /home/usrname/mysite/test.php

可以在终端下看到类似的输出:

this page is writen in the Vi!
another web page!
this is edited by Vim!