Cpanel and Custom PHP.ini

Cpanel and Custom PHP.ini

Cpanel and Custom PHP.iniI was working on helping someone migrate a WordPress blog to Drupal. It began with a review of of a couple of modules to do the trick including wordpress_import and wordpress_migrate. To sum it up, we went with wordpress_migrate for its handling of attachments and leveraging of existing infrastructure including the migrate module. The problem we ran into was when dealing with attachments. The content created by the import still referenced images from the WP blog rather than grabbing them and saving them as files in the Drupal site and modifying the post image source tags.

After review a few things, it became apparent that the host being used,, correctly has PHP’s fopen function disabled. Kudos to A2Hosting for that. Now, they offer a form that the customer can request this to be enabled with the caveat of security blah blah blah. We didn’t want to enable this permanently, only for the duration of the import. Again, some quick searches regarding Cpanel and custom php.ini’s led to the following solution.

Copy PHP.Ini and Force reading in .htaccess

Make a copy of the existing php.ini that the server uses and place it in your account home directory.

Next, edit the PHP.ini to set allow_url_fopen = On

Finally, edit the .htaccess file in the root of the Drupal installation directory and add the following:

Save. This now allowed our Drupal installation to run php with the directives in our custom php.ini with fopen allowed. The migration took all of maybe 30 seconds and we were done.

When we finished, we just reversed the process so we didn’t stay on our special php.ini and complicate life later down the road with the host.

Hope it helps.