How to check your PHP version using bash
Do you know we’ve moved on a new address. There will be no new articles on this blog anymore. If you still want to keep in touch with us, follow us @ Code Mamba!You can read the same article on our new domain by clicking here!
So, you can check your php version using PHP with the following code:
<?php phpinfo(); ?>
So how to do the same using bash. In bash you can use
php -r PHP_CODE_GOES_HERE
to run php code. You can run the phpinfo(); code after you escape all special characters:
php -r phpinfo\(\)\;
The returned information is just too much to handle. We’ll now grep only the PHP version.
php -r \phpinfo\(\)\; | grep 'PHP Version'
If you get PHP warnings you might want to silent them using @:
php -r \@phpinfo\(\)\; | grep 'PHP Version'
Now the last thing to do is to limit our grep to just one line:
php -r \@phpinfo\(\)\; | grep 'PHP Version' -m 1
and the result is:
Leave a comment