• Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Install PHP 7 on MacOS

Written by Rahul, Updated on September 13, 2019

PHP stands for HyperText Preprocessor is a server-side programming language. Originally it was developed for web development but now is also used as a general-purpose language. It was created by Rasmus Lerdorf in 1994. This tutorial will help you to install PHP on macOS.

Prerequisites

Before starting the installation of Node.js and NPM using this tutorial you must have the following prerequisites

  • Terminal: You must have Mac Terminal access and little knowledge about working with the terminal application. Ao login to your Mac system and open terminal
  • Homebrew: Homebrew is a popular package manager for the Mac operating systems. It is useful for installing most open source software like Node

.

Download and Install PHP on macOS

The latest version of macOS Sierra ships with PHP 5.6 and similarly OSX 10.11 El Capitan with PHP 5.5, OSX 10.8 Mountain Lion ships with PHP version 5.3. The latest version of PHP 7.2 is available to install. The below steps to help you to install PHP 7.2 or 7.1 or 5.6 on macOS.

Open a terminal and run below commands

Install PHP 7.3

curl -s http://php-osx.liip.ch/install.sh | bash -s 7.3

Install PHP 7.2

curl -s http://php-osx.liip.ch/install.sh | bash -s 7.2

Install PHP 7.1

curl -s http://php-osx.liip.ch/install.sh | bash -s 7.1

Install PHP 5.6 – Running with OSX 10.11 El Capitan or lower versions.

curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6

Verify PHP Installation

The PHP versions for macOS are maintained by php-osx and doesn’t overwrite the current php binaries installed on your system. The installs everything in /usr/local/php5. The new php binary is therefore in /usr/local/php5/bin/php.

export PATH=/usr/local/php5/bin:$PATH  

To verify the correct version of PHP is installed on your system, Execute the following command.

php -v  

PHP 7.2.2 (cli) (built: Feb  1 2018 13:23:34) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.2, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans

Also, create a phpinfo.php under your web root directory with the following contents and access the file in web browser.

1
<?php phpinfo();?>

Revert PHP to Default

Don’t you need the latest installed PHP? Simply edit the /etc/apache2/httpd.conf and uncomment below the line.

From:

LoadModule php5_module /usr/local/php5/libphp5.so

to

LoadModule php5_module libexec/apache2/libphp5.so

And delete the files +php-osx.conf and +entropy-php.conf from /etc/apache2/other directory.

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

12 Comments

  1. Avatar Ed Green Reply
    December 28, 2020 at 12:21 am

    And how to install php 8 without homebrew?

  2. Avatar Thomas Reply
    November 10, 2020 at 10:54 am

    how do i delete it?

  3. Avatar Ray Winestone Reply
    May 9, 2020 at 9:45 am

    I have installed php as detailed above for a Mac.

    The commmand php is working but the php info page is not

  4. Avatar peterdv3 Reply
    January 23, 2020 at 10:07 pm

    I followed the download link for 7.3 and it installed 7.3.8, no problems

  5. Avatar Alan Reply
    September 21, 2019 at 11:14 am

    I dunno if its me but mine auto reverts back to PHP7.1 despite I have installed 7.3. Anyone got an idea why or if they’re having the same issue

    • Avatar Daniel Reply
      September 24, 2019 at 7:51 pm

      Same here

    • Avatar Tony G Reply
      February 20, 2020 at 4:31 pm

      Same here.

  6. Avatar Allan Reply
    September 18, 2019 at 8:12 pm

    Thanks. Absolutely helpful.

  7. Avatar Juanmi Reply
    June 10, 2019 at 5:24 pm

    very helpful, thank you so much

  8. Avatar nacim Reply
    December 21, 2018 at 7:21 pm

    Very good work ! you saved me 🙂 i was looking for how to update my mac from 7.1 to 7.2 , since 3 days , by chance i found your post i solved my problem thanks your tuto in 2 secondes ! , i thank you 🙂

    • Avatar Tony G Reply
      February 20, 2020 at 4:34 pm

      How did you get PHP to default to 7.2 on your MAC? I just installed php 7.3 but PHP -version shows version 7.1 still. I can’t find how to make it default to version 7.3 – if you know please tell me because this blog entry doesn’t have the answer. – Thanks!

  9. Avatar Website Design Oakville Reply
    November 9, 2018 at 8:47 am

    Hello there, I found your blog via Google search, and found
    that it’s informative truly. I’ll appreciate if you continue
    this in future. Lots of individuals will be benefited from the given information
    you have provided.
    Cheers!

Leave a Reply Cancel reply

Popular Posts

  • How to View or List Cron Jobs in Linux
  • How to Install PHP 8 on Ubuntu 20.04
  • How to Set Up SSH Tunnel with PuTTY
  • How to Install Tor Browser on Ubuntu 20.04
  • Issue with phpMyAdmin and PHP: Warning in ./libraries/sql.lib.php#613 count(): Parameter must be an array or an object that implements Countable”
  • How to Allow Remote Connections to MySQL
  • How to Install MySQL 8.0 on Ubuntu 20.04
  • How to Install Apache Kafka on Ubuntu 20.04
© 2013-2021 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy