How do i find php version on mac?

The solutions above did not work for me on Big Sur I kept on getting:

WARNING: PHP is not recommended
PHP is included in macOS for compatibility with legacy software.
Future versions of macOS will not include PHP.
PHP 7.3.24-[to be removed in future macOS] [cli] [built: Dec 21 2020 21:33:25] [ NTS ]
Copyright [c] 1997-2018 The PHP Group
Zend Engine v3.3.24, Copyright [c] 1998-2018 Zend Technologies

To fix this I used the following steps:

Step 1 | Tap into another repository of formulae

brew tap shivammathur/php

Step 2 | Install the desired PHP version

brew install shivammathur/php/

Other options are:







 
 or known as just PHP

Step 3 | Link the PHP Version

brew link --overwrite --force 

Step 4 | Restart Terminal

Step 5 | Check PHP version

php -v

You should now see the new version.

PHP 7.4.25 [cli] [built: Oct 21 2021 00:29:22] [ NTS ]
Copyright [c] The PHP Group
Zend Engine v3.4.0, Copyright [c] Zend Technologies
    with Zend OPcache v7.4.25, Copyright [c], by Zend Technologies

This also solved my issues with PHP syntax in Visual Studio Code.

Here are some quick tips on how to check the PHP version on your computer or server.

There are several reasons why you want to check the version of PHP which is installed on your server. For example, you might want to install PHP-based software and to check if the software requirements match the PHP version installed on your server. Or you might be a developer who wants to use a feature which is only available in specific versions of PHP. 

There are a lot of different PHP versions, and they have some noticeable differences among them. With every new PHP version, new features are added and others are deprecated, so it’s always good to know the PHP version you’re using.

There are a few different ways to check the PHP version. Mainly, if you have SSH access to your server, you can use the command-line interface to check it. On the other hand, if you don’t have terminal access, I’ll show you how to check the PHP version using the phpinfo function.

Check the PHP Version by Using the Terminal

In this section, we’ll discuss how you could check the PHP version by using the command-line interface [CLI] in a terminal.

Check the PHP Version on Unix, Linux, and macOS

For *nix-based systems—Linux, Unix, and macOS—it just takes a single command to check the PHP version. Go ahead and run the following in your terminal.

php -v

You should see an output like the following:

PHP 7.2.24-0ubuntu0.18.04.3 [cli] [built: Feb 11 2020 15:55:52] [ NTS ]
Copyright [c] 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright [c] 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24-0ubuntu0.18.04.3, Copyright [c] 1999-2018, by Zend Technologies

As you can see, this gives you comprehensive information about the PHP version which is installed on your server. In the above output, the 7.2.24 version of PHP is installed on the server.

Check the PHP Version on Windows

For Windows users, the same command is used to check the PHP version. But you might get an error if you don't set the PATH environment variable first. You can do that by running the set PATH command. Run the following commands, and make sure that you replace the {PATH_TO_PHP_DIRECTORY} placeholder with the directory path where you’ve installed PHP. For example, if you installed PHP in the C:\software\php directory, you need to run set PATH=%PATH%;C:\software\php.

set PATH=%PATH%;{PATH_TO_PHP_DIRECTORY}
php -v

If you don’t want to set the PATH environment variable, you could also go to the directory where you’ve installed PHP and run the php -v command from there.

cd C:\softwares\php
php -v

So that was a brief introduction to the CLI option to check the PHP version. In the next section, we’ll discuss how you could check your PHP version with the phpinfo function.

Check the PHP Version by Using the phpinfo Function

You can also use the phpinfo function, which prints detailed information about the PHP software on your server and its configuration.

This option is especially useful when you don’t have SSH access to the server where your site is hosted. If you want to use this option to check the PHP version on the remote server, all you need is the ability to upload a PHP file, for example with FTP or a web-based portal.

Create a file called php_version_check.php file with the following contents. 

Upload this file to the root directory of your site. Once you’ve done that, you should be able to access it at the //example.com/php_version_check.php URL [replacing example.com with your own domain name]. It should produce output like that shown in the following screenshot.

phpinfo Security Risks

As you can see, the PHP version is displayed right on the top of the page. Also, it displays a lot of other important configuration information as well. This information can be very useful if you are setting up or debugging a PHP installation. It can also be very useful for hackers, allowing them to pinpoint specific vulnerabilities in your system! 

That's why I strongly recommend you remove this file from the server once you’ve finished checking the PHP version.

Learn PHP With a Free Online Course

If you want to learn PHP, check out our free online course on PHP fundamentals!

In this course, you'll learn the fundamentals of PHP programming. You'll start with the basics, learning how PHP works and writing simple PHP loops and functions. Then you'll build up to coding classes for simple object-oriented programming [OOP]. Along the way, you'll learn all the most important skills for writing apps for the web: you'll get a chance to practice responding to GET and POST requests, parsing JSON, authenticating users, and using a MySQL database.

Did you find this post useful?

Software Engineer, FSPL, India

I'm a software engineer by profession, and I've done my engineering in computer science. It's been around 14 years I've been working in the field of website development and open-source technologies. Primarily, I work on PHP and MySQL-based projects and frameworks. Among them, I've worked on web frameworks like CodeIgnitor, Symfony, and Laravel. Apart from that, I've also had the chance to work on different CMS systems like Joomla, Drupal, and WordPress, and e-commerce systems like Magento, OpenCart, WooCommerce, and Drupal Commerce. I also like to attend community tech conferences, and as a part of that, I attended the 2016 Joomla World Conference held in Bangalore [India] and 2018 DrupalCon which was held in Mumbai [India]. Apart from this, I like to travel, explore new places, and listen to music!

How do I check my 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..

How do I check my PHP version?

The most reliable way of finding out what version of PHP is used for that specific website is to use the phpinfo[] function, which prints various information about the PHP server, including its version. Once you find out what PHP version you have, either remove the file or restrict the access to it.

Is PHP already installed on Mac?

PHP comes preinstalled on most macOS systems, so you usually don't need any manual installation.

How do I update my PHP version on Mac?

To update the PHP version, update the brew using the command brew update . Then, use the command brew upgrade php . It upgrades the current version to the latest version of PHP. Then, restart the webserver to see the changes.

Chủ Đề