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

前端 未结 9 1954
野性不改
野性不改 2020-12-24 03:27

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 of

相关标签:
9条回答
  • 2020-12-24 03:45

    Ondřej Surý has a PPA at https://launchpad.net/~ondrej/+archive/ubuntu/php

    sudo add-apt-repository ppa:ondrej/php
    sudo apt-get update
    sudo apt-get install php7.0
    

    Using the PPA is certainly easier than building from source!

    A note for people with PHP 5.x already installed; apt-get complained a bit when I tried to install install php7.0 on a box with PHP 5 on it, but after I did apt-get remove php5 to get rid of my existing PHP 5.6 install and then explicitly did sudo apt-get install php7.0-common I was able to get the sudo apt-get install php7.0 to go through. Don't know why this was necessary; if somebody who understands Apt better than I do would like to edit in some better instructions (or provide a better answer altogether and ask me to delete this one) then feel free.

    0 讨论(0)
  • 2020-12-24 03:45

    I am the OP. My suggestion is to use Ondřej Surý 's PPA at https://launchpad.net/~ondrej/+archive/ubuntu/php-7.0 as suggested by @Mark Amery

    If you you want the fun and games of installing PHP 7 from the source then then here is the script I use for the config and build (Note the "make -j4" is if you have a 4 core machine and want it to parallel thread on every core during the build process):

    #!/bin/sh
    ./buildconf --force
    
    ./configure \
    --prefix=/usr/php7 \
    --with-config-file-path=/etc/php7 \
    --enable-phpdbg \
    --with-pdo-mysql=mysqlnd \
    --with-mysqli=mysqlnd \
    --with-pgsql \
    --with-pdo-pgsql \
    --with-pdo-sqlite \
    --enable-intl \
    --with-pear \
    --with-gd \
    --with-jpeg-dir=/usr \
    --with-png-dir=/usr \
    --enable-exif \
    --enable-zip \
    --with-zlib \
    --with-zlib-dir=/usr \
    --with-mcrypt=/usr \
    --enable-soap \
    --enable-xmlreader \
    --with-xsl \
    --with-curl=/usr \
    --with-tidy \
    --with-xmlrpc \
    --enable-sysvsem \
    --enable-sysvshm \
    --enable-shmop \
    --enable-pcntl \
    --with-readline \
    --enable-mbstring \
    --with-curl \
    --with-gettext \
    --enable-sockets \
    --with-bz2 \
    --with-openssl \
    --with-gmp \
    --enable-bcmath \
    --enable-calendar \
    --enable-ftp \
    --with-pspell=/usr \
    --with-enchant=/usr \
    --enable-wddx \
    --with-imap \
    --with-imap-ssl \
    --with-freetype-dir=/usr/local \
    --with-xpm-dir=/usr \
    --with-kerberos \
    --enable-sysvmsg 
    
    make -j4 
    sudo make install
    
    0 讨论(0)
  • 2020-12-24 03:49

    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

    0 讨论(0)
  • 2020-12-24 03:51

    You could install a control panel that supports Ubuntu and PHP 7. For example, ServerPilot supports Ubuntu and installs PHP 7.

    0 讨论(0)
  • 2020-12-24 04:00

    Installing PHP7(Nightly Build - latest build) on Ubuntu using the terminal

    i will assume that you have apache2 already installed, if not then install it with the following command:

    apt-get install apache2
    

    check if apache is running:

    service apache2 status
    

    You would be able to see something like:

    apache2.service - LSB: Apache2 web server
    Loaded: loaded (/etc/init.d/apache2)
    Active: ACTIVE (RUNNING)
    

    if apache is running then procced with the PHP 7 installation process:

    First add the PHP7 repo to your sources list, /etc/apt/sources.list, using your preferred text editor:

    deb http://repos.zend.com/zend-server/early-access/php7/repos ubuntu/ 
    

    After adding the PHP 7 repo, update your system with the following command:

    apt-get update
    

    now if everything went ok you should be able to install PHP7 Nightly Build with the following command:

    apt-get install php7-nightly
    

    During the install a warning may appear, “Do you want to continue?, if it does press enter. After pressing enter, you will also get a warning similar to below

    WARNING: The following packages cannot be authenticated!
      php7-nightly
    Install these packages without verification? [y/N]
    

    Type Y and then press Enter to continue.

    The installation is finished! Now you need to get PHP7 to work with Apache, in order to do that, copy/move the libraries and modules of PHP7 to the Apache directories with the following commands:

    cp /usr/local/php7/libphp7.so /usr/lib/apache2/modules/
    cp /usr/local/php7/php7.load /etc/apache2/mods-available/
    

    After moving the files, you need to edit /etc/apache2/apache2.conf and add the following lines to the bottom of the file. which will tell apache to serve php files

    <FilesMatch \.php$>
    SetHandler application/x-httpd-php
    </FilesMatch>
    

    Now that you fixed the apache2.conf run the following command to enable the PHP mpm module and switch to mpm_prefork.

    a2dismod mpm_event && a2enmod mpm_prefork && a2enmod php7
    

    Restart Apache so that the changes you made take effect:

    service apache2 restart
    

    Now its time to test PHP 7

    To test out PHP7, you are going to create a PHP file a called info.php in /var/www/html/ by using your favorite editor and inserting the following lines of code.

    <?php
    phpinfo();
    ?>
    

    Now you can go to your favorite browser and try the following URL

    http://localhost/info.php
    

    At the top of the page, check that the PHP version is 7.0 or higher.

    PHP7 version example

    Now that You verified that it's working, you should remove your info.php as it's a security risk. Remove it with the following command:

    rm /var/www/html/info.php

    Source:https://www.atlantic.net/community/howto/try-php7-debian-8-2-lamp-stack/

    0 讨论(0)
  • 2020-12-24 04:01

    I see other users are posting binaries but if you want to compile it yourself try auto-apt.

    For compiling any application from source you can use auto-apt. It's not a well known tool but it helps a lot for compiling applications with lots of external libraries.

    Auto-apt creates a driven checking of the configure script and detects which packages the configure.sh script it's looking for, and it allows you to install they if you want the feature the script it's looking at that moment.

    sudo apt-get install auto-apt
    sudo auto-apt update
    sudo auto-apt updatedb && sudo auto-apt update-local
    sudo auto-apt run ./configure
    

    More info: https://help.ubuntu.com/community/AutoApt

    0 讨论(0)
提交回复
热议问题