PHP stands for HyperText Preprocessor is a server-side programming language. Originally it was developed for the web development but now it 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.
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 sofware 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
For PHP 7.2
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.2
For PHP 7.1
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.1
For 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.
To verify 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.
Revert PHP to Default
Don’t you need the latest installed PHP? Simply edit the /etc/apache2/httpd.conf and uncomment below the line.
LoadModule php5_module /usr/local/php5/libphp5.so
LoadModule php5_module libexec/apache2/libphp5.so
And delete the files +php-osx.conf and +entropy-php.conf from /etc/apache2/other directory.