Run PHP Scripts on macOS

This section provides notes to verify PHP version supported on macOS and run a simple PHP interactive scripting session.

PHP is a popular scripting language for generating dynamic Web pages. macOS supports PHP out-of-the-box. You don't have to do any installation.

You can start a Terminal window and try to run PHP scripts interactively as shown below:

herong$ php -version
PHP 5.6.30 (cli) (built: Feb  7 2017 16:18:37)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

herong$ php -a
Interactive shell

php > print "Hello world!\n";
Hello world!

php > exit

You can also get a detailed list of modules supported in PHP by running the "php -i" command:

herong$  php -i | more
phpinfo()
PHP Version => 5.6.30

System => Darwin local 16.7.0 Darwin Kernel Version 16.7.0:
   Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
Build Date => Feb  7 2017 16:11:14
Configure Command =>  '/Library/Caches/com.apple.xbs/Binaries/apache_mod_php
   /apache_mod_php-117.2~3/TempContent/Objects/php/configure'
   '--mandir=/usr/share/man' '--infodir=/usr/share/info'
   '--disable-dependency-tracking' '--sysconfdir=/private/etc' ...

Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini

curl

cURL support => enabled
cURL Information => 7.54.0
Age => 3
Features
AsynchDNS => Yes
CharConv => No
Debug => No
...

Table of Contents

 About This Book

 Macintosh OS (Operating System) History

 macOS Operating System

 macOS File Systems

 macOS Network Connections

 System and Application Processes

 Keychain Access - Password Manager

 Keychain Access - Certificate Manager

 Productivity Tools on macOS

Programming Tools on macOS

 Run Perl Scripts on macOS

 Install File::Util for Perl

 Run Python Scripts on macOS

 Install New Version of Python on macOS

 pip3 - Package Installer for Python 3

Run PHP Scripts on macOS

 Install MySQL Database Server on macOS

 PHP mysqli_connect() Error on "localhost"

 Install SQuirreL SQL Client on macOS

 Connect SQuirreL to MySQL on macOS

 Install SQuirreL SQL Scripts Plugins

 Apache Web Server on macOS

 Develop and Run Java Applications

 Full Version in PDF/EPUB