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.
And how to install php 8 without homebrew?
how do i delete it?
I have installed php as detailed above for a Mac.
The commmand php is working but the php info page is not
I followed the download link for 7.3 and it installed 7.3.8, no problems
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
Same here
Same here.
Thanks. Absolutely helpful.
very helpful, thank you so much
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 🙂
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!
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!