Subscribe / Unsubscribe Enewsletters | Login | Register

Pencil Banner

How to set up and learn PHP in OS X

Lucy Hattersley | July 6, 2016
Create great web pages using PHP on an Apple Mac

Learning PHP is a good idea. PHP (a recursive acronym for PHP Hypertext Preprocessor) is a scripting language. It's the power behind some of the biggest websites on earth, including Facebook, Wikipedia, and Wordpress.

Learning PHP puts you in good stead as a programmer. You'll come across PHP all the time when working on websites, and it's a great way to add programming oomph to your HTML and CSS-based website. PHP enables you to script virtually anything.

PHP is the quintessential marmite of programming languages. Many professionals rate it quite badly, partly because it's so easy for beginners to use (which leads to a lot of mistakes); also it carries a lot of legacy code, which makes it clunky compared to Ruby or Javascript.

Don't let the naysayers distract you. If you want to create code online, then you must spend time learning how PHP works.

How to set up and learn PHP in OS X: what is PHP?

Install PHP in OS X

PHP is a general-purpose scripting language. While HTML displays text and CSS styles it up, PHP is a programming language that can automate tasks. It's often used to get information from the user, or make API (Application Programming Interface) calls to other websites and online services. You can control program flow and logic gates in PHP, and use it as a programming language.

PHP is slightly different from Javascript (a similar language) in that the code runs on your server, and then HTML is sent to the browser. So the browser gets the results, but can't see the code. Running code on the server side makes PHP good for security, as the browser doesn't get to see the code. It also means PHP isn't dependent on browser speed or setup.

How to learn PHP: Setting up PHP in OS X

Mac OS X comes with PHP prepackaged. So there isn't much you need to do to install PHP. Open a Terminal window and enter php --version to check which version you have installed. If you're running OS X El Capitan, you will see PHP 5.5.31 (or later). Ours says "PHP 5.5.31 (cli) (built: Feb 20 2016 20:33:10)".

The latest stable release is PHP 7.0, which you can install via Homebrew using brew install php70. If you don't have Homebrew, then you can install it using the script at the Homebrew website.

However, we'd advise you to stick with PHP 5.5 in the short term. While PHP 7.0 adds a lot of cool new features, most tutorials use PHP 5.5, and it's still the version commonly used in most programming environments.


1  2  Next Page 

Sign up for CIO Asia eNewsletters.