Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»PHP»How To Install PHP 5.6 & 7.3 on Ubuntu 18.04

    How To Install PHP 5.6 & 7.3 on Ubuntu 18.04

    RahulBy RahulApril 12, 20152 Mins ReadUpdated:June 10, 2021

    Thanks to Ondřej Surý for maintaining PPA of latest PHP5 versions on launchpad. If you want to install a specific version of PHP, then this article can be helpful for you.

    This article will help you for installing PHP 5.6 or PHP 7.3 using PPA on Ubuntu 18.04 LTS systems. If you have already had a higher version installed on your system and you need to install a lower version, then you have to remove the higher version first and remove the apt repository from the system.

    • Read: How to Install PHP 7.0 & PHP 5.6 on Debian 8/7 via PPA

    Install PHP 5.6 on Ubuntu

    Use the following set of commands to enable PPA for PHP 5.6 in your Ubuntu system and install PHP 5.6.

    sudo apt-get install python-software-properties
    sudo add-apt-repository ppa:ondrej/php
    sudo apt-get update
    sudo apt-get install -y php5.6
    

    Check Installed PHP Version:

    php -v 
    
    PHP 5.6.40-10+ubuntu16.04.1+deb.sury.org+1 (cli)
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
        with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    

    Install PHP 7.3 on Ubuntu

    Use the following set of commands to add PPA for PHP 7.3 in your Ubuntu system and install PHP 7.3.

    sudo apt-get install python-software-properties
    sudo add-apt-repository ppa:ondrej/php
    sudo apt-get update
    sudo apt-get install -y php7.3
    

    Check Installed PHP Version:

    php -v 
    
    PHP 7.3.9-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Sep  2 2019 12:54:04) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies
        with Zend OPcache v7.3.9-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
    

    Switch Between PHP Version’s

    If you have installed multiple PHP versions and want to use them differently than the default. Use the following steps to switch between the php5.6 and php7.3 versions. You can use the same command for other PHP versions.

    From PHP 5.6 => PHP 7.3

    Apache:-
    
    sudo a2dismod php5.6
    sudo a2enmod php7.3
    sudo service apache2 restart
    
    CLI:-
    
    sudo update-alternatives --set php /usr/bin/php7.3
    sudo update-alternatives --set phpize /usr/bin/phpize7.3
    sudo update-alternatives --set php-config /usr/bin/php-config7.3
    

    From PHP 7.3 => PHP 5.6

    Apache:-
    
    sudo a2dismod php7.3
    sudo a2enmod php5.6
    sudo service apache2 restart
    
    CLI:-
    
    sudo update-alternatives --set php /usr/bin/php5.6
    sudo update-alternatives --set phpize /usr/bin/phpize5.6
    sudo update-alternatives --set php-config /usr/bin/php-config5.6
    
    PHP PHP 5.4 PHP 5.5 PHP 5.6 PHP5 PHP7
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHOw to Get Gravatar Image with PHP
    Next Article How To Format USB Drive in Linux Command Line

    Related Posts

    How to Install Composer on Ubuntu 22.04

    Updated:June 24, 20223 Mins Read

    How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04

    Updated:June 19, 20223 Mins Read

    How To Install Linux, Nginx, MySQL, & PHP (LEMP Stack) on Ubuntu 22.04

    Updated:April 7, 20227 Mins Read

    How to Install Apache, MySQL, PHP (LAMP Stack) on Ubuntu 22.04

    Updated:June 28, 20225 Mins Read

    How To Setup Apache, PHP & MongoDB in Ubuntu & Debian

    Updated:October 8, 20213 Mins Read

    How To Install and Use PHP Composer on Debian 11

    Updated:February 16, 20224 Mins Read

    40 Comments

    1. Dave on November 2, 2021 4:55 pm

      After thinking it didn’t work, I realised php -v tells you the CLI version. This changes the apache version, so a phpinfo command in a php script revealed it did in fact work perfectly.
      Thanks

      Reply
    2. AMit singh on November 5, 2020 10:33 am

      Great Job Bro. working

      Reply
    3. Joseph on February 9, 2020 8:10 pm

      There’s certainly a great deal to find out
      abot this issue. I like all of the poins you made.

      Reply
    4. Diego Muñoz V on October 16, 2019 3:42 pm

      Hello Friend

      I am trying to do the installation and at the time of executing the repository command I have an error after pressing ENTER

      # LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
      More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
      Press [ENTER] to continue or ctrl-c to cancel adding it

      gpg: keyring `/tmp/tmp93drbu74/secring.gpg’ created
      gpg: keyring `/tmp/tmp93drbu74/pubring.gpg’ created
      gpg: requesting key E5267A6C from hkp server keyserver.ubuntu.com
      gpg: /tmp/tmp93drbu74/trustdb.gpg: trustdb created
      gpg: key E5267A6C: public key “Launchpad PPA for Ond\xc5\x99ej Sur?” imported
      gpg: Total number processed: 1
      gpg: imported: 1 (RSA: 1)
      Exception in thread Thread-1:
      Traceback (most recent call last):
      File “/usr/lib/python3.4/threading.py”, line 920, in _bootstrap_inner
      self.run()
      File “/usr/lib/python3.4/threading.py”, line 868, in run
      self._target(*self._args, **self._kwargs)
      File “/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py”, line 687, in addkey_func
      func(**kwargs)
      File “/usr/lib/python3/dist-packages/softwareproperties/ppa.py”, line 370, in add_key
      return apsk.add_ppa_signing_key()
      File “/usr/lib/python3/dist-packages/softwareproperties/ppa.py”, line 261, in add_ppa_signing_key
      tmp_export_keyring, signing_key_fingerprint, tmp_keyring_dir):
      File “/usr/lib/python3/dist-packages/softwareproperties/ppa.py”, line 210, in _verify_fingerprint
      got_fingerprints = self._get_fingerprints(keyring, keyring_dir)
      File “/usr/lib/python3/dist-packages/softwareproperties/ppa.py”, line 202, in _get_fingerprints
      output = subprocess.check_output(cmd, universal_newlines=True)
      File “/usr/lib/python3.4/subprocess.py”, line 609, in check_output
      output, unused_err = process.communicate(inputdata, timeout=timeout)
      File “/usr/lib/python3.4/subprocess.py”, line 947, in communicate
      stdout = _eintr_retry_call(self.stdout.read)
      File “/usr/lib/python3.4/subprocess.py”, line 491, in _eintr_retry_call
      return func(*args)
      File “/usr/lib/python3.4/encodings/ascii.py”, line 26, in decode
      return codecs.ascii_decode(input, self.errors)[0]
      UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xc5 in position 92: ordinal not in range(128)

      Reply
      • Diego Muñoz V on October 16, 2019 3:47 pm

        Hello Friend
        I was able to solve the execution and update, but when installing 5.6 it can’t find it …

        I have Ubuntu 14.04

        [email protected]:~# sudo apt-get install -y php5.6
        Reading package lists… Done
        Building dependency tree
        Reading state information… Done
        E: Unable to locate package php5.6
        E: Couldn’t find any package by regex ‘php5.6’

        Reply
    5. Rahul on June 19, 2019 6:39 am

      Could you do a tutorial based on version 5.3.8 and 7.3.5 or could you suggest me the approach to it.

      Reply
    6. arthuro on February 14, 2019 10:54 am

      Even the first line doesn’t work on Ubuntu 14.04:
      > sudo apt-get install -y python-software-properties
      > E: Unable to locate package python-software-properties

      Reply
    7. Mohit on February 10, 2018 2:32 pm

      Hi Author,

      I followed your instrunctions for installing php 7.1 for ubuntu server (Ubuntu 12.04.5 LTS)
      I am getting this output (after step :sudo apt-get install -y php7.1)
      Building dependency tree
      Reading state information… Done
      E: Unable to locate package php7.1
      E: Couldn’t find any package by regex ‘php7.1’

      Adding here couple of results than could help pinpoint the issue I have

      #lsb_release -a
      LSB Version: core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-4.0-amd64:core-4.0-noarch
      Distributor ID: Ubuntu
      Description: Ubuntu 12.04.5 LTS
      Release: 12.04
      Codename: precise
      #apt-cache policy php5-cli

      Any suggestion for fixing it.

      Thanks in advance!

      Reply
      • Mohit on February 10, 2018 2:36 pm

        I forget to add output for #apt-cache policy php5-cli

        Here it is:

        php5-cli:
        Installed: (none)
        Candidate: 5.3.10-1ubuntu3.26
        Version table:
        5.3.10-1ubuntu3.26 0
        500 http://gb.archive.ubuntu.com/ubuntu/ precise-updates/main amd64 Packages
        500 http://gb.archive.ubuntu.com/ubuntu/ precise-security/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu/ precise-security/main amd64 Packages
        100 /var/lib/dpkg/status
        5.3.10-1ubuntu3 0
        500 http://gb.archive.ubuntu.com/ubuntu/ precise/main amd64 Packages

        Reply
        • Rahul K. on February 12, 2018 4:22 am

          This PPA no more supported Ubuntu 12.04 end of life version.

          Reply
          • Mohit on February 12, 2018 6:41 am

            Hi Author,

            Thanks for quick reply!
            Is there any way to upgrade php 7.0 on this server (Ubuntu 12.04.5 LTS)?

            or

            only option for me is to upgrade ubuntu to Ubuntu 16.04 LTS / Ubuntu 14.04.5 LTS ?

            Thanks in Advance!

            Reply
            • Rahul K. on February 12, 2018 1:17 pm

              Try tutorial. Make sure to backup all data before upgrading.

              https://tecadmin.net/upgrade-ubuntu-12-04-to-ubuntu-14-04/

              Reply
              • idrees Laghari on September 2, 2021 2:42 am

                Rahul k bro my website only work Ubuntu 16.04 but all vps company remove 16.04 operating system i install 18.04 but not work please contact my

              • Rahul on September 3, 2021 4:52 am

                The operating system version should not be an issue. Your application might need an older PHP version. You can try Docker to run an older PHP version on Ubuntu 16.

    8. ari on April 27, 2017 5:12 am

      Cannot add PPA: ‘ppa:~ondrej/ubuntu/php’.
      ERROR: ‘~ondrej’ user or team does not exist.

      i cannot solved this problem

      Please help Me

      Reply
      • ron on June 21, 2017 6:42 am

        me too 🙁

        [email protected]:~# add-apt-repository -y ppa:ondrej/php
        Cannot add PPA: ‘ppa:~ondrej/ubuntu/php’.
        ERROR: ‘~ondrej’ user or team does not exist.
        [email protected]:~#

        Reply
        • Rahul K. on June 21, 2017 9:11 am

          Hi Ron & Ari,

          Which Ubuntu OS version are you using? It’s working on my Ubuntu 16.04 system.

          Reply
          • Ron on June 21, 2017 1:55 pm

            My OS Version is:

            [email protected]:~# lsb_release -a
            No LSB modules are available.
            Distributor ID: Ubuntu
            Description: Ubuntu 16.04.2 LTS
            Release: 16.04
            Codename: xenial
            [email protected]:~#

            any suggest?…Thx before :),,

            Reply
            • Rahul K. on June 22, 2017 4:18 am

              Hi Ron, Try this solution

              $ apt-get install -y language-pack-en-base
              $ LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php

              Reply
    9. Jaga on March 17, 2017 7:22 am

      Excellent

      Reply
    10. Peter David Carter on December 28, 2016 5:32 pm

      This doesn’t appear to work anymore.

      [email protected]:~/upm$ sudo apt-get install -y php5.6
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      E: Unable to locate package php5.6
      E: Couldn’t find any package by regex ‘php5.6’

      Reply
      • Rahul K. on December 29, 2016 5:10 am

        Peter,
        Which OS are you using ? Its working for me.

        [email protected]:~$ sudo apt install php5.6
        Reading package lists… Done
        Building dependency tree
        Reading state information… Done
        The following additional packages will be installed:
        apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php5.6 libapr1 libaprutil1
        libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0 libssl1.0.2 php-common php5.6-cli php5.6-common
        php5.6-json php5.6-opcache php5.6-readline
        Suggested packages:
        apache2-doc apache2-suexec-pristine | apache2-suexec-custom php-pear
        The following NEW packages will be installed:
        apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php5.6 libapr1 libaprutil1
        libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0 libssl1.0.2 php-common php5.6 php5.6-cli
        php5.6-common php5.6-json php5.6-opcache php5.6-readline
        0 upgraded, 18 newly installed, 0 to remove and 415 not upgraded.
        Need to get 8,458 kB of archives.
        After this operation, 26.0 MB of additional disk space will be used.
        Do you want to continue? [Y/n]

        Reply
      • Jeroen Landheer on April 2, 2017 6:41 am

        Remember to run apt-get update after you added the PPA, otherwise your system won’t be able to find it.

        Reply
    11. phil on September 9, 2016 11:42 pm

      Hello,
      I tried installing php5.6 on Ubuntu 16.04, I followed the guide but instead of php5.6 php7.0.8 has been installed.

      Did anyone have the same problem?

      Cheers

      Reply
      • Rahul K. on September 10, 2016 8:03 am

        Hi phill,

        Actually Ubuntu 16.04 have php 7 in its default repositories. That’s why it may install with packages dependencies. Please make sure that you use following syntax with php installation, like below

        $ apt install php5.6 php5.6-mysql

        Reply
        • Aravindh on June 10, 2021 4:59 am

          HI rahul,
          i also have using ubuntu 16.04 xenial..
          No LSB modules are available.
          Distributor ID: Ubuntu
          Description: Ubuntu 16.04.7 LTS
          Release: 16.04
          Codename: xenial
          but still am facing these issues

          E: Unable to locate package php7.2
          E: Couldn’t find any package by glob ‘php7.2’
          E: Couldn’t find any package by regex ‘php7.2’

          Reply
          • Rahul on June 10, 2021 5:38 am

            Ubuntu 16.04 LTS reaches to end of life. So the packages for this have been removed from repository: https://launchpad.net/~ondrej/+archive/ubuntu/php

            Reply
      • Your Friend on September 13, 2016 7:42 pm

        If you want to toggle between versions of php you can do so with the following commands:

        i. from 7.0 to 5.6 : sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart
        ii. from 7.0 to 5.6 : sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart

        Reply
    12. NElizaga on June 25, 2016 11:40 pm

      Impressive guide.

      Reply
    13. joop on June 4, 2016 7:05 am

      Please help me , I need php 5.4 the script that I use can only work with php 5.4.

      On Ubuntu 16,04 I follow this guide , but I get php5 not found ? can not install it.

      Thank you 🙂

      Reply
    14. Van on April 26, 2016 8:05 am

      Note that for php 5.5 for an ubuntu after 14.04, you have to manually update the sources.list given by the ppa to change your current ubuntu name to trusty, then you will be able to install the php5* packages

      Reply
    15. Filip on February 5, 2016 3:25 pm

      How can I remove php5 package which is loaded from ubuntu repository? For example if I add ondrej ppa, I always install ubuntu php5. When I type command apt-cache policy php5 I can see that candidate foo installation is ubuntu version not third party which I added..

      Reply
    16. Lucas on December 19, 2015 8:04 pm

      Thank you

      Reply
    17. Baruch Youssin on November 17, 2015 7:32 pm

      Thanks for clear article.
      I would like to upgrade my PHP to 5.5 on Ubuntu 12.04.
      I have seen a 2013 post http://www.dev-metal.com/how-to-setup-latest-version-of-php-5-5-on-ubuntu-12-04-lts/
      that says that the PPA you suggest would also update Apache to 2.4 and I want to stay with Apache 2.2 for now.
      I have checked the PPA and it does list Apache 2.4 among its packages.
      Would this ppa upgrade my Apache to 2.4?
      Many thanks.

      Reply
    18. anon on September 29, 2015 11:39 am

      Totally doesnt work for php 5.5, thanks for wasting 30 secs of my time

      ubuntu 15.04

      Reply
      • James on January 6, 2016 12:51 am

        I concur. It still install 5.6.

        Reply
    19. Katsukawa on June 11, 2015 12:30 pm

      Very helpfull, thank you very much!

      Reply
    20. tquang on May 22, 2015 2:07 am

      Dear Author,

      Could you please recheck for PHP 5.4? Because I’m using Ubuntu 15.04 and no way to do this. Below are output when I entered these commands:

      W: Failed to fetch 404 Not Found
      W: Failed to fetch 404 Not Found [IP: x.x.x.x 80]

      So, I don’t complete like as your article. Please help, thank so much!

      Reply
    21. Satyam on December 20, 2014 4:21 pm

      Great work, I successfully installed php 5.6….

      Reply
      • pat'son on April 22, 2015 2:47 pm

        me, too

        Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How To Install Docker on Ubuntu 22.04
    • How to Install Bower on Ubuntu 22.04 & 20.04
    • How to run “npm start” through Docker
    • Filesystem Hierarchy Structure (FHS) in Linux
    • How to accept user input in Python
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.