In my last post Compiling PHP 7 on CentOS I showed how to compile PHP 7 on CentOS. In this post I will use the basis of that post and transfer the instructions for Ubuntu Linux. This will be a truncated example so if you want the details please refer to that post. This post was also inspired by Lorna Mitchell in her post http://www.lornajane.net/posts/2016/php-7-0-and-5-6-on-ubuntu which she shows how to add ppa repository for multiple php versions, though this a good and quick way, compiling your own PHP you can compile different versions and run these at the same without having to switch and also it is good the learn to compile software ourselves as this gives us control how it is compiled and installed, it is relatively quick as this once learned can be done in 10 minutes and if you write a bash script can be automated too.

I am using Ubuntu 16.04 which is now using systemd instead of init.d to start services so this is what I will be showing you setting up PHP-FPM in systemd so it will start automatically when the system starts.

so without further ado we need some dependencies installed I will be configuring PHP the same as my last post so, alter this according to your needs

next download the PHP source code from Github

now make the target build directory

charge into the source code directory

you have to now checkout the latest stable code, at the time of writing this it was 7.0.6 so I would do

Once that has done we need to configure and build PHP with ( alter this according to your needs)

For more details what these mean see Compiling PHP 7 on CentOS. Next we will want to install the config files into our directory.

Make the module ini file

And put this in it

now press ‘Ctrl o’ and ‘Ctrl x’ to save and exit file. Next we have to configure the fpm con files so

now we need to tell fpm to use unix socket and which user to run under the default user is ‘www-data’ so if you are ok with that then you can leave it, my example I will change the defaults so:

and changes these values my user is ‘ubuntu’, but use the user your php scripts run under.

Don’t forget to make the directory for the socket file

Because I like to have check to config file before starting and restarting the service we need to add a couple of files for this. First make the directory for the temp file, (these scripts were taken from the deb and adjusted for my setup)

Then make a file in this directory and add some content to it by

and add this to it

now press ‘Ctrl o’ and ‘Ctrl x’ to save and exit file. Now by the same procedure we make the check conf file

and add this to it

Save and exit the file then make it executable by

Now we want to make the systemd file by

and add this to it

save and exit the file and install the service by

And if all is done right we should be able to start the service with

so that should be it, hopefully I didn’t miss anything

Let me know in the comments. Happy PHPing!

  • Lorna Mitchell

    Probably worth mentioning that the default PHP version on Ubuntu 16.04 is PHP 7 so anyone happy with a standard setup could consider installing via apt.

  • holly chen

    /user/local/php7/lib/tempfiles.d
    should be
    /usr/local/php7/lib/tmpfiles.d

  • holly chen

    according to your /usr/local/php7/etc/php-fpm.d/www.conf
    “d /run/php 0755 www-data www-data – -” should be “d /run/php 0755 ubuntu ubuntu – -“

  • Remus Elf

    I also have an Amazon Ubuntu 16.04 instance, and I can’t overcome the .configure level. I get this error and I have openssl installed.
    configure: error: Cannot find OpenSSL’s