Reputation: 790
I write social network with MVC architecture it work localhost (wampserver) correctly but when i upload it on real host i get this error in http://example.com/
Warning: require_once(views/index/index.php): failed to open stream: No such file or directory in /home3/farazenc/public_html/fb/views/index.php on line 14
Fatal error: require_once(): Failed opening required 'views/index/index.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home3/farazenc/public_html/fb/views/index.php on line 14
and my method not work for example when i go http://example.com/index/register must show register form but show 404
my main file: .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
index.php
<?php
session_start();
require_once './config.php';
require_once './lib/database.php';
require_once ('./lib/function.php');
$connect = database::connect();
function __autoload($classname) {
$directrey = array('controllers', 'models');
for ($i = 0; $i < sizeof($directrey); $i++) {
if (file_exists($directrey[$i] . '/' . $classname . '.php')) {
require_once ($directrey[$i] . '/' . $classname . '.php');
}
}
}
if (isset($_GET['url'])) {
$url = $_GET['url'];
$split = preg_split('/[\/\\\]/', $url);
if (sizeof($split) == 1) {
if (!file_exists('controllers/' . $split[0] . 'Controller.php')) {
require_once ('./controllers/CheckPage.php');
CheckPageController::check($split[0]);
} else {
$classname = $split[0] . 'Controller';
$Controller = new $classname();
}
} elseif (sizeof($split) == 2) {
if (file_exists('controllers/' . $split[0] . 'Controller.php')) {
if (empty($split[1])) {
$classname = $split[0] . 'Controller';
$Controller = new $classname();
} else {
$classname = $split[0] . 'Controller';
$Controller = new $classname();
if (method_exists($Controller, $split[1])) {
$Controller->$split[1]();
} else {
require_once ('./views/404.php');
}
}
} else {
require_once ('./views/404.php');
}
}
} else {
require_once ('./controllers/IndexController.php');
$IndexController = new IndexController();
}
if (isset($_POST['Action'])) {
$ajax = new Ajax();
$ajax->$_POST['Action']();
}
Controller.php
<?php
abstract class Controller {
public function render($file) {
if (!isset($_POST['Action'])) {
global $split;
$d = empty($split) ? 'index' : $split[0];
$content = "views/$d/$file.php";
require_once ('views/index.php');
}
}
public function user_views($file){
if (isset($_SESSION['user'])){
require_once ('views/user/'.$file.'.php');
} else {
require_once ('views/index.php');
}
}
public function admin_views($file){
if (isset($_SESSION['admin'])){
global $split;
$d = empty($split) ? 'index' : $split[0];
$content = "views/$d/$file.php";
require_once ("views/admin/admin.php");
} else {
require_once ('views/admin/login.php');
}
}
}
IndexController.php
class IndexController extends Controller {
public function __construct() {
global $split;
if (empty($split[1])) {
$this->render('index');
}
}
public function register() {
$this->render('register');
}
}
views/index.php:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>social network</title>
<link href="<?php echo URL ?>/css/style.css" rel="stylesheet">
<script type="text/javascript" src="<?php echo URL ?>/js/ajax.js"></script>
<script type="text/javascript" src="<?php echo URL ?>/js/jquery.js"></script>
</head>
<body>
<div style="width:1000px;height:650px;margin:50px auto;">
<div id="content">
<?php
require_once($content);
?>
</div>
<div id="ads" style="margin-right:15px;">
<img src="<?php echo URL ?>/images/ads-120.jpg">
<img src="<?php echo URL ?>/images/ads-120.jpg">
</div>
</div>
</body>
</html>
what's the problem and how can i fix it ?
Upvotes: 3
Views: 188
Reputation: 146
I had similar problem in the past. If file permission is correct (755/644), i advice you to check SELinux (for RHEL/CentOS etc.). SELinux by default configured to permit httpd to work with files in /var/www/html directory but not outside this directory.
If such software working (try "sestatus" command), you can disable it by opening SELinux config file (usually /etc/selinux/config) and change line:
SELINUX=enforcing
to:
SELINUX=disabled
and then reboot system.
Afted that "sestatus" command must show something like that:
SELinux status: disabled
and now test you code again (but make sure you activate SELinux after this tests). if it helps, you just need to config it accordingly by using command:
$ chcon -R --type=httpd_sys_content_t /path_to_document_root_of_you_great_site
or more permanent solution (better way):
$ semanage fcontext -a -t httpd_sys_content_t '/path_to_document_root_of_you_great_site(/.*)?'
$ restorecon -R -v /path_to_document_root_of_you_great_site
if you need that httpd can change files use "httpd_sys_rw_content_t" instead of "httpd_sys_content_t"
P.S. I'm apologize for my English
Reference:
Upvotes: 1