| layout | post | ||||||
|---|---|---|---|---|---|---|---|
| date | 2026-06-13 | ||||||
| lastchange | 26-06-13 v003 new from wilsonmar @macos-php.md | ||||||
| url | https://bomonike.github.io/macos-php | ||||||
| file | php-on-apple-mac-osx | ||||||
| title | PHP On macOS | ||||||
| excerpt | What a Pretty Hypertext Preprocessor (PHP)! | ||||||
| tags |
|
||||||
| image |
|
||||||
| comments | true | ||||||
| created | 2014-08-09 |
{{ page.excerpt }} {% include l18n.html %} {% include _toc.html %}
-
The marketing landing page for the PHP language is:
renowned voices in the PHP community, including Larry Garfield, Fabien Potencier, Nils Adermann, Elizabeth Barron,
-
Documentation
"Zend PHP Certified Engineer" is a well-known vendor-specific exam for PHP developers. For $200 for testing or $1295 with a class to Perforce,
"PHP Developer Fundamentals" exam from IC3 (administered by Pearson) is the entry-level PHP exam. Answer 70% of 40 questions over 50 minutes online Certiport Console 8. The IC PHP covers nine domains of knowledge and skill:
- Development Environment: Web server and database MySQL/MariaDB PhPMyAdmin
- PHP Fundamentals: General notions Style programming Limitation structure of the data Manage the output of PHP script
- Conditional instruction of control and cycles: Repetitive operations
- Complex data structures: Arrays
- PHP code management: Re-use the PHP code Functions for the variables management The functions for the management, comparison and string formatting The functions for the management of the complex structures of data The functions for the management of the dates Customized functions Send email in PHP
- Data recovery and check in an HTML form
- Maintain information in PHP: Sessions
- The DBMS MySQL and MariaDB
- Interaction with I DBMS MySQL and MariaDB
To add generative AI to PHP programs, you can use LLPhant, a comprehensive PHP Generative AI Framework using OpenAI GPT 4 Inspired by Langchain. Install it using command "composer require theodo-group/llphant".
https://www.youtube.com/watch?v=lTr06V9uyts
If it's installed, the version of PHP is obtained from this Terminal command:
php -v
If you get a response, see the Install section below.y
A Pretty Hypertext Preprocessor (PHP) was included by Apple on OS X (before MacOS):
On Mojave, the response was:
PHP 7.1.23 (cli) (built: Feb 22 2019 22:19:32) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
On Sierra, the response was:
PHP 5.6.28 (cli) (built: Dec 6 2016 12:38:54) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
On Yosemite, the response was:
PHP 5.5.14 (cli) (built: Sep 9 2014 19:09:25) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
For the location of the PHP being used by the command line:
which php
On my Yosemite, the response is:
/usr/bin/php
-
Install using Homebrew:
yes brew install php
-
Get version:
php -v
For example:
PHP 8.5.7 (cli) (built: Jun 2 2026 20:59:56) (NTS) Copyright (c) The PHP Group Built by Homebrew Zend Engine v4.5.7, Copyright (c) Zend Technologies with Zend OPcache v8.5.7, Copyright (c), by Zend Technologies
-
The history of PHP releases are at:
-
Scroll down to the latest (largest) version for "OS X" and click "Download" of the macOS installer (.dmg), not a VM image from:
https://www.apachefriends.org/download.html
The most popular PHP development environment is XAMPP, an acronym of components:
- Apache
- MariaDB
- PHP
- Perl
XAMPP is Windows-focused.
WARNING: Don's use XAMPP to develop Nextcloud which officially doesn't support Windows. You'll fight with PHP extensions (gd, mysqli, mbstring), mod_rewrite, and permissions.
- Click "Downloads" folder, then "Save" in the pop-up to store file such as "xampp-osx-8.2.4-0-installer.dmg".
- Click the downloads icon in your browser and click the file you just downloaded.
- Double-click the "installer.app" file
- Let the pop-up.
- Click the Apple icon at the upper-left corner to open System Settings app.
- Click "Privacy & Security" in the menu.
- Scroll to the Security section. Next to the message that XAMPP was blocked, click "Open Anyway". Again.
- Click Open Anyway and enter your password.
- The Setup app should pop up. In the XAMPP Setup Wizard, click "Next" repeatedly.
- Quit the installer app.
-
Start manager-osx.app (Application Manager) in ~/Applications/XAMPP From the CLI,
open -a manager-osx.app
-
Click "Open Application Folder" xampfiles in a new Finder window.
-
Click "Managed Servers", select "MySQL database" and click Start. Select "Apache Web Server" and click Start.
-
Click "Configure". Notice the port defaults to 3306.
-
Verify it works: Open a browser and go to: http://localhost:3306
You should see the XAMPP dashboard.
-
Start using CLI command (requires password entry):
sudo /Applications/XAMPP/xamppfiles/xampp start && sleep 2 && echo "================ STATUS ================" && sudo /Applications/XAMPP/xamppfiles/xampp status
or individually:
sudo /Applications/XAMPP/xamppfiles/xampp startapache sudo /Applications/XAMPP/xamppfiles/xampp startmysql
-
CLI to check whether services are running:
curl -sSI http://localhost/ | head -n 1 # Apache: expect "HTTP/1.1 200 OK" (or 3xx) nc -z -v localhost 3306 # MySQL/MariaDB: "succeeded" = port open nc -z -v localhost 21 # ProFTPD: FTP port
-
Install Visual Studio Code
-
Click "Configure", then "Open Config file". OK.
-
Can copy file to /etc/my.cnf to set global options.
-
~/.my.cnf to set user-specific options.
-
from /Applications/XAMPP/xamppfiles/var/mysql) mysql-data-dir/my.cnf to set server-specific options
-
Sample program: Convert Celsius to Fareinheit temperature.
$c = ($f - 32) * (5 / 9); echo $c from $f
-
HTML files
-
commands between It's also executed to HTML inside a // comment.
-
comment code out as a block using /* */ tags
-
semicolons after each statement
-
Constants
-
$Variables
-
Numbers, Strings and Operators: single quotes between double quotes.
-
Predefined Variables
-
Attributes #[Attribute]
-
Expressions
-
Operators
-
Control Structures
-
Enumerations
-
Errors
-
Exceptions
-
Predefined Exceptions
-
Fibers (Fibers pause the entire execution stack, so the direct caller of the function does not need to change how it invokes the function. Fibers are full-stack, interruptible functions. May be suspended from anywhere in the call-stack, pausing execution within the fiber until the fiber is resumed at a later time.)
-
Namespaces
-
References Explained
-
Predefined Interfaces and Classes
-
Predefined Attributes
-
Context options and parameters
-
Video courses on PHP by Coursera: https://www.coursera.org/search?query=php
- Intro to PHP" LAMP stack using MariaDB
To activate PHP using the Pico text editor that comes with Macs:
sudo pico /etc/apache2/httpd.conf
Within pico, press Ctrl+W and type php to search for the php5_module statement.
Press cursor key left to the right of the # comment character, press the backspace key to delete it. PHP is activated after you press Ctrl+X and Ctrl+Y to confirm Yes.
Alternately, to activate PHP using the vi text editor that also comes with Macs:
sudo vi /etc/apache2/httpd.conf
To find php...
Press 'x' over the '#' character to delete it.
Type ':w!' to save. Type 'ZZ' (upper case) to quit.
Only for Yosemite, also uncomment line 166:
LoadModule userdir_module libexec/apache2/mod_userdir.so
And also line 493:
#Include /private/etc/apache2/extra/httpd-userdir.conf
To activate PHP using the pico text editor that comes with Macs:
cd /private/etc
Copy the default file to a .ini file:
sudo cp php.ini.default php.ini
For Yosemite only, open the file with:
sudo vi /etc/apache2/extra/httpd-userdir.conf
Uncomment line 16:
#Include /private/etc/apache2/users/*.conf
Save and exit.
Ensure that your user name is listed within:
ls -la /etc/apache2/users
In addition to the Guest.conf listed, there should be a .conf file with your Mac user name (mine is wilsonmar).
Such file may not be created while upgrading to Mountain Lion. Contents of this file is different on Yosemite:
<Directory "/Users/wilsonmar/Sites/"> AddLanguage en .en LanguagePriority en fr de ForceLanguagePriority Fallback Options Indexes MultiViews AllowOverride None Order allow,deny Allow from localhost Require all granted </Directory>
By popular convention, the Sites folder (with a capital S) is used to store website files. Create one under the default /Applications folder from the command line:
mkdir ~/Sites
Create a HTML file to display by default when no file is specified:
echo "<html><body><h1>My site works</h1></body></html>" > ~/Sites/index.html.en
/Library/WebServer/Documents/index.html.en . This contains the text "It works!"
Older versions of Apache had a UI in System Preferences > Sharing and enable Web Sharing. But on Yosemite:
Within a Terminal:
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
Check the version of Apache installed:
httpd -v
The response on my Yosemite is:
Server version: Apache/2.4.9 (Unix)
Server built: Sep 9 2014 14:48:20
See http://coolestguidesontheplanet.com/get-apache-mysql-php-phpmyadmin-working-osx-10-10-yosemite/
http://coolestguidesontheplanet.com/install-mcrypt-php-mac-osx-10-10-yosemite-development-server/
To add modules to PHP, add libmcrypt-2.5.8 and PHP source code from http://us.php.net/get/php-5.5.14.tar.gz/from/a/mirror using these instructions: http://michaelgracie.com/2011/07/21/plugging-mcrypt-into-php-on-mac-os-x-lion-10-7/
Building Web Applications in PHP from University of Michigan Best for: intermediate learners, students with months to commit, and those aiming to build full web applications with User Interfaces formatted using CSS.
Full-Stack Web Development: PHP, HTML, CSS & JavaScript from Board Infinity Best for: beginners interested in full-stack development, learners with a few months available, and those wanting a specialization credential
Building Database Applications in PHP from University of Michigan Best for: intermediate developers, learners focused on database skills, and those ready to enhance PHP with MySQL integration
Introduction to VueJS Framework from Codio Best for: beginners with 1-4 weeks availability, learners new to Vue.js, and those seeking foundational web development skills
The Complete Vue.js Course for Beginners from Packt Best for: beginners with 1-3 months to learn, those interested in JavaScript frameworks, and learners preferring comprehensive beginner courses
Vue.js 3 for Beginners: Build Modern Web Applications from Packt Best for: intermediate learners with 3-6 months commitment, developers focusing on modern web apps, and those wanting to master Vue.js 3 features
Fundamentals of VueJS from Board Infinity Best for: intermediate learners with short-term availability, web developers interested in JavaScript frameworks, and those aiming to strengthen Vue.js fundamentals
This is one of a series on Mac OSX:
{% include mac_links.html %}
{{ page.lastchange }} created {{ page.created }}