Skip to content
Advertisement

Why doesn’t PHP include work on my Raspberry Pi?

So I’m very new to Linux and I just bought a Raspberry Pi to serve as my webserver and I noticed the following lines, with the location var/www/mysite/index.php, doesn’t work properly:

echo "Hello1"; // Is shown on page
include($_SERVER["DOCUMENT_ROOT"] . "/mysite/config.php"); // Is never run it seems
echo "Hello2"; // Is never shown on page

I don’t even get any errors or warnings, just a blank page showing “Hello1”, even though I have turned error_reporting and display_error on in the php.ini file. It’s like the script just dies just as it reaches the include line. My application works fine on my windows machine I might add. And yes, document root is correct (/var/www). I guess nothing is wrong with the actual code but something elementary I’ve missed/don’t know.

Any ideas?

Advertisement

Answer

Try to add a backslash after the document root inside your apache config file

From

DocumentRoot "/var/www"

To

DocumentRoot "/var/www/"

OR

Add a slash before “mysite…”

echo "Hello1"; // Is shown on page
include($_SERVER["DOCUMENT_ROOT"] . "/mysite/config.php"); // Is never run it seems
echo "Hello2"; // Is never shown on page

If that doesn’t work, run the following command to check for any errors:

tail -f /var/log/apache2/error.log
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement