-1

I have this code and the same twilio.php library running on both a local (XAMPP) server and a VPS:

checkConnection.php

<?php

    // Include Twilio PHP Library here
    require '/twilio-php/twilio/autoload.php';
    use Twilio\Rest\Client;

    $sid   = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Your Account SID from www.twilio.com/console
    $token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Your Auth Token from www.twilio.com/console

    $client  = new Twilio\Rest\Client($sid, $token);
    $message = $client->messages->create(
      'XXXXXXXXXXXXX', // Text this number
      array(
        'from' => 'XXXXXXXXXXXXX', // From a valid Twilio number
        'body' => 'MySQL down!'
      )
    );

    print $message->sid;

?>

The code runs perfectly locally, but my VPS outputs the following errors:

PHP Warning: require(/twilio-php/twilio/autoload.php): failed to open stream: No such file or directory in /var/www/html/thsportsmassagetherapy.com/mysql-monitor/checkConnection.php on line 4

PHP Fatal error: require(): Failed opening required '/twilio-php/twilio/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in **/var/www/html/thsportsmassagetherapy.com/mysql-monitor/checkConnection.php** on line 4

Locally, the script and twilio libary are located at

C:\xampp\htdocs\mysql-monitor\

On the VPS, they are located at

/var/www/html/thsportsmassagetherapy.com/mysql-monitor/

Is this likely a path error or a problem with my PHP settings?

Callum
  • 315
  • 4
  • 18
  • what are the permissions on autoload.php? if you can browse to the file manually it could be a perm issue. Just first thought... – brad Sep 22 '16 at 17:10
  • `require '/twilio-php/twilio/autoload.php';` so use a full server path then `require '/var/www/html/twilio-php (or whatever folder)....';` just as you mentioned about the VPS thing. – Funk Forty Niner Sep 22 '16 at 17:14
  • Or.. a relative link ` require './twilio-php/twilio/autoload.php'; ` assuming twillio-php is in the same DIR as this script – Duane Lortie Sep 22 '16 at 17:24
  • Possible duplicate of [PHP - Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/php-failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew Sep 22 '16 at 18:23

1 Answers1

0

To fix this problem, set the path to the autoload.php correctly.

For instance, if autoload.php is located in /usr/local/lib/myapp.

require '/usr/local/lib/myapp/autoload.php';

It is also possible to set an include_path.

For example, in your PHP file, you could do.

set_include_path('/usr/local/lib');

Then instead of the above require, you could do

require 'myapp/autoload.php';

Or you can do what I do, which is use an application framework like Symfony that uses composer to manage such things. Even when I don't use Symfony, I still use composer.

Why work so hard when there are tools out there that make this stuff easy?

Halfstop
  • 1,710
  • 17
  • 34
  • To answer your last question, while application frameworks probably make life a lot easier after the initial time investment, that initial setup of the application frameworks and understanding how it works requires a time investment much more than just getting your file to point at the right path. – Mikey Apr 27 '21 at 01:11