0

so on my Ubuntu 16.04 server, i have a couple of .php files in my /var/www/html/ directory which i do regular php stuff such as data retrieval, user login... etc. I wanted to implement a mail verification service in which i wanted to use the gmail smtp service, so i installed mail through pear by the following command:

pear install --alldeps Mail

After following the steps in this website, i restarted apache2 and now my php require_once isn't working. I tried include_path which also didn't work.

I uninstalled mail by pear uninstall mail, deleted php and reinstalling it hoping it would get the files back as it was but no luck, does anyone know what happened and how can i fix it?

sample code: require_once 'DbOperation.php';

The above code worked and i want it to work as it is the key to my entire php api, please dont suggest a workaround. Any help is appreciated.

Community
  • 1
  • 1
Crashie
  • 19
  • 6
  • What was the `include_path` before you installed `Mail`? What is it now? – Dave May 01 '19 at 15:57
  • it wasn't include_path before, it was require_once, i just tried include_path to test it after it started failing – Crashie May 01 '19 at 15:58
  • @Dave and right now its nothing because its not working... so i left it as require_once hoping i can fix it and leave the php files as is – Crashie May 01 '19 at 16:04
  • The default include path in the sample ini files includes `.:` for Linux. Is the code that uses `require_once` in the `/var/www/html/` directory and is `DbOperation.php` in that directory too? – Dave May 01 '19 at 16:08
  • @Dave yes, all .php files in the /var/www/html directory, it used to work before by calling the file as is without directory separators, the sample code i provided in my question was valid, and used to work like a charm. – Crashie May 01 '19 at 16:10
  • @Dave can installing mail alter the php config in anyway that would make a function not working? – Crashie May 01 '19 at 16:11
  • Not that I've ever heard of. Exactly what is the error you are getting? – Dave May 01 '19 at 16:11
  • I don't know, im echoing a random sentence before and after the require_once function, when running, only the first echo is working, its not reaching the second echo, like its a fatal error, is there a way i can print my error? – Crashie May 01 '19 at 16:13
  • Make sure all error reporting is enabled. `ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL);`. Could `DbOperation.php` be failing now for some reason? – Dave May 01 '19 at 16:15
  • @Dave oh wow it actually was failing due to a missing ")"... thats a rookie mistake :'( , you're actually a life savior mate, please post your answer officially so i can mark as solved, thank you so much – Crashie May 01 '19 at 16:22
  • @Dave I actually feel embarrassed now, forgive me xD – Crashie May 01 '19 at 16:23
  • Was it in the require code? – Dave May 01 '19 at 16:23
  • @Dave it was in the DbOperation.php, like you said, it was failing, but i dont understand, this syntax error was a small line in a function (inside DbOperation.php) that was never going to be called by the original file, does it detect it too? – Crashie May 01 '19 at 16:24
  • Syntax errors will never get past the parser. It doesn't matter if it is in a function. You'll probably want to get in the habit of using the `-l` option of PHP to do a quick lint check any time you make updates to something. In the editor I use it's a key sequence that I use frequently without even thinking about it. – Dave May 01 '19 at 16:27
  • @Dave hey since you're a php expert, Im on a remote server and writing php files is a bit hard when im constantly uploading the updated .php file via ssh, is there a text editor i can use that will connect to my server and update stuff in realtime? – Crashie May 01 '19 at 16:30
  • Short answer, don't do that. Install everything you need locally and develop locally only deploying to the serve when it's tested and working correctly. For Linux the LAMP stack gives you everything you should need. If you really want to learn how it all works together install each piece manually (PHP, Apache and MySQL or MariaDB). – Dave May 01 '19 at 16:34
  • If an answer solved your problem, consider accepting the answer. [Here's how](https://meta.stackexchange.com/q/5234/379718), then return here and do the same with the tick/checkmark till it turns green. This informs the community, a solution was found. Otherwise, others may think the question is still open and may want to post (more) answers. You'll earn points and others will be encouraged to help you. Welcome to Stack! – Dave May 01 '19 at 17:24

2 Answers2

0

Dave's answer solved my problem by checking the filename in require_once('filename'), which had a missing ")"... rookie mistake, i know.

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

put this in your php file to display errors to find out what your problem is. Thank you Dave!

Crashie
  • 19
  • 6
0

Nothing in what you've tried should be causing require or require_once to suddenly stop working. Make sure you have all error reporting turned on:

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

With error reporting enabled you may spot a problem with something else (like the code that is being required).

Dave
  • 5,108
  • 16
  • 30
  • 40