Oh Dear! monitors your entire website, not just the homepage. You'll get a notification as soon as your website is down, a monthly uptime report, a warning a few days before your SSL certificate expires and much more! Start your free 10 day trial now!

How to check which version of PHP you are running

Original – by Freek Van der Herten – 1 minute read

When working on open source code, I like using the latest version of PHP. When developers that are not on the latest version use the package, they might see syntax errors.

You might ask why Composer doesn't protect against this? When composer.json requires the latest version, how do devs, not on the latest version, can even install the package?

Well, there seemingly are a lot of people that only upgrade the PHP version on the command line. For handling web requests, they are unknowingly using an older version of PHP. Here's how to make sure you are on the latest version of PHP on both the CLI and for handling web requests.

On the CLI type this command to see your PHP version:

php -v

To check the PHP version that handles web requests, create a .php file with this content somewhere the public directory of your app.

<?php

phpinfo();

Point your browser to that file. You will now see which version of PHP you are running. Don't forget to delete the file afterward.

Stay up to date with all things Laravel, PHP, and JavaScript.

Follow me on Twitter. I regularly tweet out programming tips, and what I myself have learned in ongoing projects.

Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.

Comments

You can comment on this post by replying to this tweet.
Mark van den Broek liked on 19th March 2020
Knight  liked on 19th March 2020
Daniel Tsou liked on 19th March 2020
Azerdaoui Othmane liked on 18th March 2020
tefo liked on 18th March 2020
Spatie retweeted on 18th March 2020
Daniel liked on 18th March 2020
Nasirou Wagana retweeted on 18th March 2020
Nasirou Wagana liked on 18th March 2020
Dmitry Neverovski liked on 18th March 2020
Ahmed Abd El Ftah liked on 18th March 2020
Hadjidoro 🇸🇳 liked on 18th March 2020
Wyatt liked on 17th March 2020
Lawrence Enehizena liked on 17th March 2020
Kristoffer retweeted on 17th March 2020
QiroLab retweeted on 17th March 2020
atthakorn liked on 17th March 2020
Mozammil liked on 17th March 2020
QiroLab liked on 17th March 2020
Thomas Digby liked on 17th March 2020
Tom Witkowski liked on 17th March 2020
Hardik Shah liked on 17th March 2020
Peter Sowah retweeted on 17th March 2020
Rolf den Hartog retweeted on 17th March 2020
Mateus Junges liked on 17th March 2020
Peter Sowah liked on 17th March 2020
Edwin I Arellano liked on 17th March 2020
Pavlo Bezdverniy liked on 17th March 2020
Ram Ratan Maurya liked on 17th March 2020
Arman Ahmadi liked on 17th March 2020
Andreas 'Ando 🦆 ' Frömer liked on 17th March 2020
Joseph Silber replied on 17th March 2020
That assumes composer install always runs on the Target machine, or at least on a machine with the same version of PHP. That's not always the case.
hedeqiang retweeted on 17th March 2020
Vincenzo La Rosa liked on 17th March 2020
Abel Ponce liked on 17th March 2020
hedeqiang liked on 17th March 2020
Benjamin Crozat replied on 17th March 2020
It's actually hard to believe such a post is needed. PHP newbies usually don't know WTF are Git and GitHub.
Petar Djurich liked on 17th March 2020
Brent retweeted on 17th March 2020
Andre Sayej liked on 17th March 2020
Peter Brinck 🤘 liked on 17th March 2020
Miguel Piedrafita 🚀 liked on 17th March 2020
Jigal Sanders liked on 17th March 2020
Owen Voke (pxgamer) liked on 17th March 2020
Vireak liked on 17th March 2020
S I K I R U 👨‍💻 liked on 17th March 2020
finalFlick liked on 17th March 2020
Zubair Mohsin liked on 17th March 2020
ujwal dhakal liked on 17th March 2020
Bas de Groot liked on 17th March 2020
Ben Holmen liked on 17th March 2020
Cyril de Wit liked on 16th March 2020
. liked on 16th March 2020
José Cage liked on 16th March 2020
Gabule, John Paul liked on 15th March 2020
Miguel Piedrafita 🚀 liked on 15th March 2020
AbdulHameed olamilekan replied on 15th March 2020
This is good idea,pls if i may ask how to upgrade cli php version to the latest or from one version to the other, i have google searched this alot but i have not found any resourceful answer thank you
talv replied on 15th March 2020
Ahh that makes sense I wondered why this post came up but got it now!
Brian Coogan replied on 15th March 2020
This is why devs should do a version check in their code. Also, not a bad idea to check the specific functionality so it’s clear what was needed, ala JavaScript eg: in PHP, if function_exists(), etc. Would be a nice addition to the article.
ali ali liked on 15th March 2020
Thanks for sharing ... We are all newbies at anytime, as we move in different directions, tools and platforms. #CodeNewbie
Enzo Notario liked on 15th March 2020
Sumon Molla Selim, FRSA liked on 15th March 2020
Khorshed Alam liked on 15th March 2020
Manpreet Rathore liked on 15th March 2020
Ahmed Abd El Ftah liked on 15th March 2020
lost.design liked on 15th March 2020
Salman Zafar liked on 15th March 2020
Kevin Guo liked on 15th March 2020
togo retweeted on 14th March 2020
togo liked on 14th March 2020
Ⓜ️ fuz liked on 14th March 2020
Peter Sowah liked on 14th March 2020
boner boy replied on 14th March 2020
How about linking to it as part of the issue template?
Abdullah Hejazi liked on 14th March 2020
Musa  liked on 14th March 2020
Jérémy DECOOL liked on 14th March 2020
Peter Fox replied on 14th March 2020
If you want to go the extra mile, adding how to fine which binary you're using and how to find the ini file is also a must for PHP development in my opinion anyways
Gregorio Hernández Caso replied on 14th March 2020
If you want to check your "web requests" PHP version from command line, usually (it depends on the server configuration) you can do something likes this: curl -vk http://localhost 2>&1 | grep "X-Powered-By"
oluwajubelo loves VueJS 🚨 liked on 14th March 2020
Mahamadou retweeted on 14th March 2020
Mahamadou liked on 14th March 2020
Freek Van der Herten replied on 14th March 2020
Well, for some people, that’s not enough.
Nixon Kosgei replied on 14th March 2020
I always just check on composer.json file for php dependency version. on terminal by doing php -v