Wilson Mar bio photo

Wilson Mar

Hello!

Calendar YouTube Github

LinkedIn

What a Pretty Hypertext Preprocessor!

US (English)   Norsk (Norwegian)   Español (Spanish)   Français (French)   Deutsch (German)   Italiano   Português   Estonian   اَلْعَرَبِيَّةُ (Egypt Arabic)   Napali   中文 (简体) Chinese (Simplified)   日本語 Japanese   한국어 Korean

Overview

A Pretty Hypertext Preprocessor (PHP) is included by Apple on MacOS.

PHP Version and Location

The version of PHP is obtained from this Terminal command:

php -v

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

Activate PHP for Apache

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

Activate php.ini

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

Enable Apache

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.

Specify Mac User Name in Apache

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>

Establish Sites folder PHP website default file

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 “&LT;html>&LT;body>&LT;h1>My site works&LT;/h1>&LT;/body>&LT;/html>” > ~/Sites/index.html.en

/Library/WebServer/Documents/index.html.en . This contains the text “It works!”

Launch Apache

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</tt>

See http://coolestguidesontheplanet.com/get-apache-mysql-php-phpmyadmin-working-osx-10-10-yosemite/

Libmcrypt PHP

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/

More on OSX

This is one of a series on Mac OSX: