Hướng dẫn how to check php version on mac terminal - cách kiểm tra phiên bản php trên mac terminal

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 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
1 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 http://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.

Hướng dẫn how to check php version on mac terminal - cách kiểm tra phiên bản php trên mac terminal
Hướng dẫn how to check php version on mac terminal - cách kiểm tra phiên bản php trên mac terminal
Hướng dẫn how to check php version on mac terminal - cách kiểm tra phiên bản php trên mac terminal

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!

Hướng dẫn how to check php version on mac terminal - cách kiểm tra phiên bản php trên mac terminal

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.

Bạn có thấy bài đăng này hữu ích?

Hướng dẫn how to check php version on mac terminal - cách kiểm tra phiên bản php trên mac terminal

Kỹ sư phần mềm, FSPL, Ấn Độ

Tôi là một kỹ sư phần mềm chuyên nghiệp, và tôi đã thực hiện kỹ thuật khoa học máy tính. Đã khoảng 14 năm tôi đã làm việc trong lĩnh vực phát triển trang web và công nghệ nguồn mở. Chủ yếu, tôi làm việc trên các dự án và khung dựa trên PHP và MySQL. Trong số đó, tôi đã làm việc trên các khung web như Codeignitor, Symfony và Laravel. Ngoài ra, tôi cũng có cơ hội làm việc trên các hệ thống CMS khác nhau như Joomla, Drupal và WordPress và các hệ thống thương mại điện tử như Magento, Opencart, WooC Commerce và Drupal Commerce. Tôi cũng muốn tham dự các hội nghị công nghệ cộng đồng, và là một phần của điều đó, tôi đã tham dự Hội nghị Thế giới Joomla 2016 được tổ chức tại Bangalore (Ấn Độ) và 2018 Drupalcon được tổ chức tại Mumbai (Ấn Độ). Ngoài ra, tôi thích đi du lịch, khám phá những địa điểm mới và nghe nhạc!

Làm thế nào để tôi biết nếu PHP được cài đặt trên thiết bị đầu cuối MAC của tôi?

Lệnh PHP -V hoạt động trên Linux, MacOS, Windows và các hệ thống được hỗ trợ khác. Đầu ra của nó chứa số phiên bản PHP, ngày xây dựng và thông tin bản quyền. Lưu ý: Nếu có nhiều phiên bản PHP được cài đặt trên máy chủ, lệnh PHP -V hiển thị phiên bản giao diện dòng lệnh (CLI) mặc định.php -v command works on Linux, macOS, Windows, and other supported systems. Its output contains the PHP version number, build date, and copyright information. Note: If there is more than one PHP version installed on the server, the php -v command shows the default command-line interface (CLI) version.

Tôi có phiên bản PHP nào?

Kiểm tra phiên bản PHP được cài đặt trên máy chủ Linux và UNIX của bạn..
Mở dấu nhắc đầu cuối và sau đó nhập các lệnh sau ..
Đăng nhập vào máy chủ từ xa bằng lệnh SSH.....
Để kiểm tra phiên bản PHP, chạy: PHP --Version hoặc PHP-CGI --Version ..
Để in phiên bản Php 7, loại: Php7 --Version hoặc PHP7-CGI --Version ..

Làm cách nào để biết tôi có phiên bản PHP nào?

Cách đáng tin cậy nhất để tìm ra phiên bản PHP nào được sử dụng cho trang web cụ thể đó là sử dụng hàm phpinfo (), in thông tin khác nhau về máy chủ PHP, bao gồm cả phiên bản của nó.Khi bạn tìm hiểu phiên bản PHP bạn có, hãy xóa tệp hoặc hạn chế quyền truy cập vào nó.

Làm cách nào để thay đổi phiên bản PHP trong thiết bị đầu cuối MAC?

Thực hiện theo các bước của tôi:..
Kiểm tra các phiên bản PHP đã cài đặt của Brew, chắc chắn mọi thứ đều tốt> Danh sách bia |grep php #output php56 php56-intl php56-mcrypt php71 php71-intl php71-mcrypt ..
Chạy Script> Switch-Php 71 # hoặc Switch-Php 56 #Output Php phiên bản [71] Tìm thấy chuyển đổi từ [Php56] sang [Php71] ....