2 years ago

#66249

test-img

plugandplay

php including broke after testing on live environment

I'm having trouble launching my php web-app to the cloud ( shared-hosting )

My web-app works on localhost ( windows environment ) without errors or warnings, but when I try running it on linux ( ubuntu based distro ) - cPanel to be specific including/requiring functions aren't finding the files they were suppose to open.

example Directory Structure

app/
|
|__ index.php
|__ include_me.php
|_(folder1)|
           |_ helloworld.php

in index.php

<?php 

echo "1 2 3..";
require("folder1/helloworld.php");
?>

in helloworld.php

<?php 
# code...
include("include_me.php")
?>

in include_me.php

<?php
echo "Hello, I've been included";
?>

this code was working on localhost ( WINDOWS ) but it breaks on linux environment

I think the reason is the include_path

It's different on windows and Linux:

On Windows

Include_path SET TO => "A:\apps\php\PEAR" 

On Linux

Inlcude_path SET TO => ".:/opt/alt/php72/usr/share/pear"

I've also tried to run it from a VPS to see if the issue is only on Shared hostings, and still didn't work

Ubuntu

Include_path SET TO => ".:/usr/share/php"

How can I fix it ?

UPDATE :

Video that shows the code works at localhost https://streamable.com/wxvv2c

index.php is including helloworld.php into index.php then the helloworld.php code execute on index.php that's why it's finding the file, but if I added ../ in helloworld.php then

when index.php includes helloworld.php now the code inside helloworld.php will run on index.php so now index.php can't find ../include_me.php

php

apache

cpanel

0 Answers

Your Answer

Accepted video resources