Check php version mac terminal

There are several possibilities to check and validate PHP version on Linux.

1. Open a bash shell terminal and use the command “php –version” or “php -v” to get the version of PHP installed on the system.

# php --version
PHP 5.4.16 (cli) (built: Mar  7 2018 13:34:47) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

# php -v
PHP 5.4.16 (cli) (built: Mar  7 2018 13:34:47) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

As you can see from both the command output above, the system has PHP 5.4.16 installed.

2. You can also check for the package versions installed on the system to get the PHP version.
On RedHat Based Distributions :

# rpm -qa | grep php
php-common-5.4.16-43.el7_4.1.x86_64
php-pdo-5.4.16-43.el7_4.1.x86_64
php-mysql-5.4.16-43.el7_4.1.x86_64
php-mbstring-5.4.16-43.el7_4.1.x86_64
php-cli-5.4.16-43.el7_4.1.x86_64
php-gd-5.4.16-43.el7_4.1.x86_64
php-5.4.16-43.el7_4.1.x86_64

On debian based distributions :

# apt list --installed | grep php

3. Let’s create a PHP file with content as shown below. The phpinfo() function outputs a great deal of information about the state of the current PHP environment, including loaded extensions, compilation options, version, server information, and so on.

# echo "" > /var/www/html/phpinfo.php

4. Now, considering that Apache is installed and working, open a browser and test PHP using address as follow:

http://server/phpinfo.php

Check php version mac terminal

Here's How to Check the Version of PHP You're Running

A Simple Command to Check Your PHP Information

Paul Bradbury/Getty Images

Updated on September 20, 2018

If you can't get something to work and think it might be because you have the wrong version of PHP, there's a really simple way to check the current version. 

Different versions of PHP may have different default settings, and in the case of newer versions, might have new functions.

If a PHP tutorial is giving instructions for a particular version of PHP, it's important to understand how to check the version you have installed.

How to Check the PHP Version

Running a simple PHP file will not only tell you your PHP version but an abundance of information about all your PHP settings. Just put this single line of PHP code in a blank text file and open it on the server:

Below is how to check the locally installed version of PHP. You can run this in Command Prompt in Windows or Terminal for Linux/macOS.

php -v

Here's an example output:

PHP 5.6.35 (cli) (built: Mar 29 2018 14:27:15)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

Is the PHP Version Not Showing in Windows?

Given that you actually are running PHP on your web server, the most common reason for the version of PHP not showing up is if the path to PHP is not set up with Windows.

You might see the error like this if the correct environment variable isn't configured:

‘php.exe’ is not recognized as an internal or external command, operable program or batch file.

In a Command Prompt, type the following command, where the path after "C:" is the path to PHP (yours may be different):

set PATH=%PATH%;C:\php\php.exe

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:

WARNING: PHP is not recommended
PHP is included in macOS for compatibility with legacy software.
Future versions of macOS will not include PHP.

However, don't be scared. It's pretty easy to install PHP and even install multiple versions if you like.

Installing Homebrew

When 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:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Installing PHP with Homebrew on Mac

To install PHP, we can run the following command:

brew install php

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.

brew update
brew doctor

Installing PHP 7.4 with Homebrew

In 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.

brew install [email protected]

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 php -v command, we might still see a different version like PHP 7.3.14 (CLI) or whatever you have installed.

To fix this, we need to link the correct PHP version.

Switching PHP Versions with Homebrew on Mac

Now that we installed versions, we can easily switch between them using the link command.

First, check which version of PHP is currently running:

php -v

# PHP 8.0.1 (cli) (built: Jan  8 2021 01:27:28) ( NTS )
# Copyright (c) The PHP Group

Then we can unlink that version by using:

brew unlink [email protected]

The next step is to link the version we want:

brew link [email protected]

It will tell you to run a script to add the path:

echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

This will make sure the right PHP version is loaded, now if you run php -v again it should show:

# PHP 7.4.14 (cli) (built: Jan  8 2021 01:35:35) ( NTS )
# Copyright (c) The PHP Group

And there we go. We switched to the PHP version.

Php -v is still showing the wrong version

I had the issue when upgrading from 7.4 to 8.0 for my demo that I kept seeing 7.4 when running php -v. Remove the old line in your .zshrc file to fix this manually.

nano ~/.zshrc

Remove the line that points to your old instance of PHP.

export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"

Note: This is an example of my version. It might differ from what you installed before.

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

How do I check PHP version on 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..

What version of PHP do I have terminal?

Open a bash shell terminal and use the command “php –version” or “php -v” to get the version of PHP installed on the system.

Is PHP already installed on Mac?

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.

Where does PHP get installed on Mac?

Set the php. ini location or use the default A typical default location on macOS is /usr/local/php/php.