php 命令行不执行 php 文件
php command line not executing the php file
我在 Debian 10 上使用 Php 7.3。它可以很好地安装各种客户端(Drupal 等)。
但是,对于目录中的简单文件,例如 /var/www/some_directory/index.php
,该文件无法执行并显示 PHP 代码(some_directory
不是 */public_html
) .
当我简单地使用命令行时:
php -f /var/www/some_directory/index.php
我得到同样的错误,这使我认为它与 Apache2 配置无关。
index.php 文件的内容相当简单:
<html>
<body>
You have been redirected.
<php?
echo "This is a test";
?>
</body>
</html>
更让我困惑的是,如果我输入:
php <<< '<?php echo "This is a test";?>'
我得到了预期的行为。
到底发生了什么事?有人可以帮忙吗?
.htaccess 就在这一行的下方。它是 Drupal .htaccess 的蹩脚副本(希望这会修复错误)。
这是文件。它是 drupal 目录中包含的 .htaccess 文件的蹩脚副本(经过改编)(我希望这将是一个快速修复)。
<FilesMatch "\.(engine|inc|install|make|module|profile|po|sh|.*sql|theme|twig|t\
pl(\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\.(?!well-known).*|En\
tries.*|Repository|Root|Tag|Template|composer\.(json|lock)|web\.config)$|^#.*#$\
|\.php(~|\.sw[op]|\.bak|\.orig|\.save)$">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
</IfModule>
</FilesMatch>
Options -Indexes
DirectoryIndex index.php index.html index.htm
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
<IfModule mod_php5.c>
php_value assert.active 0
php_flag session.auto_start off
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_flag mbstring.encoding_translation off
php_value always_populate_raw_post_data -1
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A1209600
<FilesMatch \.php$>
ExpiresActive Off
</FilesMatch>
</IfModule>
这是 apache.conf 文件:
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
有错字,试试看
<html>
<body>
You have been redirected.
<?php
echo "This is a test";
?>
</body>
</html>
或者您可以将它与 shebang 一起使用
#!/usr/bin/env php
<html>
<body>
You have been redirected.
<?php
echo "This is a test";
?>
</body>
</html>
我在 Debian 10 上使用 Php 7.3。它可以很好地安装各种客户端(Drupal 等)。
但是,对于目录中的简单文件,例如 /var/www/some_directory/index.php
,该文件无法执行并显示 PHP 代码(some_directory
不是 */public_html
) .
当我简单地使用命令行时:
php -f /var/www/some_directory/index.php
我得到同样的错误,这使我认为它与 Apache2 配置无关。
index.php 文件的内容相当简单:
<html>
<body>
You have been redirected.
<php?
echo "This is a test";
?>
</body>
</html>
更让我困惑的是,如果我输入:
php <<< '<?php echo "This is a test";?>'
我得到了预期的行为。
到底发生了什么事?有人可以帮忙吗?
.htaccess 就在这一行的下方。它是 Drupal .htaccess 的蹩脚副本(希望这会修复错误)。
这是文件。它是 drupal 目录中包含的 .htaccess 文件的蹩脚副本(经过改编)(我希望这将是一个快速修复)。
<FilesMatch "\.(engine|inc|install|make|module|profile|po|sh|.*sql|theme|twig|t\
pl(\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\.(?!well-known).*|En\
tries.*|Repository|Root|Tag|Template|composer\.(json|lock)|web\.config)$|^#.*#$\
|\.php(~|\.sw[op]|\.bak|\.orig|\.save)$">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
</IfModule>
</FilesMatch>
Options -Indexes
DirectoryIndex index.php index.html index.htm
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
<IfModule mod_php5.c>
php_value assert.active 0
php_flag session.auto_start off
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_flag mbstring.encoding_translation off
php_value always_populate_raw_post_data -1
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A1209600
<FilesMatch \.php$>
ExpiresActive Off
</FilesMatch>
</IfModule>
这是 apache.conf 文件:
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
有错字,试试看
<html>
<body>
You have been redirected.
<?php
echo "This is a test";
?>
</body>
</html>
或者您可以将它与 shebang 一起使用
#!/usr/bin/env php
<html>
<body>
You have been redirected.
<?php
echo "This is a test";
?>
</body>
</html>