Linux Ubuntu PHP Version is different in CLI and in PHPINFO() - php

I am very new to linux and setting up PHP in the server.
When I try to do a php -v, the php version is returning a version of 7.0, but when I checked the php version in phpinfo(), it is returning 5.5.9.
My question here is that how can I make both versions to be the same, like when I checked in to the phpinfo(), it should also have 7.0 version.
Your help would be greatly appreciated! Thank you!

First you will need to remove the php by following command. This will remove both i.e php 5 and 7.
sudo apt purge php*
Now install php7.0
sudo apt -y install php7.0 libapache2-mod-php7.0
Then restart Apache:
systemctl restart apache2

Probably, you have a ubuntu version with PHP already installed on it. Then you installed another php on it, like xampp.
Try to diagnose your own problem.
Get know which php used by CLI by type:
Which php
If you want to keep only PHP 5 running on your machine, then you must set the variable environment of your bash to running php.exe from php5 directory. Restart your machine and test it.

Related

Installing PHP 7.4 on macOS Sierra without brew?

I am unable to find any info on installing PHP 7.4, all the info seems to go untill 7.3 but that has not been helpful.
What I have done so far is execute:
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.4
And this is the message I got:
It doesn't seem to install. How can I solve this problem?
If you check the script https://php-osx.liip.ch/install.sh you can see it only support 7.3
Yes, you can install and upgrade to latest php version on mac without homebrew.
For me I use MacPorts a package manager for MacOS which is similar to HomeBrew but more stable.
Example to upgrade to php74:
sudo port install php74
Install the extensions you need
sudo port install php74-cgi php74-gd php74-curl php74-intl php74-iconv php74-gettext php74-mbstring php74-imap php74-mcrypt php74-xmlrpc php74-mysql php74-openssl php74-sockets php74-zip php74-tidy php74-opcache php74-xsl php74-sqlite
Select php74 as the active PHP version. With this command you can have multiple php version and quickly switch from one to the other.
sudo port select php php74
Check which PHP binary is used (should return /opt/local/bin/php). Perhaps you may need to restart you terminal.
which php
Check the version (should return “PHP 7.4.XX (cli)…”)
php --version
Also, If you use XAMPP ensure to restart Apache Web server.
(Article Reference)

Detecting PHP version in Linux Mint

I am a new Linux Mint user. In my computer I found PHP version 7.1 from phpinfo() like below
I found PHP version 7.4.3 from terminal like below
My /etc/php/ folder is like below
Which PHP version am I using ?
Try in your terminal
which php
your will find your terminal PHP path.
You have multiple versions installed and you're using the version that PHP tells you you are using.
When you use the webserver module version of PHP it is version 7.1.33. When you use the command line version you are using 7.4.3.
You might also have 7.0 and 7.2 installed (or they may be folders for leftover config files in versions that have since been uninstalled).
Disable php 7.1 module on Apache
sudo a2dismod php7.1
and enable php 7.4
sudo a2enmod php7.4
sudo systemctl restart apache2
The php version used by the CLI and the one used by apache CAN be different.
The installed versions are listed in your /etc/php/ folder as you already emntioned.
To switch the used version for apache you can use the following commands:
sudo a2dismod php7.1
sudo a2enmod php7.4
Also you have to restart your apache afterwards.
Reference: https://serverfault.com/questions/149039/how-to-change-what-version-of-php-apache2-uses

When trying to install Opencats using installwizard.php it gives some errors

I tried to install opencats on linux server. Running ubuntu version is 18. When I try to install opencats via http://localhost/opencats (server ip address used as localhost) and click installwizard.php I get the following errors/warnings:
It won't work on PHP7 if it wants the MySQL extension. It has been removed. Its sounds like a very very old project you are trying to install.
I had a quick look on their homepage:
Opencats has a minimum supported PHP version of PHP 5.5, and are working towards full PHP 7 compatibility.
http://www.opencats.org/
OpenCATS does not currently support php7. It must be 5.6.X
you should install PHP5.6, Open your terminal and execute those commands as follow:
1- to install PHP5.6
sudo apt-get install php5.6
2- Now, you should know which PHP version you are using
php --version
3- To stop running the current PHP version, run the commands below to disable it for Apache2 (ex: PHP7.2)
sudo a2dismod phpX
where X is your PHP version
4- Then run the commands below to enable PHP 5.6 for Apache2 to use
sudo a2enmod php5.6
5- Now, You can install the needed PHP extensions like MySQL
sudo apt-get install php5.6-mysql
5- Restart Apache2 for the changes to apply by running the commands below
sudo systemctl restart apache2.service
Hope that this can help you.

PHP version must be equal or higher than 5.6

I have updated PHP 5.5.9 to PHP 5.6.31 using the command lines in Ubuntu.
This is the picture
And then I was trying to install CakePHP, but it is showing that "your PHP version must be equal or higher than 5.6.0 to use CakePHP."
This is the error message of cakePHP
I am doing work in Linux(Ubuntu) Operating system.
What can I do now?
Your PHP CLI version and the version configured with your web server can very well be different. If you check phpinfo(), you can see exactly what paths and what not are in use.
I have found the solution. PHP CLI and PHP Apache are the different module. We have to notice the Apache server PHP version which is showing by-
<?php
phpinfo()
?>
To run the same version, first I disabled the PHP 5.5.9 version-
sudo a2dismod php5
Then I enabled the PHP 5.6 version-
sudo a2enmod php5.6
Restart the server-
sudo service apache2 restart

php version showing different in application/browser

I have installed ubuntu/trusty64 using vagrant on my windows pc. I have installed all the required package for php development environment.
Now problem is while I check php version on browser it's showing different from terminal.
From application browser showing :
PHP Version 5.5.9-1ubuntu4.20
Terminal showing:
PHP 5.6.27-1+deb.sury.org~trusty+1 (cli)
Why different version showing on my application?
Please let me know how can I sync up application with php 5.6.27 ?
//php 7.0 to php 7.2 switcher
sudo a2dismod php7.0
sudo a2enmod php7.2
sudo systemctl restart apache2
sudo ln -sfn /usr/bin/php7.2 /etc/alternatives/php
If I understood your question correctly, then the difference between your terminal and the application is the PHP source that they are getting the information from. If you had installed PHP apart from your application, that's why is showing different versions.
To change this (for example that you want to have only the PHP that your terminal is displaying:PHP 5.6.27-1+deb.sury.org~trusty+1 (cli), then change the pointer from your application to point to the directory where PHP 5.6 is installed (For Ubuntu: /usr/share/php5).

Categories