2 years ago by: matt
I work out of /usr/local/src for anything I'm compiling from source so adjust to suit your own setup.
Grab yourself the latest version available on the php.net website using wget in the current directory.
Once you have finished downloading you need to gunzip and untar:
sudo gunzip php-7.0.1.tar.gz
sudo tar -xvf php-7.0.1.tar
To keep track of what configuration I compiled software in I use a small configure.sh script in which I keep all of the configure commands. That way later on I can just open up configure.sh to see/change configuration instead of having to look through build history.
The configuration I need for this setup is the following:
sudo ./configure \ --enable-fpm \ --prefix=/usr/local/php-7 \ --with-zlib \ --enable-shmop \ --enable-sysvsem \ --enable-sysvshm \ --enable-sysvmsg \ --enable-mbstring \ --with-openssl \ --enable-huge-code-pages \
I have that saved into configure.sh which is kept inside the php-src directory.
Make sure its executable:
sudo chmod +x configure.sh
If you are seeing errors at this point it is most likely due to missing libraries. Most of these can be fixed by sudo apt-get install LIBRARY-dev but a quick google search will confirm you are installing the right lib.
Once configure has finished with no errors you can go ahead and build/install:
sudo make install
You now have PHP 7 installed into the /usr/local/php-7 path as defined with the --prefix tag during configure. The last thing you will need is to copy the default .ini file from the src into the correct location.
sudo cp php.ini-development /usr/local/php-7/lib/php.ini
In my case I am running php-fpm so I need to also copy the relevant files over:
sudo cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
sudo chmod +x /etc/init.d/php-fpm
The default php-fpm.conf files are kept in the etc/ directory within the install location:
sudo cp php-fpm.conf.default php-fpm.conf
sudo cp www.conf.default www.conf
I run the process as www-data, to change the user of the process open up www.conf and find the user/group lines and change as needed. In my case:
user = www-data
group = www-data
You should now be able to start/stop the process by running:
sudo /etc/init.d/php-fpm start
sudo /etc/init.d/php-fpm stop
I also like to have easy access to the php executable so I create a link to it in my bin directory:
sudo ln -s /usr/local/php-7/bin/php /usr/local/bin/php
If you now run php -v in the terminal it should output the correct version information for you.