🏝 If you like the content of this blog, I would really appreciate your vote in Tuple's Send an Open Source Developer on Vacation contest. Just search for "Freek Van der Herten" in the nominees list and cast your vote. 🙌
😀 This holiday won't only be a nice reward for me, but also for my girlfriend who always gives me a lot of time working on open source packages and blog posts.
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:
To check the PHP version that handles web requests, create a
.php file with this content somewhere the public directory of your app.
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.
Follow me on Twitter. I regularly tweet out programming tips, and what I myself have learned in ongoing projects.
Every month 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.
Want to join the conversation? Log in
or create an account
to post a comment.
My favourite one of these is “Syntax error, unexpected ‘use’ (T_USE)”, which usually means they’re running on PHP < 5.3
✅vursion.io shows a warning if your PHP and PHP-CLI versions do not match.
Learned from experience that PHP versions are never in sync on Combell webhosting (🇧🇪).
Could I just dd(phpinfo()) ?
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.
It's actually hard to believe such a post is needed. PHP newbies usually don't know WTF are Git and GitHub.
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
Ahh that makes sense I wondered why this post came up but got it now!
Thanks for sharing ...
We are all newbies at anytime, as we move in different directions, tools and platforms.
How about linking to it as part of the issue template?
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
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"
Well, for some people, that’s not enough.
I always just check on composer.json file for php dependency version.
on terminal by doing php -v