Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install PHP 7 (PHP next generation) on Ubuntu

Tags:

php

ubuntu

How do I install PHP 7 (PHP next generation) on Ubuntu?

I wanted to install PHP 7 on a clean install of Ubuntu to see what issues I would face.

Here’s the official (yet meager guide):

https://wiki.php.net/phpng

like image 252
RyanNerd Avatar asked Jun 22 '15 19:06

RyanNerd


People also ask

What version of PHP does Ubuntu 20.04 use?

Note: Ubuntu 20.04 ships with PHP 7.4 in its upstream repositories. This means that if you attempt to install PHP without a specified version, it will use 7.4. You will want to avoid relying on the default version of PHP because that default version could change depending on where you are running your code.


1 Answers

I did a run through on my own, and thought it would be useful to document what problems I ran into as I went and how I overcame them thus saving others perhaps some pain and suffering.

I did however (after the fact) find this http://jcutrer.com/howto/linux/how-to-compile-php7-on-ubuntu-14-04 which is a much cleaner guide than what I provide below.

From the guide (https://wiki.php.net/phpng):

./buildconf 
mkdir  ~/tmp 
cd ~/tmp
git clone https://git.php.net/repository/php-src.git
cd php-src

So far so good. At this point I started having problems:

./buildconf

Reported that I did not have make installed. The solution was found here: https://askubuntu.com/questions/192645/make-command-not-found

I tried this, but still had problems so I did this:

sudo apt-get purge make  
sudo apt-get install make 

Next problem when I tried ./buildconf again it complained that I did not have autoconfig. Here’s the solution to that:

sudo apt-get install autoconf  

Now finally got to run ./configure command and got this:

configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers. configure: error: bison is required to build PHP/Zend when building a GIT checkout!

Installing Bison also appears to install re2c as well so this fixes both problems:

sudo apt-get install bison    

Config churned along for quite some time and then puked with:

configure: error: xml2-config not found. Please check your libxml2 installation.

Should be an easy fix right? Just run:

sudo apt-get install libxml2

Nope. Not that easy. We already have the latest and greatest for this:

libxml2 is already the newest version.

Okay. Maybe we can solve this like we did make and purge and reinstall:

sudo apt-get purge libxml2 sudo apt-get install libxml2

Nope. Running ./configure barfs on the same error. SO to the rescue:

How to fix error with xml2-config not found when installing PHP from sources?

Aparently we need the development version of this library:

sudo apt-get install libxml2-dev

./configure again and we have progress...a new error:

configure: error: Cannot find OpenSSL's

Learning from our last foray let’s try:

sudo apt-get install openssl-dev

or

sudo apt-get install open-ssl-dev

Nope, Okay let’s do a search for this:

apt-cache search openssl 

Wow, that’s quite a few packages. Let’s narrow it down a bit:

apt-cache search openssl | grep php

Well that gives us a smaller list, but all have php5 in the front and we are doing a php7 (phpng Next Generation build from scratch); will any of these packages work? Off to the interwebs for our solution:

https://serverfault.com/questions/415458/php-error-cannot-find-openssls-evp-h

sudo apt-get install libcurl4-openssl-dev pkg-config

Let’s see if that made ./configure happy (nope, but progress...a new error):

configure: error: Please reinstall the BZip2 distribution

Searching the web again leads us to:

http://zgadzaj.com/how-to-install-php-53-and-52-together-on-ubuntu-1204

which tells us to do this:

sudo apt-get install libbz2-dev

Once again we send a prayer to the ./configure god and...

If configure fails try --with-vpx-dir= configure: error: jpeglib.h not found.

TO THE INTERWEBS!!!

Found this: http://www.omniweb.com/wordpress/?p=1040

sudo apt-get install libjpeg-dev 

Try ./configure again and SURVEY SAYS:

configure: error: png.h not found.

From the same website as above it says to do this:

sudo apt-get install libpng-dev

Try ./configure AGAIN and SURVEY SAYS:

configure error xpm.h not found

I took a stab in the dark and hit the target with:

sudo apt-get install libxpm-dev

Once again praying to the ./configure god and the reply is:

configure: error: freetype-config not found.

The ALL KNOWING Google directs us to the SO god here:

Configure php 5.3 fail with error : freetype.h not found (but libfreetype6-dev is installed)

sudo apt-get install libfreetype6-dev 

By now you have probably recognized the pattern of:

  1. run ./configure

  2. Search the error message on your favorite search engine or directly on SO.

  3. Install the missing component via apt-get.

  4. GOTO 1.

So from here on I am just going to show the error and the apt-get command or other commands that resolve the issue:

configure: error: Unable to locate gmp.h

build php5.3.8 on ubuntu , get error: configure: error: Unable to locate gmp.h

sudo apt-get install libgmp-dev  
sudo apt-get install libgmp3-dev
ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

sudo apt-get install libmcrypt-dev

configure: error: Please reinstall the mysql distribution

http://www.spiration.co.uk/post/1332/install%20PDO_MYSQL%20-%20mysql_config%20and%20header%20files%20problem

sudo apt-get install libmysqlclient15-dev  

configure: error: Cannot find pspell

sudo apt-get install libpspell-dev

configure: error: Can not find recode.h anywhere under /usr / usr/local /usr /opt.

sudo apt-get install librecode-dev

configure: WARNING: unrecognized options: --with-t1lib

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=658248

No solution. Appears to be a regression bug. Workaround is to remove the --with-t1lib from the configuration options. I think this may apply to Windows builds only, but I’m not certain.

configure: WARNING: unrecognized options: --with-my-sql

No solution. Work around is to remove the --with-mysql switch from the configuration options. Since we are including the pdo-mysql this is probably not an issue anyway.

FINALLY We get to actually build PHP7 with this command (I suggest you make yourself a cup of coffee now as this takes some time) :

make

Use the command sudo make install to actually install our php build:

sudo make install 

To check if all is well and we have the right version execute this in the terminal:

cd $HOME/tmp/usr/bin
./php -v

PHP 7.0.0-dev (cli) (built: Jun 22 2015 18:11:13) Copyright (c) 1997-2015 The PHP Group Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies

like image 154
RyanNerd Avatar answered Sep 25 '22 02:09

RyanNerd