showing two different PHP versions in command line - php

I installed laravel project 5.1 which is working fine but artisan commands are not working throwing each() error which is deprecated in php 7.1. When I run phpinfo() it shows php version 5.6 and on command line there's also two versions are showing
when run
phpinfo();
5.6
when run on command Line in xampp folder
C:/xampp> php -v;
5.7
when run in command in this xammpp/php directory
C:/xampp/php> php -v;
5.6

This is because there are CLI version and WEB version.
How Giacomo1968 says in this answer on Super User:
“Don’t panic! If you are concerned about what PHP version your Apache server is using, the output of phpinfo() is always what you should pay attention to. The Apache PHP module and the PHP command line binary are two different things that don’t interfere with each other.
In fact you can compile and load various PHP versions you want to work with Apache as long as you adjust Apache to properly load it. The PHP command line interface will never come into play in the case of Apache parsing PHP pages.
The command line version of PHP is simply there for command line specific tasks and the PHP module for Apache will never touch, use or need that.”

Related

Symfony fos:user:create through error "could not find driver", (Xampp with multiple verison of PHP)

INTRODUCTION:
I am in a Symfony Project with PHPStorm. I'm trying to create a fos user on DB (xampp MySQL).
Symfony CLI version v4.21.6
Composer version 1.10.19
C:\Program Files\Symfony\name_projectFolder>php -v
PHP 8.0.0 (cli)
C:\Program Files\Symfony\name_projectFolder>symfony php -v
PHP 7.4.14 (cli)
With the first command we see the actual php version (8.0.0) that is used by default, but my project doesn't support it, so i installed another one (on xampp folder with the correct procedure) and told to the project to use this new version (7.4.14) instead of the default one.
TO SET which php version the project should use:
C:\Program Files\Symfony\name_projectFolder>echo 7.4 > .php-version
TO SEE the list of PHP versions that we have:
C:\Program Files\Symfony\name_projectFolder>symfony local:php:list
The highlighted number on the left is the actual version that the project is using.
The asterisk on the right indicates the default system PHP version.
(INFO:
If you want to use a normal command you need to specify which PHP version it should refer to, in order to run it.
To do so just add before the normal command the "symfony" word because it will use the project settings and not the system ones.)
START with the procedure to CREATE the fos user:
(as we said before, we use the word "symfony" to "tell" to the command to use the 7.4 PHP version, keep in mind that normally you don't to this)
C:\Program Files\Symfony\name_projectFolder>symfony php bin\console fos:user:create
you'll get this error:
in a few words "An exception occurred in driver: could not find driver"
SOLUTION
Because you have two PHP versions, in the new one you need to enable the pdo_mysql extension that normaly is not.
STOP the Apache Server in the XAMPP controller.
just go in the folder C:\xampp\php7_4 and open the file php.ini
search (CTRL+F) for pdo_mysql and uncomment/remove the ";"
BEFORE ;extension=pdo_mysql
AFTER extension=pdo_mysql
SAVE the changes
START the Apache Server and re-run the symfony php bin\console fos:user:create command and it will work !!

I'm getting php5.5 instead php7 when I run exec(php -v) in php script

When I run php -v in cli I get the exact php version 7, but when i run exec("php -v") in web server I get php 5.5 even thought in phpinfo i see that I am runing php 7?! Any idea why I get the older version of PHP?
running exec you get the CLI version of PHP
you probably installed php5.5 as CLI and php7 as apache module
If you use CentOs, add this line at the end of /etc/bashrc (or ~/.profile for Ubuntu)
export PATH=$PATH:/your/path/to/php7/bin
Then run:
source /etc/bashrc
P/s It may be better if you edit /etc/profile.d. Take a look both of them.
UPDATE
In MacOS, let edit ~/.bash_profile (create it if it does not exist) with the same content.

Ubuntu Command Line Reports PHP version as 5.3.3 but phpinfo says 5.5.9

When I look at a phpinfo page on my ubuntu server it says the php version is 5.5.9. But when I do a php -i or -v from command line it says php version 5.3.3 and it doesn't list the modules I've installed in 5.5.9.
I guess I have two versions running. How do I get rid of 5.3.3 so command line reports 5.5.9?
Do a locate bin/php to see all files on your system that might possibly be PHP binaries. Then do a which php to see which one would be executed. I have one in /usr/bin/php and a self-compiled version in /usr/local/bin/php53, of varying versions.
To run things on the command line with the other version, you can specify the full path of PHP thus: /usr/local/bin/php /command/to/run and it will run that. Or, add the path to the new version to your system path at the start, and this will "see" the new PHP version before the old one.
If you are running this thing from cron, I tend to recommend using the full path to the PHP interpreter anyway - I think it's a good habit, in case the available paths are different between your environment and the cron environment.

Laravel - artisan command not working

I am getting started with using laravel on Mac and am using MAMP. I am using the `artisan' command with laravel in php.
php artisan migrate:make create_users_table --table=users --create
But it is giving me this error
php artisan migrate:make create_users_table --table=users --create
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so, 9): image not found in Unknown on line 0
Laravel requires the Mcrypt PHP extension.
I have installed the mcrypt extension for PHP.
brew install php53-mcrypt
This gives me a message saying that it is already installed: php53-mcrypt-5.3.26 already installed
PHP being different when run in the command line versus through your web server turns out to be a pretty common issue (note that those are three separate links with possible solutions :D)
The key point is to:
make sure the correct PHP binary (the one used by MAMP) is in your PATH
(less likely) to check to see if your CLI-run php.ini and loaded extensions is different from your web-server (apache)-run PHP (They can be potentially different).
Finally, please consider saving your time and some stress by using Vagrant or another VM provider, which gives you the ability to run a "real" web server on your computer without mucking up your Mac OS install!

CentOS - Mongo class not found in PHP

I need the MongoDB PHP driver on my CentOS 5.4 machine. My PHP version is 5.1.6. I downloaded the RPM and installed it. That created several files in /usr/bin directory. I copied
/usr/bin/mongo
to
/usr/lib/php/modules
which was what extension_dir showed on doing phpinfo();.
I also added
extension=mongo.so
in /etc/php.ini.
However on executing my PHP script, i still get
Mongo class not found.
What's going wrong here ?
Also, my phpinfo() shows PHP version 5.1.6 whereas running PHP from command line shows 5.3.3. Could anything be wrong with that ?
Thanks in advance.
You're saying your webserver and command line PHP report different versions. These are going to be installed in different locations, and their extensions are API incompatible with each other.
When you installed the php_mongo extension, it may have used the command line php to determine the directory to install the extension to.
Make sure you have the correct php_mongo for the php version of your webserver, and it is in the correct extensions directory. (get the directory from the php.ini returned by phpinfo())
I hope you realise PHP 5.1 is also many years out of date. Unless you have a specific reason to use a version that old, you should also look at upgrading to a more recent version.
Edit:
Just read your comment "I must also mention that /usr/bin/mongo is a binary executable file but its not having a .so extension. Im copying it as is to /usr/lib/php/modules"
No no no! :)
This is the mongo command line client. This is not the PHP extension!
You can run a find /* -name "mongo.so" to see where the installer put the file, this will probably also give you an indication of which version of PHP it was installed for.
It looks as though you are confusing the RPM-packages for the MongoDB server with the requirements to install the MongoDB PHP driver. The PHP driver provides access to the server from your PHP applications, and does not install any command line tools.
restart httpd !
yum service httpd restart

Categories