Enabling file_get_contents() and fopen() With Remote URL’s on MediaTemple

After our recent transition to MediaTemple, we realized that our homepage wasn’t being updated with our latest Twitter posts. As it turns out, the server has the ability to access remote files disabled by default, which is a good thing to prevent Remote File Injection attacks, but a bad thing if you want your Twitter account to update your homepage ;).

So, to fix this, you’ll need to re-enable it in your php.ini file. If you’re using the (gs) plan, you’ll want to FTP into your domain, go to the root folder, go into the etc folder, and add a file named php.ini with the following contents:

allow_url_fopen = On

This will let file_get_contents() and fopen() have the ability to accept URL’s as an argument.

5 Responses to “Enabling file_get_contents() and fopen() With Remote URL’s on MediaTemple”

  1. Thank you for sharing this with the community!

    Scott DeSmet
    (mt) Media Temple

    Reply
  2. thanks! worked perfectly on a client site hosted with MT.

    Reply
  3. Michael Pelz-Sheman

    This isn’t working for me for a PHP script run as a cron job. I also tried setting the option in my script using ini_set, to no avail. Still getting “Warning: fopen(): URL file-access is disabled in the server configuration” when I run the script. Any suggestions?

    Reply
    • MT might have a separate php.ini for CLI vs httpd executed PHP (I’ve seen some distro’s do this).

      So, you might want to try having your CRON execute your script by doing a “wget http://URL“, instead of a “php /path/to/file”.

      Otherwise, you could always edit the script and switch to using cURL instead of fopen.

      Reply

Comment

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>