By PixelBoii
I have installed my droplet (ubuntu 18.04) both manually but also tried the one-click apps. Both times the PHP variables are “undefined” but they are defined in another file. I used the following code to include them: require ‘/var/www/developer/steamauth/userInfo.php’;
This works on my other server (Linus @ ExtraVM) so I don’t understand why this doesn’t work. Am I missing any PHP packages?
PLEASE HELP!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @PixelBoii,
I’ll recommend checking the following article - Ubuntu PHP - How to
It will help you properly install PHP and every packages needed on an Ubuntu.
I’m unsure what you mean by PHP variables not working with require though. Can you please give a little bit more information on the matter?
This comment has been deleted
Here are some steps you could take to debug your issue.
Check if file is readable: First, make sure that the file you are trying to require actually exists at the path you are specifying, and that the PHP process has the necessary permissions to read the file.
You can check the existence and permissions of the file by running the following commands in your server terminal:
ls /var/www/developer/steamauth/userInfo.php
stat -c "%a %n" /var/www/developer/steamauth/userInfo.php
The first command lists the file, and the second command shows the file permissions in numeric format (for example, “755” means the owner can read, write, and execute, and others can read and execute).
Turn on Error Reporting: It’s possible that PHP is encountering errors but not displaying them. Ensure that you have error reporting turned on, at least for debugging purposes. You can enable it by adding these lines at the beginning of your PHP script:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
This could help you see if there are any errors occurring that you’re not currently aware of.
Check PHP include path: The PHP include_path configuration setting specifies a list of directories where the require, include, and other file importing functions look for files. You can check your current include path with the following PHP code:
echo get_include_path();
If the directory of your file isn’t listed, you can either use the absolute path (as you’re already doing) or add the necessary directories to your include path.
Debugging require statement: If all else fails, you could try to var_dump the require statement to see if it’s working as expected:
var_dump(require('/var/www/developer/steamauth/userInfo.php'));
This should return bool(true) if the file is imported correctly, or it will return bool(false) if the file is not imported correctly.
Ensure PHP version compatibility: Make sure the PHP version of your droplet is the same as the one on your previous server (where the code was working). PHP syntax and package support can change between versions, so if there’s a significant difference (like PHP 5.x to PHP 7.x), this might be part of the problem. Use php -v in the terminal to check your PHP version.
I hope these suggestions help you identify the issue! If you’re still experiencing problems, could you provide the specific error message you’re seeing? That would help me assist you more effectively.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.