How to Install PHP on MacOS? | GeeksforGeeks

https://www.geeksforgeeks.org/how-to-install-php-on-macos/

How to Install PHP on MacOS?

Last Updated : 21 Dec, 2021

 Homebrew Installation command
installing home brew 2
install PHP 8 using brew
Check the version of PHP installed on your Mac

PHP (Hypertext Preprocessor) is known as a general-purpose scripting language that can be used to develop dynamic and interactive websites. It was among the first server-side languages that could be embedded into HTML, making it easier to add functionality to web pages without needing to call external files for data.

Originally PHP was developed for web development but now is also used as a general-purpose language. It was created by Rasmus Lerdorf in 1994. 

This article will help you to set up PHP@8.0 or any version on macOS.

null

Installing PHP on macOS :

So we start by installing HomeBrew, if you haven’t installed you can navigate to the link by clicking here.  

Step 1: Copy the installation command.Installation command

Step 2: Next, paste the copied command in the Terminal. 

It will now ask for your ‘sudo’ password, So provide your account password. And press RETURN to continue with the installation.

After a few seconds depending upon your internet speed, you should see the output  “Installation successful!” message.

https://aa74acda6d26bf8aef72268d163f1141.safeframe.googlesyndication.com/safeframe/1-0-45/html/container.html

Step 3: Now, we will enter the below command to update our packages:

brew update   

In this case, we are already up-to-date.

In case if you are getting the ‘brew’ command not found error. You have to run two commands to add Homebrew to your PATH: 

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"'

Note: Below, Substitute ‘<username>’ to the username of your macOS account.

>> /Users/<username>/.zorofile eval "$(/opt/homebrew/bin/brew shellenv)"

Now you can update packages.

Step 4: Before we can install PHP, we need to install a third-party repository with a brew tap

Enter the following command.

brew tap shivammathur/php

Step 5: Now, we are all set and we can install PHP 8 using brew install.

brew install shivammathur/php/php@8.0

Of course,  you can change the version to another one, if you are interested in a different version.

If everything worked, you should now see the selected output below.

And PHP 8.0 is now installed on your MacBook.

Step 6: You need to have PHP@8.0 first in your PATH, to do that run the two following commands:

echo 'export PATH="/opt/homebrew/opt/php@8.0/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/php@8.0/sbin:$PATH"' >> ~/.zshrc

For compilers to find php8.0 you may need to set:

export LDFLAGS="-L/opt/homebrew/opt/php@8.0/lib"
export CPPFLAGS="-I/opt/homebrew/opt/php@8.0/include"

Close and restart Terminal to load new settings.

Check the Version of PHP Installed on your MacOS:

Run the following command to check.

php -v

You can see the version of PHP installed on your MacOS.

Congratulations! You now have installed PHP with associated extensions running on your Mac development environment.

Next Article

rishabhsinha20

Article Tags :

Similar Reads

geeksforgeeks-footer-logo

Corporate & Communications Address:

A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)

Registered Address:

K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305

GFG App on Play Store
GFG App on App Store

Advertise with us

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

Lightbox

Leave a comment

Design a site like this with WordPress.com
Get started