Skip to content

Instantly share code, notes, and snippets.

@tronsha
Last active October 13, 2023 00:13
Show Gist options
  • Save tronsha/b471dd6d73dc8ebae242 to your computer and use it in GitHub Desktop.
Save tronsha/b471dd6d73dc8ebae242 to your computer and use it in GitHub Desktop.
Install PHP7 to Ubuntu
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
apt-get update
apt-get install -y git-core autoconf bison libxml2-dev libbz2-dev libmcrypt-dev libcurl4-openssl-dev libltdl-dev libpng-dev libpspell-dev libreadline-dev make
mkdir -p /etc/php7/conf.d
mkdir -p /etc/php7/cli/conf.d
mkdir /usr/local/php7
cd /tmp
git clone https://github.com/php/php-src.git --depth=1
cd php-src
./buildconf
./configure --prefix=/usr/local/php7 --enable-bcmath --with-bz2 --enable-calendar --enable-exif --enable-dba --enable-ftp --with-gettext --with-gd --enable-mbstring --with-mcrypt --with-mhash --enable-mysqlnd --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --enable-pcntl --with-pspell --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-zlib --enable-zip --with-readline --with-curl --with-config-file-path=/etc/php7/cli --with-config-file-scan-dir=/etc/php7/cli/conf.d
make
make test
make install
@k0pernikus
Copy link

The gist is failing for me on Ubuntu14.04:

PASS Multipart Form POST Data, incorrect content length [sapi/tests/test007.phpt] 
=====================================================================
TIME END 2015-12-04 18:15:49

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :   22
Exts tested     :   53
---------------------------------------------------------------------

Number of tests : 14289             11536
Tests skipped   : 2753 ( 19.3%) --------
Tests warned    :    3 (  0.0%) (  0.0%)
Tests failed    :    6 (  0.0%) (  0.1%)
Expected fail   :   36 (  0.3%) (  0.3%)
Tests passed    : 11491 ( 80.4%) ( 99.6%)
---------------------------------------------------------------------
Time taken      :  590 seconds
=====================================================================

=====================================================================
EXPECTED FAILED TEST SUMMARY
---------------------------------------------------------------------
Test open_basedir configuration [tests/security/open_basedir_linkinfo.phpt]  XFAIL REASON: BUG: open_basedir cannot delete symlink to prohibited file. See also
bugs 48111 and 52176.
Inconsistencies when accessing protected members [Zend/tests/access_modifiers_008.phpt]  XFAIL REASON: Discussion: http://marc.info/?l=php-internals&m=120221184420957&w=2
Inconsistencies when accessing protected members - 2 [Zend/tests/access_modifiers_009.phpt]  XFAIL REASON: Discussion: http://marc.info/?l=php-internals&m=120221184420957&w=2
Bug #48770 (call_user_func_array() fails to call parent from inheriting class) [Zend/tests/bug48770.phpt]  XFAIL REASON: See Bug #48770
Bug #48770 (call_user_func_array() fails to call parent from inheriting class) [Zend/tests/bug48770_2.phpt]  XFAIL REASON: See Bug #48770
Bug #48770 (call_user_func_array() fails to call parent from inheriting class) [Zend/tests/bug48770_3.phpt]  XFAIL REASON: See Bug #48770
Initial value of static var in method depends on the include time of the class definition [Zend/tests/method_static_var.phpt]  XFAIL REASON: Maybe not a bug
Bug #70228 (memleak if return in finally block) [Zend/tests/try/bug70228.phpt]  XFAIL REASON: See https://bugs.php.net/bug.php?id=70228
DateTime::add() -- fall type2 type3 [ext/date/tests/DateTime_add-fall-type2-type3.phpt]  XFAIL REASON: Various bugs exist
DateTime::add() -- fall type3 type2 [ext/date/tests/DateTime_add-fall-type3-type2.phpt]  XFAIL REASON: Various bugs exist
DateTime::add() -- fall type3 type3 [ext/date/tests/DateTime_add-fall-type3-type3.phpt]  XFAIL REASON: Various bugs exist
DateTime::add() -- spring type2 type3 [ext/date/tests/DateTime_add-spring-type2-type3.phpt]  XFAIL REASON: Various bugs exist
DateTime::add() -- spring type3 type2 [ext/date/tests/DateTime_add-spring-type3-type2.phpt]  XFAIL REASON: Various bugs exist
DateTime::add() -- spring type3 type3 [ext/date/tests/DateTime_add-spring-type3-type3.phpt]  XFAIL REASON: Various bugs exist
DateTime::diff() -- fall type2 type3 [ext/date/tests/DateTime_diff-fall-type2-type3.phpt]  XFAIL REASON: Various bugs exist
DateTime::diff() -- fall type3 type2 [ext/date/tests/DateTime_diff-fall-type3-type2.phpt]  XFAIL REASON: Various bugs exist
DateTime::diff() -- fall type3 type3 [ext/date/tests/DateTime_diff-fall-type3-type3.phpt]  XFAIL REASON: Various bugs exist
DateTime::diff() -- spring type2 type3 [ext/date/tests/DateTime_diff-spring-type2-type3.phpt]  XFAIL REASON: Various bugs exist
DateTime::diff() -- spring type3 type2 [ext/date/tests/DateTime_diff-spring-type3-type2.phpt]  XFAIL REASON: Various bugs exist
DateTime::diff() -- spring type3 type3 [ext/date/tests/DateTime_diff-spring-type3-type3.phpt]  XFAIL REASON: Various bugs exist
DateTime::sub() -- fall type2 type3 [ext/date/tests/DateTime_sub-fall-type2-type3.phpt]  XFAIL REASON: Various bugs exist
DateTime::sub() -- fall type3 type2 [ext/date/tests/DateTime_sub-fall-type3-type2.phpt]  XFAIL REASON: Various bugs exist
DateTime::sub() -- fall type3 type3 [ext/date/tests/DateTime_sub-fall-type3-type3.phpt]  XFAIL REASON: Various bugs exist
DateTime::sub() -- spring type2 type3 [ext/date/tests/DateTime_sub-spring-type2-type3.phpt]  XFAIL REASON: Various bugs exist
DateTime::sub() -- spring type3 type2 [ext/date/tests/DateTime_sub-spring-type3-type2.phpt]  XFAIL REASON: Various bugs exist
DateTime::sub() -- spring type3 type3 [ext/date/tests/DateTime_sub-spring-type3-type3.phpt]  XFAIL REASON: Various bugs exist
Bug #55407 (Impossible to prototype DateTime::createFromFormat) [ext/date/tests/bug55407.phpt]  XFAIL REASON: Bug #55407
RFC: DateTime and Daylight Saving Time Transitions (zone type 3, bd2) [ext/date/tests/rfc-datetime_and_daylight_saving_time-type3-bd2.phpt]  XFAIL REASON: Still not quite right
RFC: DateTime and Daylight Saving Time Transitions (zone type 3, fs) [ext/date/tests/rfc-datetime_and_daylight_saving_time-type3-fs.phpt]  XFAIL REASON: Still not quite right
Bug #42718 (unsafe_raw filter not applied when configured as default filter) [ext/filter/tests/bug42718.phpt]  XFAIL REASON: FILTER_UNSAFE_RAW not applied when configured as default filter, even with flags
Bug #67296 (filter_input doesn't validate variables) [ext/filter/tests/bug49184.phpt]  XFAIL REASON: See Bug #49184
Bug #67167: filter_var(null,FILTER_VALIDATE_BOOLEAN,FILTER_NULL_ON_FAILURE) returns null [ext/filter/tests/bug67167.02.phpt]  XFAIL REASON: Requires php_zval_filter to not use convert_to_string for all filters.
Bug #53640 (XBM images require width to be multiple of 8) [ext/gd/tests/bug53640.phpt]  XFAIL REASON: Padding is not implemented yet
Phar: bug #69958: Segfault in Phar::convertToData on invalid file [ext/phar/tests/bug69958.phpt]  XFAIL REASON: Still has memory leaks, see https://bugs.php.net/bug.php?id=70005
Test basic function : variation3 use_trans_sid [ext/session/tests/session_basic3.phpt]  XFAIL REASON: Waiting url_scanner_ex.re fix. https://bugs.php.net/bug.php?id=68970
Bug #70470 (Built-in server truncates headers spanning over TCP packets) [sapi/cli/tests/bug70470.phpt]  XFAIL REASON: bug is not fixed yet
=====================================================================

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Concatenating many small strings should not slowdown allocations [Zend/tests/concat_003.phpt]
Bug #61948 (CURLOPT_COOKIEFILE '' raises open_basedir restriction) [ext/curl/tests/bug61948.phpt]
Bug # #68937 (Segfault in curl_multi_exec) [ext/curl/tests/bug68937.phpt]
Bug # #68937 (Segfault in curl_multi_exec) [ext/curl/tests/bug68937_2.phpt]
Bug #41655 (open_basedir bypass via glob()) 1/2 [ext/standard/tests/file/bug41655_1.phpt]
Test glob() function: ensure no platform difference, variation 3 [ext/standard/tests/file/glob_variation5.phpt]
=====================================================================

=====================================================================
WARNED TEST SUMMARY
---------------------------------------------------------------------
Live range & throw from finally [Zend/tests/temporary_cleaning_010.phpt] (warn: XFAIL section but test passes)
Bug #70172 - Use After Free Vulnerability in unserialize() [ext/standard/tests/serialize/bug70172_2.phpt] (warn: XFAIL section but test passes)
Bug #70219 Use after free vulnerability in session deserializer [ext/standard/tests/serialize/bug70219.phpt] (warn: XFAIL section but test passes)
=====================================================================

You may have found a problem in PHP.
This report can be automatically sent to the PHP QA team at
http://qa.php.net/reports and http://news.php.net/php.qa.reports
This gives us a better understanding of PHP's behavior.
If you don't want to send the report immediately you can choose
option "s" to save it.  You can then email it to [email protected] later.
Do you want to send this report now? [Yns]: Y

@fa8ster
Copy link

fa8ster commented Dec 4, 2015

@csanonymus @LubosRemplik @ersin-demirtas where shall I replace http://pear.php.net/install-pear-nozlib.phar ? I'm confused :(

@Faryshta
Copy link

Faryshta commented Dec 4, 2015

@fabianhenzler open the /tmp/php-src/Makefile with any text editor and seek https://pear.php.net/install-pear-nozlib.phar edit it and run make install again

@Geekbell
Copy link

Geekbell commented Dec 4, 2015

Mine works successfully, it seems, but it's almost as if php is not running. Anyone have a similar experience? Are there any prerequisites?

@jacobschweitzer
Copy link

@Geekbell Yeah I've tried all kinds of different things and can't get this working.

@Geekbell
Copy link

Geekbell commented Dec 4, 2015

I actually got it to work after reboot php -v:
PHP 7.1.0-dev (cli) (built: Dec 4 2015 18:40:47) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2015 Zend Technologies

php info in web browser still shows 5.6. The other weird part is that I get raw php in browser until I refresh each page.

@aisthetes
Copy link

add --with-apxs2 to ./configure for create /usr/lib/apache2/modules/libphp7.so
and sudo cp /etc/apache2/mods-available/php5.conf /etc/apache2/mods-enabled/php7.conf

work on ubuntu 15.10 :)

PHP 7.1.0-dev (cli) (built: Dec 5 2015 12:40:12) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2015 Zend Technologies

@joshuataylor
Copy link

Looks like the pear server is having dramas:

http://pear.php.net/

Intermediate pear.php.net server

The server running pear.php.net had a fatal hard disk failure and gets replaced by a new machine this week. Until the new machine is setup, this page is up to let you continue installing PEAR packages via the PEAR installer.

So you will have thep atch your files, as above.

Also make sure you're on 7.0.0 if you want extensions etc to work properly :).

If you are lazy:

sed -i 's/https:\/\/pear.php.net\/install-pear-nozlib.phar/http:\/\/pear.php.net\/install-pear-nozlib.phar/g' /tmp/php-src/Makefile

@Geekbell
Copy link

Geekbell commented Dec 5, 2015

@aisthetes I started over on 15.10 to see if I could get it to work. Still a no go. does php5 have to be installed for it to work?

@aisthetes
Copy link

@Geekbell
$ sudo a2dismod php5
$ sudo cp /etc/apache2/mods-available/php5.conf /etc/apache2/mods-enabled/php7.conf
$ sudo service apache2 restart

@enoch85
Copy link

enoch85 commented Dec 6, 2015

Will this install the stable version of PHP7? I see alot of dev packages...

Anyone tested on Ubuntu Server 14.04.3?

@roman204
Copy link

roman204 commented Dec 6, 2015

http://pear.php.net/install-pear-nozlib.phar is throwing a 404 error ?!?
anyone got it working ?

@aisthetes
Copy link

work on Raspbian GNU/Linux 8.0 (jessie), but slower than PHP Version 5.6.14-0+deb8u1

@jacobschweitzer
Copy link

So this is what ended up working for me on Ubuntu 14.04 with Nginx:
sudo service nginx stop
sudo apt-get purge php5-*
sudo add-apt-repository ppa:ondrej/php-7.0
sudo apt-get update
sudo apt-get install php7.0 php7.0-common php7.0-cgi php7.0-fpm php7.0-mysql

Then edit your Nginx config file:
sudo nano /etc/nginx/sites-available/thedomainnamegoeshere.com
location ~ .php$ {
include fastcgi_params;
fastcgi_keep_conn on;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}

Then restart Nginx:
sudo service nginx start

Source - https://laracasts.com/discuss/channels/tips/how-to-upgrade-from-php-5-to-php-70-on-ubuntu-1404-with-nginx-146

@akeinhell
Copy link

Add check for root-prvilege

if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

@Shaeldon
Copy link

How can i compile it withj mssql drivers/dblib? --with-mssql doesnt work?

@ram-you
Copy link

ram-you commented Dec 10, 2015

For Apache2, add to @jacobschweitzer method :
sudo apt-get install libapache2-mod-php7.0

@andrewtweber
Copy link

Thanks @ram-you

@oppachoriya
Copy link

Script is falling for me

TIME END 2015-12-15 13:58:47

TEST RESULT SUMMARY

Exts skipped : 22

Exts tested : 53

Number of tests : 14319 11560
Tests skipped : 2759 ( 19.3%) --------
Tests warned : 3 ( 0.0%) ( 0.0%)
Tests failed : 8 ( 0.1%) ( 0.1%)
Expected fail : 36 ( 0.3%) ( 0.3%)

Tests passed : 11513 ( 80.4%) ( 99.6%)

Time taken : 409 seconds

EXPECTED FAILED TEST SUMMARY

Test open_basedir configuration [tests/security/open_basedir_linkinfo.phpt] XFAIL REASON: BUG: open_basedir cannot delete symlink to prohibited file. See also
bugs 48111 and 52176.
Inconsistencies when accessing protected members [Zend/tests/access_modifiers_008.phpt] XFAIL REASON: Discussion: http://marc.info/?l=php-internals&m=120221184420957&w=2
Inconsistencies when accessing protected members - 2 [Zend/tests/access_modifiers_009.phpt] XFAIL REASON: Discussion: http://marc.info/?l=php-internals&m=120221184420957&w=2
Bug #48770 (call_user_func_array() fails to call parent from inheriting class) [Zend/tests/bug48770.phpt] XFAIL REASON: See Bug #48770
Bug #48770 (call_user_func_array() fails to call parent from inheriting class) [Zend/tests/bug48770_2.phpt] XFAIL REASON: See Bug #48770
Bug #48770 (call_user_func_array() fails to call parent from inheriting class) [Zend/tests/bug48770_3.phpt] XFAIL REASON: See Bug #48770
Initial value of static var in method depends on the include time of the class definition [Zend/tests/method_static_var.phpt] XFAIL REASON: Maybe not a bug
Bug #70228 (memleak if return in finally block) [Zend/tests/try/bug70228.phpt] XFAIL REASON: See https://bugs.php.net/bug.php?id=70228
DateTime::add() -- fall type2 type3 [ext/date/tests/DateTime_add-fall-type2-type3.phpt] XFAIL REASON: Various bugs exist
DateTime::add() -- fall type3 type2 [ext/date/tests/DateTime_add-fall-type3-type2.phpt] XFAIL REASON: Various bugs exist
DateTime::add() -- fall type3 type3 [ext/date/tests/DateTime_add-fall-type3-type3.phpt] XFAIL REASON: Various bugs exist
DateTime::add() -- spring type2 type3 [ext/date/tests/DateTime_add-spring-type2-type3.phpt] XFAIL REASON: Various bugs exist
DateTime::add() -- spring type3 type2 [ext/date/tests/DateTime_add-spring-type3-type2.phpt] XFAIL REASON: Various bugs exist
DateTime::add() -- spring type3 type3 [ext/date/tests/DateTime_add-spring-type3-type3.phpt] XFAIL REASON: Various bugs exist
DateTime::diff() -- fall type2 type3 [ext/date/tests/DateTime_diff-fall-type2-type3.phpt] XFAIL REASON: Various bugs exist
DateTime::diff() -- fall type3 type2 [ext/date/tests/DateTime_diff-fall-type3-type2.phpt] XFAIL REASON: Various bugs exist
DateTime::diff() -- fall type3 type3 [ext/date/tests/DateTime_diff-fall-type3-type3.phpt] XFAIL REASON: Various bugs exist
DateTime::diff() -- spring type2 type3 [ext/date/tests/DateTime_diff-spring-type2-type3.phpt] XFAIL REASON: Various bugs exist
DateTime::diff() -- spring type3 type2 [ext/date/tests/DateTime_diff-spring-type3-type2.phpt] XFAIL REASON: Various bugs exist
DateTime::diff() -- spring type3 type3 [ext/date/tests/DateTime_diff-spring-type3-type3.phpt] XFAIL REASON: Various bugs exist
DateTime::sub() -- fall type2 type3 [ext/date/tests/DateTime_sub-fall-type2-type3.phpt] XFAIL REASON: Various bugs exist
DateTime::sub() -- fall type3 type2 [ext/date/tests/DateTime_sub-fall-type3-type2.phpt] XFAIL REASON: Various bugs exist
DateTime::sub() -- fall type3 type3 [ext/date/tests/DateTime_sub-fall-type3-type3.phpt] XFAIL REASON: Various bugs exist
DateTime::sub() -- spring type2 type3 [ext/date/tests/DateTime_sub-spring-type2-type3.phpt] XFAIL REASON: Various bugs exist
DateTime::sub() -- spring type3 type2 [ext/date/tests/DateTime_sub-spring-type3-type2.phpt] XFAIL REASON: Various bugs exist
DateTime::sub() -- spring type3 type3 [ext/date/tests/DateTime_sub-spring-type3-type3.phpt] XFAIL REASON: Various bugs exist
Bug #55407 (Impossible to prototype DateTime::createFromFormat) [ext/date/tests/bug55407.phpt] XFAIL REASON: Bug #55407
RFC: DateTime and Daylight Saving Time Transitions (zone type 3, bd2) [ext/date/tests/rfc-datetime_and_daylight_saving_time-type3-bd2.phpt] XFAIL REASON: Still not quite right
RFC: DateTime and Daylight Saving Time Transitions (zone type 3, fs) [ext/date/tests/rfc-datetime_and_daylight_saving_time-type3-fs.phpt] XFAIL REASON: Still not quite right
Bug #42718 (unsafe_raw filter not applied when configured as default filter) [ext/filter/tests/bug42718.phpt] XFAIL REASON: FILTER_UNSAFE_RAW not applied when configured as default filter, even with flags
Bug #67296 (filter_input doesn't validate variables) [ext/filter/tests/bug49184.phpt] XFAIL REASON: See Bug #49184
Bug #67167: filter_var(null,FILTER_VALIDATE_BOOLEAN,FILTER_NULL_ON_FAILURE) returns null [ext/filter/tests/bug67167.02.phpt] XFAIL REASON: Requires php_zval_filter to not use convert_to_string for all filters.
Bug #53640 (XBM images require width to be multiple of 8) [ext/gd/tests/bug53640.phpt] XFAIL REASON: Padding is not implemented yet
Phar: bug #69958: Segfault in Phar::convertToData on invalid file [ext/phar/tests/bug69958.phpt] XFAIL REASON: Still has memory leaks, see https://bugs.php.net/bug.php?id=70005
Test basic function : variation3 use_trans_sid [ext/session/tests/session_basic3.phpt] XFAIL REASON: Waiting url_scanner_ex.re fix. https://bugs.php.net/bug.php?id=68970

Bug #70470 (Built-in server truncates headers spanning over TCP packets) [sapi/cli/tests/bug70470.phpt] XFAIL REASON: bug is not fixed yet

FAILED TEST SUMMARY

Bug #61948 (CURLOPT_COOKIEFILE '' raises open_basedir restriction) [ext/curl/tests/bug61948.phpt]
Bug # #68937 (Segfault in curl_multi_exec) [ext/curl/tests/bug68937.phpt]
Bug # #68937 (Segfault in curl_multi_exec) [ext/curl/tests/bug68937_2.phpt]
Bug #32330 (session_destroy, "Failed to initialize storage module", custom session handler) [ext/session/tests/bug32330.phpt]
Test session_set_save_handler() function : variation [ext/session/tests/session_set_save_handler_variation4.phpt]
Test session_set_save_handler() function : variation [ext/session/tests/session_set_save_handler_variation5.phpt]
Bug #41655 (open_basedir bypass via glob()) 1/2 [ext/standard/tests/file/bug41655_1.phpt]

Test glob() function: ensure no platform difference, variation 3 [ext/standard/tests/file/glob_variation5.phpt]

WARNED TEST SUMMARY

Live range & throw from finally [Zend/tests/temporary_cleaning_010.phpt](warn: XFAIL section but test passes)
Bug #70172 - Use After Free Vulnerability in unserialize() [ext/standard/tests/serialize/bug70172_2.phpt](warn: XFAIL section but test passes)

Bug #70219 Use after free vulnerability in session deserializer [ext/standard/tests/serialize/bug70219.phpt](warn: XFAIL section but test passes)

You may have found a problem in PHP.
This report can be automatically sent to the PHP QA team at
http://qa.php.net/reports and http://news.php.net/php.qa.reports
This gives us a better understanding of PHP's behavior.
If you don't want to send the report immediately you can choose
option "s" to save it. You can then email it to [email protected] later.
Do you want to send this report now? [Yns]:

@hvanmegen
Copy link

Please add root-permission check like @akeinhell stated 7 days ago:

if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

Also, add the 'make' package to 'apt-get install' list of packages; I just installed a fresh 14.04 server, and that package was missing :)

@tronsha
Copy link
Author

tronsha commented Jan 8, 2016

thanks @akeinhell, I've added it

@tronsha
Copy link
Author

tronsha commented Jan 8, 2016

thanks @hvanmegen, I've added the make to 'apt-get install'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment