linux(Centos7) | I have two php.ini files - php

I installed the apm on my Linux (Centos7) and i think i installed the php again with yum.
I have two php.ini file in the paths below.
/usr/loacal/php/bin/php.ini (v5.3)
/etc/php.ini (v5.4)
php -v
PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27)
/usr/local/php/bin/php -v
PHP 5.3.27 (cli) (built: Mar 3 2016 11:17:12)
I have two versions of php on one server right now.
rpm -qa | grep php
php-pdo-5.4.16-36.el7_1.x86_64
php-tcpdf-6.2.11-1.el7.noarch
php-tidy-5.4.16-3.el7.x86_64
php-xml-5.4.16-36.el7_1.x86_64
php-mbstring-5.4.16-36.el7_1.x86_64
php-cli-5.4.16-36.el7_1.x86_64
php-php-gettext-1.0.11-12.el7.noarch
php-bcmath-5.4.16-36.el7_1.x86_64
php-gd-5.4.16-36.el7_1.x86_64
php-process-5.4.16-36.el7_1.x86_64
php-common-5.4.16-36.el7_1.x86_64
php-mysql-5.4.16-36.el7_1.x86_64
php-tcpdf-dejavu-sans-fonts-6.2.11-1.el7.noarch
I think this all files are installed with php(v5.4)
I can I remove these?
Can i just use the yum command again like below?
yum remove php
I'm so afraid that something happens when i do that.
Please let me know how to deal with this situation... Thanks

You might not need to remove anything. You can have as many versions of PHP installed as you like. The PATHS etc determine what actually gets used. To see what php binary is being used on command line use
which php
To see what php.ini file is being used by that binary use
php -i |grep "php.ini"
If you have the correct one then you're probably fine. To see what files will be remove by removing packages you can query the package to get the file list ie
rpm -ql php-common-5.4.16-36.el7_1.x86_64
The common package should contain the php.ini file that gets installed. From these commands you should be able to work out if you want to remove anything.
Note, if you can, use the more modern versions of PHP that you have installed. PHP 5.3 and 5.4 are both considered old versions now and are no longer supported.
https://en.wikipedia.org/wiki/PHP#Release_history

Related

Why phpinfo() shows a different version than php -v?

I install php via brew. With brew install PHP. My version of php-cli is 7.2
But, if I use phpinfo() on my server, I get php version 7.1.
If I use php -v in my terminal, I get php version 7.2.
Disclaimer: I'm adding this hopefully extensive answer as part of the Revival badge. (Answer more than 30 days after a question was asked as first answer scoring 2 or more)
TL;DR
php -v settings can be different from phpinfo() inside your web-server due to the running service state of fpm and your webserver. Perhaps you need to restart php-fpm and/or your web-server (apache, nginx, ..).
Long version: Command line
Command-line based calls like php -v or php -i or php test.php will read your configuration, options and arguments every time you execute your script within a terminal.
This means if you update php in your operating system then you'll get the most recent version in your terminal session.
Attention: Depending on your PATH variables you still might get an older version.
What does this mean? Even if you update your php version on your operating system you might still have an older terminal session which links to an older php-binary.
Here is an example: I am an OSX user and installed php through brew. Currently php links to php#7.3. Here is my way to validate which versions are running where. For this I'm using which php.
$ which php
/usr/local/opt/php#7.3/bin/php
$ php -v
PHP 7.3.11 (cli) (built: Oct 24 2019 11:29:42) ( NTS )
// or the equivalent "absolute path" example
$ /usr/local/opt/php#7.3/bin/php -v
PHP 7.3.11 (cli) (built: Oct 24 2019 11:29:42) ( NTS )
I have multiple php-versions installed on my local system. I can run them all individually. Here is an example:
$ /usr/local/opt/php#7.2/bin/php -v
PHP 7.2.20 (cli) (built: Jul 5 2019 12:56:54) ( NTS )
Long version: Why is my phpinfo() using the wrong php version?
Since we now have an understanding that we can run multiple and different versions of php on a single operating system, lets dig into our web-server based script which runs phpinfo().
After installing a new php-version you'll have your binaries replaced by new versions. Awesome! but.. how does my running web server get notified about it?
For this I'll refer to the php documentation Apache 2.x on Unix systems Point 7. Also apache allows us to load different modules for PHP.
Edit your httpd.conf to load the PHP module. [...]
For PHP 7:
LoadModule php7_module modules/libphp7.so
For PHP 5:
LoadModule php5_module modules/libphp5.so
Since you are upgrading from PHP 7.1 to PHP 7.2 there is probably no change but your webserver is still running the old linked version of php.
In this case a restart of your apache webserver should help so it can pickup the new binaries correctly.
Please let me know if this will help you to solve your issue. For all the other readers: If you think there is something missing OR there is something wrong in my explanation then please let me know with a comment.

PHP version on MacOS X 10.11 issue

Recently I updated the default PHP version on MacOS X 10.11 to the newer 7.1.4, but when I do php -v on the terminal it says this: PHP 5.5.38 (cli) (built: Aug 21 2016 21:48:49).
I created the phpinfo on the web root and it says that the version is actually the 7.1.4.
What should I do to resolve this issue? Is this a real issue?
Since you said:
I used the command curl -s php-osx.liip.ch/install.sh | bash -s 7.1
I took a look at https://php-osx.liip.ch, which says:
Why does php -v on the command line still show my old version?
php-osx doesn't overwrite the php binaries installed by Apple, but
installs everything in /usr/local/php5. The new php binary is
therefore in /usr/local/php5/bin/php.
You can also adjust your PATH do include that directory, eg. write
into your ~/.profile file the following
export PATH=/usr/local/php5/bin:$PATH

Install php-cgi on Mac OS X Yosemite

Is it possible to install php-cgi on Mac OS X Yosemite keeping the standard PHP version provided by the OS?
Thanks,
Alberto
You can install PHP easily with Homebrew:
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew install php54
Homebrew doesn't change the version of the system PHP. System and Homebrew versions are located in different directories. This is how it looks like for me:
System /usr/bin/php:
/usr/bin/php -v
PHP 5.4.30 (cli) (built: Jul 29 2014 23:43:29)
Homebrew /usr/local/bin/php:
/usr/local/bin/php -v
PHP 5.6.2 (cli) (built: Nov 14 2014 10:30:28)
If you wish to use PHP CGI on Mac OS X you will need PHP build with the CGI enabled. By default, PHP version 4.3 and higher is built with "-enable-cli" option so default interface is CLI (Command Line Interface). You can check this by running "php -v" from the shell. Output will probably be something like this:
PHP 4.4.4 (cli) ....
CLI does not output any headers and output is plain text by default. More details about this is available here.
In order to use PHP with the wxWebServer (or any other CGI application), you will need to build your own PHP binaries with CGI SAPI. It's simple, it takes only 15 minutes and you will be proud of yourself for having a "personal" build of the PHP. Here is the procedure, step by step:
Download the complete source code for the latest PHP version from php.net. Instructions here are for PHP 5.2.3 but should work for PHP 4 as well. I tested with 4.4.7 too.
Unpack downloaded archive somewhere, for example ~/Temp/php-5.2.3
Open terminal window (shell) and go to folder where you unpacked files:
cd ~/Temp/php-5.2.3
Decide where you want to install this custom PHP build and create folder. This document will assume it's custom folder under your home folder, for example if user name is webdev it's /Users/webdev/custom/php5
Create that folder (in Finder or in Terminal with "mkdir ~/custom; mkdir ~/custom/php5")
Go back to that Terminal window, you should still be in ~/Temp/php-5.2.3.
Run ./configure with CLI disabled if you are planning to use this private PHP build only for CGI. Modify paths and options to reflect your preferences.
You don't need option "--disable-cli", you can replace it with "--enable-cli" if you plan to use this PHP for something more. You will get both binaries but you will need to use php-cgi in wxWebServer.
Here is a full command line for .configure that should produce PHP with all common options and CLI disabled:
./configure --prefix=/Users/webdev/custom/php5 --disable-cli --enable-cgi --enable-trans-sid
--enable-mbstring --with-xml --enable-exif --enable-mbregex --enable-dbx --enable-sockets
--with-iodbc=/usr --with-curl=/usr --with-config-file-path=/etc --sysconfdir=/private/etc
--with-mysql=/usr/local/mysql --without-pear
When configure is completed, run
make install
Edit your profile (~/.profile) to add new php path before existing one. Add something like this to the end of your .profile file:
PATH=~/custom/php5/bin:$PATH
export PATH
If you don't know how to edit profile from the command line, just create a plain text file in TextEdit containing those 2 lines and save it in your home folder (~/Users/webdev) as newpath.txt. Then open Terminal and enter command:
cat newpath.txt >> .profile
The easiest way for changes to take effect is to log out and log back in (or you can use source command).
Congratulations, you now have a custom php installation! If you wish to use other PHP just comment your changes to .profile
Verify your new PHP is the default one:
# which php-cgi
/Users/webdev/custom/php5/bin/php-cgi
php-cgi -v
PHP 5.2.3 (cgi) (built: Jul 11 2007 00:48:59)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
If you wish, you may now delete the source files in ~/Temp/php-5.2.3. To remove you custom PHP just delete target folder, i.e.
"/Users/webdev/custom/php4".
Once you have custom php installation, configure wxWebServer to use new php binaries. Regardless if you enabled or disabled CLI, you can use php-cgi (output of "which php-cgi", in this case
"/Users/webdev/custom/php5/bin/php-cgi").
If you disabled CLI build, you may also use php binary as it will be CGI build. That's it, enjoy your personal PHP build!
Found It Here

MongoDb php extension not loading

I'm trying to load the MongoDb extension for php on a Windows 7 64 bit PC, running XAMPP with Apache 2.0 and PHP 5.3.5, compiler version VC6. I started out with this tutorial, and have also tried the extensions that the php documentation suggested. MongoDb itself is running fine, and shell commands seem to work.
At the moment I have:
Added extension=php_mongo.dll to my php.ini file.
Put the VC6 version of php_mongo.dll (from the following download page, suggested by the PHP documentation) in the php/ext folder.
Restarted my Apache server.
I have also tried php_mongo.dll files form Stealth's github, but they didn't seem to work either.
When restarting Apache, I don't get any errors, but I can't find anything on MongoDb in phpinfo(), and the Mongo class is not recognised either.
Any ideas of what might be wrong? Let me know if you need more info.
The problem might be incorrect version of extension. Try different versions downloaded from here: http://pecl.php.net/package/mongo/1.6.4/windows
Use Bitnami WAMP Stack instead of XAMPP it comes preloaded php_mongo.dll driver installed and no need to configure php.ini file
There is no official MongoDB Driver released for PHP7. So it would be better to download the recommended PHP version 5.5.30(currently) offered by Bitnami Wamp Stack.
There might be two reasons:
First one is as #Sadd suggested. Your mongodb extension should be loaded after what you have done so its very likely that you have enabled extension in wrong file. And yes, there are two such similar files (named php.ini-development and php.ini-production on windows computers), so make sure to enable it in php.ini file and run the following code echo extension_loaded("mongodb") ? "loaded\n" : "not loaded\n"; and you should see loaded on screen.
If you still don't see it, then the second thing you can do is to check whether the version is right or not. You can check your phpinfo() for your php version and then put the right versioned dll file in ext folder. In this, you can have to check whether your php is ts or nts and second one is whether your php is x64 or x86. I hope you are good to go after one or both of the changes.
This was driving my crazy until I looked closely at my PHP version:
$ php -v
PHP 7.4.1 (cli) (built: Dec 17 2019 19:23:59) ( NTS Visual C++ 2017 x64 )
Notice that it says PHP 7.4.1 and NTS and x64? This means that when I download from PECL, I need version 7.4 Non Thread Safe (NTS) x64 or it won't run correctly.
If the correct version of module is not added, an error is thrown.
[PHP Warning: PHP Startup: Unable to load dynamic library 'php_mongodb.dll' (tried: C:\xampp\php\ext\php_mongodb.dll (The specified module could not be found), C:\xampp\php\ext\php_php_mongodb.dll.dll (The specified module could not be found)) in Unknown on line 0]
When downloading the dll extension from https://pecl.php.net/package/mongodb, make sure that NTS (Non Thread Safe) or TS (Thread Safe) is chosen according to what shown from php -v command.
$ php -v
PHP 8.1.7 (cli) (built: Jun 7 2022 21:45:53) (ZTS Visual C++ 2019 x64)
Although here it shows ZTS, TS version can be used in this case.

Problem of different PHP versions reported

I have upgraded to PHP 5.3 on a development machine (Windows 7 box).
php-v shows
PHP 5.3.3 (cli) (built: Jul 21 2010 20:36:55)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
However, phpinfo.php shows that the version on the machine is: 5.2.14 as shown
The loaded configuration file rightly loads the correct php.ini file for 5.3
The configuration file (php.ini) Path wrongly reads: C:\Windows - I don't install PHP on the said path. I have however done a recursive search of PHP folders and files within that file but the search turned up nothing.
Applications seem to use the settings reported by the phpinfo and not by php -v or php -m or php -i (or else).
Apart from deleting the PHP folder and starting from scratch (which I have done), and ensuring that Apache points to the right PHP dir using PHPINIDir, what could I possibly do to solve this? Thanks.
Hello
You should also update apache php
module
#soju - that fixed it, thanks, but I thought I'd make this a little clearer for others.
Apache requires the php module to serve php files. On Windows it comes as a .dll file. This would be called: php5apache2_2.dll - located within your php folder. Strangely though, during upgrading the php folder with a newer version, you may find out that apache still uses the old php module file. So while php -v correctly reports the new version, Apache still looks at the old php module (reported by phpinfo). To find out what module version you have, you could: right-click on the .dll file > select properties -> view the details tab. Or just hover on the file.
If this version is not what you want, you might want to hunt for a newer version and replace it. Good idea to back up first. Also, the php5apache.dll file works with and requires the file: php5ts.dll - so ensure these files are the same versions.
With your httpd.conf file with the directive:
LoadModule php5_module "\path to\php5apache2_2.dll"
You may restart apache and smile!
Your command line (CLI) php is an other version than the one used for Apache. Check also that both use the same php.ini. When you call on your Windows machine
c:\path\to\php\php.exe -v
or
c:\path\to\php\php-win.exe -v
and
c:\path\to\php\php-cli.exe -v
They all can return different versions. Often this happens when upgrading to a new WAMP version and forgetting to delete the old versions. I'm sure you will find the executable PHP binary which matches the same version. It is also save to use the php.exe or php-win.exe instead the php-cli.exe on Windows.

Categories