I’m still hosting this site on Bluehost currently. I have considered a number of times moving to something like Digital Ocean, but for now, I’m here. Until then, I’ve worked to make the best of what Bluehost has to offer. As part of that, I wanted to set up a legitimate object cache for the site. Furthermore, I much prefer something like batcache to act as a full page caching system which requires some kind of persistent caching.
There are ways of setting up Memcached on Bluehost installs, but I was tired of fighting the server to get it to do what I want. Instead I decided to go with APC to gain both the opcode cache and the object cache. The only problem with that decision is that Bluehost doesn’t actually have the APC extension available.
I found a nice Bluehost article explaining how to compile a new module for use with PHP, but after following it I immediately ran into issues. PHP starting spitting out errors regarding the module API number. When compiling the module you have to get the source, phpize
it, and then run ./cofigure
before you can run make
and actually compile the module. When you are running something other than the default PHP version, these commands use the wrong APIs, incompatible with the PHP version. This happens because SSH always runs the default version of PHP, which in the current version of Bluehost for me is 5.2. Yuck.
I definitely don’t want to run 5.2, so I have asked Bluehost to run 5.4. It is doing this happily, but my custom APC module is compiled for 5.2. You can still access the 5.4 tools from SSH, but you have to know where they are at. Pushing up a <?php phpinfo();
file showed me that the configuration file was located at /usr/php/54/etc
. This looked promising. And after some digging I found a footnote in another Bluehost article which noted that after changing the PHP version to 5.4, cron jobs needed to be pointed at /usr/php/54/usr/bin/php
. At this point I started piecing it all together.
You can follow the Bluehost help article to compile extensions, but you should know which version of PHP is running, because otherwise installing Bluehost PHP extensions just fails. Make three adjustments to the Bluehost instructions and everything starts working fine.
- Use
/usr/php/54/usr/bin/phpize
(or whatever PHP path you have when viewing yourphp.ini
file tophpize
your extension. - When configuring (
./configure
) use the--with-php-config=/usr/php/54/usr/bin/php-config
flag, again using the correct path for your PHP install - When copying the bluehost pre-compiled extensions back into your extensions folder, copy them from the correct PHP directory such as
cp /usr/php/54/usr/lib64/php/modules/* ~/php/extensions/
Doing those three things and adding the correct configuration to my php.ini
file caused everything to start working.
Snippet
cd ~
mkdir pecl php php/extensions #if not already created
cd pecl
pecl download <packagename>
cd <packagename>
/usr/php/54/usr/bin/phpize
./configure --prefix=$HOME/pecl/<packagedirectory> --with-php-config=/usr/php/54/usr/bin/php-config
make
cp modules/<extensionname>.so ~/php/extensions
cp /usr/php/54/usr/lib64/php/modules/* ~/php/extensions/ #if not already done
# Make sure the extension_dir directive points to the correct ~/php/extensions folder
# Configure /public_html php.ini file for the new extension
July 21, 2016 at 12:29 pm
Hi Luke,
I just read this article. It will be a big help because in the near future I need to install the MongoDB extension and the intl extension.
Currently, my Bluehost PHP Configuration is set to “PHP 5.4”. The Bluehost instructions say “assuming you’re on single php.ini mode”. My questions are:
1) Must I be using “PHP 5.4 (Single php.ini)” to install an extension? Bluehost displays the following warning:
“If you are not familiar with these options, do NOT change them.
This can cause all PHP scripts on your site to stop functioning if misconfigured.”
2) Did you change to “Single php.ini” and if so, did you have to deal with any problems or issues as a result of that change?
Thanks,
Jim