Jump to content

PHP not working in subdirectories on OpenShift


Go to solution Solved by Ch0cu3r,

Recommended Posts

I am working on OpenShift and my PHP files in my sub directories are not working when pushed to the server. They work through localhost when using XAMPP so I dont know what is going wrong. Any help would be great.

 

I have a link from my main index.php that links to the one in the subdir but when hosted it just pulls up a blank page. I am not sure if this as something to do with PHP permissions or what.

 

/index.php

/racedata/index.php

No, idea.

 

Usually a blank page means php has encountered an unrecoverable error. Either check your servers error log or add the following two lines at the top of your script to force php to display errors

ini_set('display_errors', 1);
error_reporting(E_ALL);

Post the error messages in in full and the corresponding code.

No, idea.

 

Usually a blank page means php has encountered an unrecoverable error. Either check your servers error log or add the following two lines at the top of your script to force php to display errors

ini_set('display_errors', 1);
error_reporting(E_ALL);

Post the error messages in in full and the corresponding code.

The error is

Warning: include(/resources/layout.php): failed to open stream: No such file or directory in /var/lib/openshift/534f43c45973ca6597000154/app-root/runtime/repo/racedata/index.php on line 13 Warning: include(): Failed opening '/resources/layout.php' for inclusion (include_path='.:/var/lib/openshift/534f43c45973ca6597000154/app-root/runtime/repo/lib:/var/lib/openshift/534f43c45973ca6597000154/app-root/runtime/repo/libs:/var/lib/openshift/534f43c45973ca6597000154/app-root/runtime/repo/libraries:/var/lib/openshift/534f43c45973ca6597000154/app-root/runtime/repo/src:/var/lib/openshift/534f43c45973ca6597000154/app-root/runtime/repo/vendor:/var/lib/openshift/534f43c45973ca6597000154/app-root/runtime/repo/vendors:/var/lib/openshift/534f43c45973ca6597000154/php/phplib/pear/pear/php:/usr/share/pear') in /var/lib/openshift/534f43c45973ca6597000154/app-root/runtime/repo/racedata/index.php on line 13

Its sayins /racedata/resources/layour.php isnt valid...

 

The code is:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL); 
// connect to data base
//include '/resources/connectdb.php';

// Set page vars
$pagetitle = "Front Page!!";
$navbar = "/resources/navbar.php";
$page = "main.php";
$footer = "/resources/footer.php";
// Load complete layout
include "/resources/layout.php";
?>
Edited by rukamir
  • Solution

The problem is most likely to do with the forward slash ( / ) at the start of the file paths.

 

Having the forward slash at the start of file paths does not mean the root of your websites document root, but the root of the servers storage device. This is normal strickly off limits to you, unless you own the server.

 

Try replacing the / with $_SERVER['DOCUMENT_ROOT'] instead eg

define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT']);

$pagetitle = "Front Page!!";
$navbar = SITE_ROOT . "/resources/navbar.php";
$page = "main.php";
$footer = SITE_ROOT . "/resources/footer.php";

// Load complete layout
include SITE_ROOT . '/resources/layout.php/';

Because we now prepend the file paths with the document root path, PHP will now try to load the files from there.

You were right about it not liking the '/'. I removed them from the beginning of all and it started working. Thanks for letting me know about DOCUMENT_ROOT and pointing me in the right direction!

// Set page vars
$pagetitle = "Front Page!!";
$navbar = "resources/navbar.php";
$page = "main.php";
$footer = "resources/footer.php";

// Load complete layout
include  "resources/layout.php";
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.