Skip to content

Compiling PHP 7 on Bluehost Shared Accounts

UPDATE: There is now an easier way to change your PHP version. Just login to your Bluehost control panel and go to “PHP Config”, select PHP 7 and click “Save Changes”.

UPDATE: This is no longer required to use PHP 7 as Bluehost has put PHP 7 on their servers. You can now put one of these directives in your .htaccess file depending on how you want PHP configured. If you don’t know what these do, just go with the first one.

AddHandler application/x-httpd-php70 .php for regular PHP
AddHandler application/x-httpd-php70f .php for FastCGI
AddHandler application/x-httpd-php70s .php for Single ini

I’ve been hearing about all these speed increases from lower PHP versions to PHP 7, so I thought I’d see if I could get it compiled on my Bluehost shared account. I was able to get it compiled and running, but I haven’t done any speed comparisons yet. I’ll just show you how I got it compiled for now. To follow this, you have to have SSH access enabled. You can find instructions for that here.

Once you’re ssh’d into your account, go to your local bin directory. and download the PHP 7 tarball.

$ cd ~/bin
$ wget http://us3.php.net/get/php-7.0.0.tar.gz/from/this/mirror

Then unpack the .tar.gz and move into the PHP 7 directory.

$ mv mirror php7.tar.gz
$ tar -xvzf php7.tar.gz
$ cd php-7.0.0

Here’s where we configure, make, and make install PHP 7.

$ ./configure --with-config-file-path=/homedir/username/etc/php/ --with-config-file-scan-dir=/homedir/username/etc/php/conf.d/ --enable-mysqlnd --with-curl --with-openssl --with-readline --with-recode --with-zlib --with-mysqli --prefix=/homedir/username/bin/ --enable-mbstring --with-gd
$ make -j"$(nproc)"
$ make install

Note: Make sure to change “/homedir/username/” to your homedir and username. You can get this with pwd. Additionally, this is compiled with only a few options. You can compile with whatever options you’d like.

Now that we have PHP 7 compiled and installed, test the binary. Make a PHP file with the following:

<?php
echo "ok\n";
?>

Then run it.

$ ~/bin/bin/php filename.php

You should see the output “ok”. The final step is to make .htaccess run your PHP files with PHP 7. Change to whatever directory you want PHP 7 to run in and make a symlink to your php binary.

$ cd ~/public_html
$ ln ~/bin/bin/php-cgi cgi-bin/php

Then drop the following in your .htaccess file:

<FilesMatch "\.php$">
Action application/x-httpd-php7 /cgi-bin/php
SetHandler application/x-httpd-php7
</FilesMatch>

And there you go. Whatever site is in that directory is now running on PHP 7.

A few notes. This isn’t exactly a great way to get on PHP 7, I’m just showing that it’s possible. If you do decide to do this, I’m not responsible for your actions. Use this with caution.

Published inphp

5 Comments

  1. TikiWIki Documentaion has been updated to allow people to run Tiki16 with composer on bluehost shared environments based on this post.

    • garthmortensen garthmortensen

      You’ll want to update that post with the update I just made. Compiling from source is no longer required.

  2. Is there a better way to get php 7 working on bluehost?

    If so, why not mention it?

    • garthmortensen garthmortensen

      At the time of this writing, there was no better way. However, in the recent weeks, Bluehost put PHP 7 on their servers. You can now put one of these into your .htaccess file depending on how you want PHP configured.
      AddHandler application/x-httpd-php70 .php for regular PHP
      AddHandler application/x-httpd-php70f .php for FastCGI
      AddHandler application/x-httpd-php70s .php for Single PHP

      I will update the post to reflect this.

Comments are closed.