【问题标题】:Can't access php files on apache无法访问apache上的php文件
【发布时间】:2013-03-06 06:28:54
【问题描述】:

我在 Ubuntu 10.04 x32 上安装了 Apache、Php、Mysql。安装它们后,我无法访问某些 php 文件。 APM 开启。 以下是一些文件和 .htaccess 来解决问题。 如果您在浏览器上看不到“可以访问”文件,则服务器可能已关闭。

权限:phpinfo.php 644、index.php 600、hello.php 600

[可以访问]

http://222.118.53.30/phpinfo.php
http://222.118.53.30/phpmyadmin

[无法访问]

http://222.118.53.30/index.php
http://222.118.53.30/hello.php

.haccess 正在关注

SetEnv APPLICATION_ENV development



Options -Indexes

Options +FollowSymLinks

DirectoryIndex index.php index.html

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)\?*$ index.php [L,QSA]

#remove www.

#RewriteCond %{HTTPS} off

#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]

#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

#RewriteRule ^(.*\.(png|jpg|jpeg|gif))$ index.php?controller=minify&action=index&file_path=$1&ext=$2 [L,NC]

#RewriteRule ^(.*\.(css|js))$ index.php?controller=minify&action=jscss&file_path=$1&ext=$2 [L,NC]


</IfModule>

ErrorDocument 404 index.php

<ifModule mod_expires.c>

ExpiresActive On

ExpiresDefault "access plus 1 seconds"

ExpiresByType text/html "access plus 1 seconds"

ExpiresByType image/gif "access plus 2592000 seconds"

ExpiresByType image/jpeg "access plus 2592000 seconds"

ExpiresByType image/png "access plus 2592000 seconds"

ExpiresByType text/css "access plus 604800 seconds"

ExpiresByType text/javascript "access plus 216000 seconds"

ExpiresByType application/x-javascript "access plus 216000 seconds"

</ifModule>

<FilesMatch "\.(htaccess|htpasswd|ini|log|sh|inc|bak|cache)$">

Order Allow,Deny

Deny from all

</FilesMatch>

[hello.php]

<?php 
 echo "Hello World";
?>

[index.php]

<?php 

// Define application path
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application/'));

// Define base path
defined('BASE_PATH')
|| define('BASE_PATH', realpath(dirname(__FILE__)));

// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../JO/v.0.9b/'),
realpath(APPLICATION_PATH . '/library/'),
get_include_path(),
)));

require_once 'JO/Application.php';

// Create application, bootstrap, and run
$application = new JO_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/config/application.ini',
isset($argv) ? $argv : null
); 

// Set Routers links
$configs_files = glob(APPLICATION_PATH . '/config/config_*.ini');
if($configs_files) {
foreach($configs_files AS $file) {
    $config = new JO_Config_Ini($file);
    $application->setOptions($config->toArray());
    JO_Registry::set(basename($file, '.ini'), $config->toArray());
}
}

// Set Routers links
$routers_files = glob(APPLICATION_PATH . '/config/routers/*.ini');
if($routers_files) {
foreach($routers_files AS $file) {
    $config = new JO_Config_Ini($file, null, false, true);
    $application->setOptions($config->toArray());
    JO_Registry::set('routers_'.basename($file, '.ini'), $config->toArray());
}
}

//dispatch application
$application->dispatch();



// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
if (!(error_reporting() & $errno)) {
    // This error code is not included in error_reporting
    return;
}

switch ($errno) {
case E_USER_ERROR:
    echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
    echo "  Fatal error on line $errline in file $errfile";
    echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
    echo "Aborting...<br />\n";
    exit(1);
    break;

case E_USER_WARNING:
    echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
    break;

case E_USER_NOTICE:
    echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
    break;

default:
    echo "Unknown error type: [$errno] $errstr<br />\n";
    break;
}

/* Don't execute PHP internal error handler */
return true;
}

你能帮我看看我的配置有什么问题吗?

【问题讨论】:

  • 当您尝试访问这些 URL 时会显示什么消息?
  • 什么都没有显示...可以通过浏览器访问它们。服务器现在还活着。
  • 另外请发index.phphello.php的代码
  • 文件权限可能会导致该问题。你检查index.php的访问权限了吗?

标签: php apache


【解决方案1】:

那些文件显示HTTP 500 Internal server error。这意味着这些文件有一些代码不适用于您的 PHP 版本。您需要查看这些文件中的代码

【讨论】:

  • 如果我将 hello.php 的权限从 600 更改为 644。有用。但我认为它应该使用 600 权限....
  • @SteveLee 600 权限意味着owner read and write 如果你想正常工作,你必须设置权限 655,这意味着公共也可以执行 php 文件
  • 或者网络服务器可以拥有该文件;)但是 644 是常见的用法。
【解决方案2】:

您确定不能访问这些文件吗?因为从这点来看,我可以。我刚刚收到一个内部服务器错误 (500),这可能有很多原因。

最常见的是您的 php 文件中的语法错误。因此,请发布您的 hello.php 的源代码。

【讨论】:

  • 我发布了代码... index.php 代码没有问题,因为它是流行的软件之一。
【解决方案3】:

我测试Htaccess是正确的没有问题。

通过注释这行 htaccess 来测试 php

  RewriteCond %{REQUEST_FILENAME} !-f

  RewriteCond %{REQUEST_FILENAME} !-d

  RewriteRule ^(.*)\?*$ index.php [L,QSA] 

如果hello.php 正常工作,则意味着问题出在索引 php 代码上

如果问题没有解决,意味着索引 php 是正确的,我认为问题来自虚拟主机部分的 httpd.conf

其他一些问题可能会导致此问题,例如权限,(您的 php 文件必须是 655,这意味着公共 readexecutereadexecute by Group,read 和 @ 987654329@所有者)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-02
    • 2014-08-04
    • 2020-12-15
    • 2015-06-07
    • 2018-07-28
    • 2012-01-26
    相关资源
    最近更新 更多