Home  >  Article  >  Backend Development  >  How to install PHP7 on macOS

How to install PHP7 on macOS

不言
不言Original
2019-04-08 09:40:133972browse

PHP stands for HyperText Preprocessor and is a server-side programming language. Initially it was developed for web development but now it is also used as a general purpose language. This article will introduce you to installing PHP on macOS.

How to install PHP7 on macOS

Requirements

Before you start installing node.js and npm, you must meet the following conditions

Terminal: Must have Mac Terminal access.

homebrew: homebrew is a popular package manager for Mac operating systems. It is suitable for installing most open source software such as Node.

Download and Install PHP on MacOS

The following steps help install PHP 7.2 or 7.1 or 5.6 on macOS.

Open a terminal and run the following command

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

Works with PHP 5.6 - Runs with OSX 10.11 El Capitan or lower.

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

Verify PHP Installation

The version of PHP for MacOS is maintained by php osx and will not overwrite the current php binaries installed on the system. Installed in /usr/local/php5. Therefore, the new php binary is located in /usr/local/php5/bin/php.

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

To verify that 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 in the web root directory with the following content and access the file in the web browser.

<?php phpinfo();?>

Restore php to default

If you don't need the latest installed PHP, just edit /etc/apache2/httpd.conf and uncomment the line below .

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 the /etc/apache2/other directory.

This article has ended here. For more other exciting content, you can pay attention to the PHP Video Tutorial column on the PHP Chinese website!

The above is the detailed content of How to install PHP7 on macOS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn