I am trying to install PHP 7.2 on my Mac
I did:
php --version
PHP 7.1.33 (cli) (built: Jan 26 2020 22:52:32) ( NTS )
So I started to install the PHP 72
brew update
brew upgrade
Then I couldnt unlink PHP71
brew unlink php71
Error: No such keg: /Users/tavelino/.brew/Cellar/php71
So I tried to remove PHP 71
brew remove --force --ignore-dependencies httpd
... Uninstalling httpd... (1,625 files, 27.2MB)
brew remove --force --ignore-dependencies php70-xdebug php71-xdebug
brew remove --force --ignore-dependencies php70-imagick php71-imagick
brew remove --ignore-dependencies --force php70 php71
Doesn't uninstall PHP71. And I have no idea what's going on
So I tried to install php72
brew install httpd php72
...
To have launchd start php#7.2 now and restart at login:
brew services start php#7.2
Or, if you don't want/need a background service you can just run:
php-fpm
Then I also runned
brew install php72 --with-httpd --with-thread-safety
Now if I check the version:
php -v
It still PHP 71
PHP 7.1.33 (cli) (built: Jan 26 2020 22:52:32) ( NTS )
So I am trying to find a way to change the version.
#Thais Avelino, I believe this sounds more like a PATH issue.
Below is basically what I did
brew install php#7.2, php7.2 is under an version alias now
echo 'export PATH="/usr/local/opt/php#7.2/bin:$PATH"' >> ~/.bash_profile, this might be a step for your case
source ~/.bash_profile to apply the change
$ php --version
PHP 7.2.31 (cli) (built: May 28 2020 23:54:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.31, Copyright (c) 1999-2018, by Zend Technologies
$ ls -al $(which php)
-r-xr-xr-x 1 rchen staff 13912836 Jul 4 16:33 /usr/local/opt/php#7.2/bin/php
Let me know if that works out, also attach brew --version and brew config if you still run into any issue. Thanks!
Experiment with the positioning of your php path. Try moving it to the beginning.
i.e. like so...
PATH="/usr/local/php5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin: ...etc.
I used packagephp-osx.liip.ch package to upgrade to 7.3. It creates php5 alias for the folder with version 7.3, hence php5 in the PATH.
Terminal kept showing older version (7.1.33) until I modified the PATH.
Related
I have Centos 7 and Virtualmin installed, with the tipycal php-fpm 5.4, 7.0, 7.1 that you can choice between the versions you prefer on every virtualhost via Virtualmin control panel, and everything works well.
But when I access to the server via SSH and check php -v I get this:
PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
How can I select another php default/base version for the shell system?
When you issue the php command on the shell it uses the default php version on the server which in your case is php-5.4.16
To use another php version, you have to check where the binaries for those php versions are and invoke them with their full path rather than just typing php.
For example, on CentOS, for PHP 7.2 for example, the full path of the php binary is: /opt/rh/rh-php72/root/usr/bin/php
root#virtualmin /root
» /opt/rh/rh-php72/root/usr/bin/php -v
PHP 7.2.24 (cli) (built: Nov 4 2019 10:23:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.24, Copyright (c) 1999-2018, by Zend Technologies
Install versions of PHP in centos 7
Setup Yum Repository
First of all, you need to enable Remi and EPEL yum repositories on your system. Use the following command to install EPEL repository on your CentOS and Red Hat 7/6 systems
Use this command to install EPEL yum repository on your system
sudo yum install epel-release
and now execute one of the following commands as per your operating system version to install the Remi repository.
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Install PHP 7 on CentOS
Your system is prepared for the PHP installation from yum repositories. Use one of the following commands to install PHP 7.4 or PHP 7.3 or PHP 7.2 or PHP 7.1 on your system based on your requirements.
Install PHP 7.4
yum --enablerepo=remi-php74 install php
Install PHP 7.3
yum --enablerepo=remi-php73 install php
Install PHP 7.2
yum --enablerepo=remi-php72 install php
.
Check version PHP install
php -v
.
PHP 7.4.1 (cli) (built: Dec 17 2019 16:35:58) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
Install PHP Modules
You may also need to install additional PHP modules based on your application requirements. The below command will install some more useful PHP modules.
For PHP 7.4
yum --enablerepo=remi-php74 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
For PHP 7.3
yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
For PHP 7.2
yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
I'm trying to update php. When I check my php version, it returns:
php -v
PHP 5.5.12 (cli) (built: Mar 10 2017 16:27:17)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
So I added ondrej's repository
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.0
But STILL:
php -v
PHP 5.5.12 (cli) (built: Mar 10 2017 16:27:17)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
I don't know what to do anymore... Already tried purge, everything... this php doesn't upgrade, it remains this version. Any ideas?
If you have this problem while upgrading from PHP5 to PHP7 on Ubuntu 16.04
with Apache, here's what helped me (credit goes here):
Disable PHP5 module on Apache:
sudo a2dismod php5
Now enable PHP7:
sudo a2enmod php7.1
To reflect changes Apache restart is required:
sudo systemctl restart apache2
By the way run phpinfo() in your script take a look which version is this running. Command line php is a complete separate system
Try to run First :
sudo apt-get upgrade
And then : For PHP 5.5, PHP 5.6 and PHP 7.0:
sudo apt-add-repository ppa:ondrej/php
You have flipped "apt" and "add". Please take a look at your command.
Then the other steps that you made.
I know that many people has asked this question, But I believe that its all old answers, nothing worked here ..
When I've installed PhPMyadmin 4.7.0 I got this message:
The mbstring extension is missing. Please check your PHP configuration.
I tried to search on all answers, but nothing changed:
Some people asked to fix some issues in this file: /etc/httpd/conf.d/phpMyAdmin.conf
But I dont have this file at all!
Some people said that this line can fix: yum install php56-mbstring
but its not fixed.
My php-v said:
PHP 5.6.29 (cli) (built: Jan 18 2017 19:08:44)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
now what to do? How I can fix it
I found the answer:
In this page:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html
Instead of using this command: sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd
I used this one:
sudo yum install -y httpd24 php56 mysql55-server php-56-mysqlnd
Then follow all steps in this link:http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html
I want to update php version, currently I have 5.5.38 and I want 7.1
What I tried so far is using this command:
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.1
I tried several different versions but none of them worked.
It opens bash_profile for a second and then I get Received SIGHUP or SIGTERM and message below:
Buffer written to /Users/Morpheus/.bash_profile.save.6
Not sure what went wrong and why it won't update...
Any ideas?
Thanks.
Install php
brew install php#7.2
Install the required PHP to your PATH
echo 'export PATH="/usr/local/opt/php#7.2/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php#7.2/sbin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
Then make sure it's all working
php -v
php --version
This command will show you where your ini file is loaded
php --ini
Use Homebrew:
I would probably recommend installing homebrew to manage such installations for you. With that installed you can just run the following command to install php7.1
brew update
brew install php#71
The simplest way to update the version of php on Mac is via Homebrew.
If you do not have brew please visit https://brew.sh/
or install via command in terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
When finished installing Homebrew, run the following commands:
brew update && brew upgrade
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew unlink php#56
brew install php#71
You might get an error if PHP 5.6 has not been installed by brew previously, but don't worry, you can simply continue.
You can also change the version to 7.0 by replacing the command from above commands from brew install php#71 to brew install php#70.
You can check the output by command.
php -v
If the output of php -v still doesn’t echoes the version 7, simply type this command and hit enter in terminal.
export PATH=/usr/local/php5/bin:$PATH
The solutions above did not work for me on Big Sur I kept on getting:
WARNING: PHP is not recommended
PHP is included in macOS for compatibility with legacy software.
Future versions of macOS will not include PHP.
PHP 7.3.24-(to be removed in future macOS) (cli) (built: Dec 21 2020 21:33:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.24, Copyright (c) 1998-2018 Zend Technologies
To fix this I used the following steps:
Step 1 | Tap into another repository of formulae
brew tap shivammathur/php
Step 2 | Install the desired PHP version
brew install shivammathur/php/php#7.4
Other options are:
php#5.6
php#7.0
php#7.1
php#7.2
php#7.3
php#7.4
php#8.0
php#8.1 or known as just PHP
Step 3 | Link the PHP Version
brew link --overwrite --force php#7.4
Step 4 | Restart Terminal
Step 5 | Check PHP version
php -v
You should now see the new version.
PHP 7.4.25 (cli) (built: Oct 21 2021 00:29:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.25, Copyright (c), by Zend Technologies
This also solved my issues with PHP syntax in Visual Studio Code.
For me none of the mentioned worked. So to upgrade from php#7.3.11 to php#7.4 I had to install
brew update
brew install php#7.4
export PATH=/usr/local/php7.4/bin:$PATH
Then force overwrite as following:
brew link --overwrite --force php#7.4
then
php -v
output: PHP 7.4.24
Try to use below command
brew update
brew install php#72
If it shows below error,
"Error: No available formula with the name "php"
try
brew install php#7.2
try to use the command, its working fine with me
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3
In case you guys run all install commands above but when checking the PHP version, it is still linking to the old version. So you guys may want to update the PATH.
In my case, I open the .bash_profile which located in HOME directory by command:
nano ~/.bash_profile
Then, I add the path to the new version of PHP:
PATH=/usr/local/Cellar/php/7.4.4/bin:<other_paths>
Finally, run source ~/.bash_profile command to refresh the terminal window and checking the PHP version again.
Hope this helps.
Try to use below command
brew update
brew upgrade php
or
brew reinstall php
You can brew upgrade php7
or brew uninstall old php version.
Last, I recommend you brew install php-version, php-version can help you change your php version
Im running Mac OS 10.13.8 and this worked all the way to PHP version 7.3
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3.8-20190811-205217
brew install php#x.y
brew link --overwrite --force php#x.y
For Mac remember this is the last step & don't forget to kill & restart the terminal
echo 'export PATH="/opt/homebrew/opt/php#8.0/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/php#8.0/sbin:$PATH"' >> ~/.zshrc
I have installed php 5.3 manually by executing commands like make & make install. But I need to upgrade it to v5.5 therefore I deleted all the directories related to php5 using sudo command.
But when I run php -v Still I am getting
PHP 5.3.29 (cli) (built: Jun 8 2015 05:53:32) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies
Please help me to remove
The below answer credit goes to Maythux
To uninstall something you installed from source, you would use cd back into the directory you built it from and then run sudo make uninstall but I don't think this will work with PHP since it doesn't have an uninstall.
So what you can do is to make a package from the existing compiled version you have and then you could install the new created package over the old one, and if this works you can remove it. First install checkinstall if you dont have it:
sudo apt-get install checkinstall
Then run:
cd php-5.3.29
sudo checkinstall
Accept all the defaults.The result will be a phpXX.deb package, so try to install it, this will replace the old files from the compiled package:
sudo dpkg -i phpXX.deb
If this goes smooth then you are near to have it. Now purge the package:
sudo apt-get purge phpXX.deb
What to do if this doesn't work
you should remove all files manually
locate php5
Then remove the files and install a new version with apt-get again