How to install php in mac
Show
Submit a Pull Request Report a Bug Table of Contents
This section contains notes and hints specific to installing PHP on macOS. PHP is bundled with macOS since macOS X (10.0.0) prior to macOS Monterey (12.0.0). Compiling is similar to the Unix installation guide. +add a note User Contributed NotesThere are no user contributed notes for this page. PHP is missing in MontereyStarting with macOS Monterey, PHP is no longer included in a default installation of the system. If you want to use PHP on macOS Monterey, you must first install PHP. The following instructions show the Terminal commands to install PHP. To enter a Terminal command, you can copy it from your web browser to the clipboard and then paste it in Terminal and hit the return key to execute the command. Installing HomebrewTo install Homebrew, see
the instructions on the Homebrew installation page and the Homebrew home page. brew --version Installing PHPOnce Homebrew is installed, enter the following command to install PHP: brew install php This will take a while and will produce some output in the Terminal window. At the end, when you see the input prompt again, check the path of "php" with the following command: command -v php The command should display something like /usr/local/bin/php or /opt/homebrew/bin/php Now PHP is ready, and you can run PHP scripts on your computer. Running PHP scriptsScripts start with a
"shebang" line that tells the system where it can find the interpreter for the script language. Up to macOS Big Sur, PHP was pre-installed in the location /usr/bin/php, but now PHP lives at a different path. You will therefore need to update the shebang line in PHP scripts to #!/usr/bin/env php Using PHP in TypinatorIn Typinator, you can use PHP scripts in expansions in two ways: a) You can store external scripts in the Includes/Scripts folder and then include invocations of these scripts in Typinator expansions. If you already have used PHP scripts before, you need to update the shebang lines in these scripts, as described above in "Running PHP scripts". b) You can include inline scripts in expansions. A simple inline script in PHP would be: In this case, Typinator knows where to find the PHP interpreter in both Monterey and in older versions of macOS, but you need at least Typinator 8.11 to run PHP scripts on Monterey. Older versions of Typinator will display an error message that says "script RunPHP.php failed". Typinator 8.11 and newer will even check whether PHP is installed, and it helps you with the installation by displaying these instructions in a web browser. Get more information about Typinator here. I've got a brand new Mac yesterday and noted that it states PHP will be removed from future Mac OS versions by default. I'm pretty surprised they go this way. By default, it comes with PHP 7.3, and I needed 7.4 for my project so let me guide you through setting up PHP on your Mac! Mac's warning looks like this:
However, don't be scared. It's pretty easy to install PHP and even install multiple versions if you like. Installing HomebrewWhen it comes to installing software on your Mac, we need only one package manager, and it's Homebrew. It can install any package or software you want and even install specific versions. Read more on Homebrew - Package manager for Mac. Quick guide: Run the following command in your terminal:
Installing PHP with Homebrew on MacTo install PHP, we can run the following command:
This will install the latest stable version of PHP (At the moment of writing, this is PHP 8.0). Before running any brew commands, it's a good habit to run the following commands first. These will check if Homebrew is all up to date and running the latest versions.
Installing PHP 7.4 with HomebrewIn my case, I wanted to install PHP 7.4 since it's the version our server is running. To install a specific version, we can use the @ notation.
This will run the installer, and it should end with a success notice in your terminal. However, even though this installed PHP, it didn't change our running instance yet. So if we run the To fix this, we need to link the correct PHP version. Switching PHP Versions with Homebrew on MacNow that we installed versions, we can easily switch between them using the First, check which version of PHP is currently running:
Then we can unlink that version by using:
The next step is to link the version we want:
It will tell you to run a script to add the path:
This will make sure the right PHP version is loaded,
now if you run
And there we go. We switched to the PHP version. Php -v is still showing the wrong versionI had the issue when upgrading from 7.4 to 8.0 for my demo that I kept seeing 7.4 when running
Remove the line that points to your old instance of PHP.
Thank you for reading, and let's connect!Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter Can you download PHP on Mac?PHP is bundled with macOS since macOS X (10.0.
How do I know if PHP is installed Mac?2 Answers. Go to File > Preferences > User Settings > Settings.json.. Change the value of php. validate. executablePath according to the installed directory of php7. "php.validate.executablePath": "/Applications/MAMP/bin/php/php7.0.14/bin/php". Relaunch VM Code.. How do I run PHP 8 on Mac?By right the steps will also work for the previous macOS versions like Catalina and Mojave.. Step 1: Install Homebrew. ... . Step 2: Install PHP. ... . Step 3: The php. ... . Step 4: Check if PHP is running. ... . Step 5: Checking PHP Version.. How install PHP install?How to Install PHP. Step 1: Download the PHP files. You'll need the PHP Windows installer. ... . Step 2: Extract the files. ... . Step 3: Configure php. ... . Step 4: Add C:\php to the path environment variable. ... . Step 5: Configure PHP as an Apache module. ... . Step 6: Test a PHP file.. |