-
-
Save m1st0/1c41b8d0eb42169ce71a to your computer and use it in GitHub Desktop.
| #!/bin/bash | |
| # PHP 8 Compile # | |
| # Author: Maulik Mistry | |
| # Please share support: https://www.paypal.com/paypalme/m1st0 | |
| # References: | |
| # http://www.zimuel.it/install-php-7/ | |
| # http://www.hashbangcode.com/blog/compiling-and-installing-php7-ubuntu | |
| # root-talis https://gist.github.com/root-talis/40c4936bf0287237839ccd3fdfdaec28 | |
| # | |
| # License: BSD License 2.0 | |
| # Copyright (c) 2015-2025, Maulik Mistry | |
| # All rights reserved. | |
| # | |
| # Redistribution and use in source and binary forms, with or without | |
| # modification, are permitted provided that the following conditions are met: | |
| # * Redistributions of source code must retain the above copyright | |
| # notice, this list of conditions and the following disclaimer. | |
| # * Redistributions in binary form must reproduce the above copyright | |
| # notice, this list of conditions and the following disclaimer in the | |
| # documentation and/or other materials provided with the distribution. | |
| # * Neither the name of the <organization> nor the | |
| # names of its contributors may be used to endorse or promote products | |
| # derived from this software without specific prior written permission. | |
| # | |
| # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
| # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | |
| # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| # Text message colors | |
| RED="\033[0;31m" | |
| YELLOW="\033[0;33m" | |
| END_TEXT="\033[0m" | |
| # Desired PHP branch if not using git tag autodetection | |
| PHP_VERSION="8.4.9" | |
| # I like to setup thing here so that it doesn't bother Kubuntu/Ubuntu | |
| PHP_DIR="/usr/local" | |
| # Stop execution if things fail to move forward. | |
| set -e | |
| ## DEPENDENCIES | |
| # Setup dependencies for PHP 8 | |
| # Add any missing needs from configuration area | |
| #sudo apt update | |
| #sudo apt upgrade | |
| #sudo apt clean | |
| sudo apt install libldap2-dev \ | |
| libldap-common \ | |
| libtool-bin \ | |
| libzip-dev \ | |
| lbzip2 \ | |
| libxml2-dev \ | |
| bzip2 \ | |
| re2c \ | |
| libbz2-dev \ | |
| apache2-dev \ | |
| libjpeg-dev \ | |
| libxpm-dev \ | |
| libxpm-dev \ | |
| libgmp-dev \ | |
| libgmp3-dev \ | |
| libmcrypt-dev \ | |
| libpspell-dev \ | |
| librecode-dev \ | |
| libcurl4-openssl-dev \ | |
| libxft-dev \ | |
| libonig-dev \ | |
| libsqlite3-dev \ | |
| ccache | |
| if dpkg -l | grep -q '^ii mysql-server'; then | |
| echo "MySQL server detected." | |
| USE_MYSQL=1 | |
| elif dpkg -l | grep -q '^ii mariadb-server'; then | |
| echo "MariaDB server detected." | |
| USE_MARIADB=1 | |
| else | |
| echo "No MySQL or MariaDB server found." | |
| # Decide on default or exit | |
| exit 1 | |
| fi | |
| if [ "$USE_MYSQL" = "1" ]; then | |
| sudo apt install libmysqlclient-dev | |
| elif [ "$USE_MARIADB" = "1" ]; then | |
| sudo apt install libmariadb-dev | |
| fi | |
| # LDAP does not recognize these without additional symlinks | |
| if [[ ! -e /usr/lib/libldap.so ]]; then | |
| sudo ln -sf /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/libldap.so | |
| fi | |
| if [[ ! -e /usr/lib/liblber.so ]]; then | |
| sudo ln -sf /usr/lib/x86_64-linux-gnu/liblber.so /usr/lib/liblber.so | |
| fi | |
| if [[ ! -e /usr/include/gmp.h ]]; then | |
| sudo ln -sf /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h | |
| fi | |
| ## CONFIGURE | |
| if [ -d ./php-src ]; then | |
| cd ./php-src | |
| git reset --hard HEAD | |
| git fetch --tags --force | |
| # Check if we are already on the desired tag | |
| if [ "$(git describe --tags --exact-match 2>/dev/null)" != "php-${PHP_VERSION}" ]; then | |
| git checkout "php-${PHP_VERSION}" 2>/dev/null || git checkout -b "PHP-${PHP_VERSION}" "php-${PHP_VERSION}" | |
| else | |
| printf "\n${YELLOW}Already on php-${PHP_VERSION}${END_TEXT}\n" | |
| fi | |
| # Obtain latest tag | |
| # Sometimes the latest tag is not properly found using either of the following | |
| # or we don't want the latest Release Candidate | |
| #tag=$(git describe --tags `git rev-list --tags --max-count=1`) | |
| #tag=$(git describe --tags `git rev-list --branches --max-count=1`) | |
| #git checkout tags/$tag -b $tag | |
| #git checkout tags/php-${PHP_VERSION} -b PHP-${PHP_VERSION} | |
| else | |
| git clone https://github.com/php/php-src | |
| cd ./php-src | |
| git switch --create PHP-${PHP_VERSION} php-${PHP_VERSION} | |
| fi | |
| # Helped fix configure issues and ignored files needing an update | |
| ./buildconf --force | |
| # Compile options | |
| export CC="ccache gcc" && export CXX="ccache g++" | |
| ./configure --prefix="$PHP_DIR/php8" \ | |
| --with-config-file-path="$PHP_DIR/php8/etc/" \ | |
| --with-config-file-scan-dir="$PHP_DIR/php8/etc/conf.d/" \ | |
| --enable-mbstring \ | |
| --with-zip \ | |
| --enable-bcmath \ | |
| --enable-pcntl \ | |
| --enable-ftp \ | |
| --enable-exif \ | |
| --enable-calendar \ | |
| --enable-sysvmsg \ | |
| --enable-sysvsem \ | |
| --enable-sysvshm \ | |
| --enable-intl \ | |
| --enable-zts \ | |
| --with-curl \ | |
| --with-iconv \ | |
| --with-gmp \ | |
| --with-pspell \ | |
| --with-zlib-dir=/usr \ | |
| --enable-gd-jis-conv \ | |
| --with-openssl \ | |
| --with-gettext=/usr \ | |
| --with-zlib=/usr \ | |
| --with-bz2 \ | |
| --with-apxs2=/usr/bin/apxs \ | |
| --with-ldap \ | |
| --with-mysql=mysqlnd \ | |
| --with-mysqli=mysqlnd \ | |
| --with-pdo-mysql=mysqlnd \ | |
| --with-xdebug | |
| # --with-mcrypt \ | |
| # --enable-wddx \ | |
| # --with-gd \ | |
| # --with-jpeg-dir=/usr \ | |
| # --with-png-dir=/usr \ | |
| # --with-xpm-dir=/usr \ | |
| # --with-freetype-dir=/usr \ | |
| # --enable-gd-native-ttf \ | |
| # --with-recode=/usr \ | |
| # --without-xml | |
| ## COMPILE | |
| # Cleanup for previous failures | |
| make clean | |
| # Build | |
| CPUNUM=`nproc` | |
| make -j ${CPUNUM} | |
| # Install | |
| sudo make install | |
| # Update paths for easy switching | |
| sudo update-alternatives --install /usr/bin/php php $PHP_DIR/php8/bin/php 50 \ | |
| --slave /usr/share/man/man1/php.1.gz php.1.gz \ | |
| $PHP_DIR/php8/php/man/man1/php.1 | |
| # Provide PHP version choice | |
| printf "Select the version of PHP you want active in subsequent shells and the \ | |
| system:\n" | |
| sudo update-alternatives --config php | |
| ## APACHE SETUP | |
| # Provide Apache2 libphp.so for later configuration | |
| printf "Running 'libtool --finish ./libs' as recommended.\n" | |
| libtool --finish ./libs | |
| sudo mkdir -p "$PHP_DIR/php8/lib/apache2/modules" | |
| sudo cp "./libs/libphp.so" "$PHP_DIR/php8/lib/apache2/modules/" | |
| # Left unconfigured between Apache2 vs CLI | |
| sudo mkdir -p "$PHP_DIR/php8/etc/" | |
| sudo cp "php.ini-development" "$PHP_DIR/php8/etc/" | |
| sudo cp "php.ini-production" "$PHP_DIR/php8/etc/" | |
| # Work on non-threaded version from configure | |
| #sudo a2dismod mpm_worker | |
| #sudo a2enmod mpm_prefork | |
| # Work on threaded --enable-zts version from configure | |
| sudo a2dismod mpm_prefork | |
| sudo a2enmod mpm_worker | |
| PHP_MODULE_CONF="/etc/apache2/mods-available/php8.conf" | |
| if [[ ! -e "$PHP_MODULE_CONF" ]]; then | |
| sudo tee "$PHP_MODULE_CONF" > /dev/null <<EOF | |
| <IfModule php_module> | |
| <FilesMatch ".+\.ph(ar|p|tml)$"> | |
| SetHandler application/x-httpd-php | |
| </FilesMatch> | |
| <FilesMatch ".+\.phps$"> | |
| SetHandler application/x-httpd-php-source | |
| # Deny access to raw php sources by default | |
| # To re-enable it's recommended to enable access to the files | |
| # only in specific virtual host or directory | |
| Require all denied | |
| </FilesMatch> | |
| # Deny access to files without filename (e.g. '.php') | |
| <FilesMatch "^\.ph(ar|p|ps|tml)$"> | |
| Require all denied | |
| </FilesMatch> | |
| </IfModule> | |
| EOF | |
| fi | |
| PHP_MODULE_LOAD="/etc/apache2/mods-available/php8.load" | |
| if [[ ! -e "$PHP_MODULE_LOAD" ]]; then | |
| sudo tee "$PHP_MODULE_LOAD" > /dev/null <<EOF | |
| LoadModule php_module $PHP_DIR/php8/lib/apache2/modules/libphp.so | |
| EOF | |
| fi | |
| sudo a2dismod php | |
| sudo a2enmod php8 | |
| # Restart Apache if all went well. | |
| sudo systemctl restart apache2 | |
| sudo systemctl status apache2 | |
| # View any errors for Apache startup. | |
| printf "\n${YELLOW}Any errors starting Apache2 with PHP can be seen with 'sudo journalctl -xe' .${END_TEXT}\n" | |
| # An example: | |
| # | |
| # Running PHP scripts in user directories is disabled by default | |
| # | |
| # You may commnt this out as needed in conf files at | |
| # /etc/apache2/mods-available/ | |
| # to re-enable PHP in user directories | |
| # from <IfModule> to </IfModule> | |
| # | |
| #<IfModule mod_userdir.c> | |
| # <Directory /home/*/public_html> | |
| # php_admin_flag engine Off | |
| # </Directory> | |
| #</IfModule>" | |
| # Return to reprevious location | |
| cd - |
Hello, how do I install pdo_firebird driver?
I was getting the following error while enabling mpm_prefork
Considering conflict mpm_event for mpm_prefork:
ERROR: Module mpm_event is enabled - cannot proceed due to conflicts. It needs to be disabled first!
Considering conflict mpm_worker for mpm_prefork:
This ultimately led to the following error while starting apache
* The apache2 configtest failed.
Output of config test was:
[Fri Feb 19 07:25:37.100983 2016] [:crit] [pid 16524:tid 140221303203712] Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP.
AH00013: Pre-configuration failed
Action 'configtest' failed.
I Solved it by apt-get install libapache2-mod-php7.0
you can save a lot of hdd space and time by shadow cloning a particular branch instead the whole repository:
$git clone https://github.com/php/php-src = 320MB
$git clone -b PHP-7.0.6 https://github.com/php/php-src --depth 1 = 19.7 MB
(my revision: https://gist.github.com/vanilla-thunder/83149000fcc7974b58a157f3f3020a9d/revisions )
I am not seeing any folder "/etc/php7/". so anyone guide me about this issue?
when you run :
./configure
.....
--with-apxs2=/usr/bin/apxs
i got that error :
sorry i cannot run apxs. possible reasons follow
to resolve this you need to configure with :
--with-apxs2=/usr/bin/apxs2
and if you got that error :
configure: error: freetype-config not found.
you will need to install libfreetype6-dev
in some machines you will need to do some manual search for those files
libldap.so , liblber.so , gmp.h
on AMD64 system you will not be able to locate that folder
/usr/lib/x86_64-linux-gnu/
and i found this folder under i386-linux-gnu name
so that part in some machines may be as like that
sudo ln -sf /usr/lib/i386-linux-gnu/libldap.so /usr/lib/libldap.so
sudo ln -sf /usr/lib/i386-linux-gnu/liblber.so /usr/lib/liblber.so
sudo ln -sf /usr/include/i386-linux-gnu/gmp.h /usr/include/gmp.h
you will face a problem with --with-t1lib
from php.net
T1lib To enable support for T1lib (Postscript Type 1 fonts) add --with-t1lib[=DIR] (Removed as of PHP 7.0.0).
I recommend --with-readline as well, to make sure you don't get stuck with libedit. Eg you can cut and paste text with ^U/^W and ^Y in interactive mode.
Line with t1lib is unnecesarry because of depreciation. (75)
http://php.net/manual/en/image.installation.php
T1lib To enable support for T1lib (Postscript Type 1 fonts) add --with-t1lib[=DIR] (Removed as of PHP 7.0.0).
Generally great script. I am impressed!
On Ubuntu server 16.04 , before executing configure you should install bison package.
Configure: error: bison is required to build PHP/Zend when building a GIT checkout!
Ubuntu 15.04 ERROR: Module php7 does not exist!
I used your script to install php 5.6.
Works like a charm. Thanks
I am installing php-7.1.5 and able to build it smoothly using source code. I have one doubt, which url should I check if php server is running fine
I have updated the gist here: https://gist.github.com/root-talis/40c4936bf0287237839ccd3fdfdaec28
@m1st0 please consider pulling the changes.
How do you create a pull request for a gist?..
You can add commit messages to new revision, in case you didn't know. I think those would be better place for change descriptions. To achieve this, you need to clone and manage the Gist as a Git repository.