简体   繁体   English

PHP脚本导致500内部服务器错误

[英]php script causing 500 Internal Server Error

I am test a simple php script and got some problem. 我正在测试一个简单的PHP脚本,却遇到了一些问题。 My php is as follows: 我的PHP如下:

#!/usr/local/bin/php

<html><head><title>PHP Test</title></head>
<body>
<?php print( "Hello World<br />"); ?>
</body></html>

In the same folder, I have a htaccess file as 在同一文件夹中,我有一个htaccess文件,

AddHandler cgi-script .php

Also, I run these command to ensure the permission is correct. 另外,我运行这些命令以确保权限正确。

chmod 711 hello.php
chmod 644 htaccess

However, I got a "500 Internal Server Error" as result when I tried to reach the page. 但是,当我尝试访问该页面时,结果为“ 500 Internal Server Error”。 I am totally new to php. 我对php完全陌生。 Could anyone help me out here? 有人可以帮我吗?

PHP files are not run in the same way as CGI scripts. PHP文件的运行方式与CGI脚本的运行方式不同。 CGI scripts are executables and need to be able to run from the commandline by themselves. CGI脚本是可执行文件,需要自己能够从命令行运行。 PHP files need to be run through an interpreter, and typically can't use the #! PHP文件需要通过解释器运行,并且通常不能使用#! pragma at the top of their files to invoke an interpreter like Perl or Ruby or Python (etc) scripts can. 文件顶部的编译指示可调用Perl或Ruby或Python(etc)脚本之类的解释器。

I've usually seen the following: 我通常看到以下内容:

AddHandler php5-script .php

which tells Apache to run the PHP file through the PHP interpreter. 告诉Apache通过PHP解释器运行PHP文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM