OK so I am experiencing something quite odd. My phpinfo() shows one version while php -v shows another.
I am running locally on a MacBook Air (Mojave), with Laravel and Valet.
phpinfo():
PHP Version 7.2.13
Configuration File (php.ini) Path /usr/local/etc/php/7.2
Loaded Configuration File /usr/local/etc/php/7.2/php.ini
Scan this dir for additional .ini files /usr/local/etc/php/7.2/conf.d
While in my terminal, it shows:
php -v
PHP 7.3.0 (cli) (built: Dec 7 2018 11:00:11) ( NTS )
Now, if I do a which php I get this:
/usr/local/bin/php
In my ~/.bash-profile, I have this:
export "PATH=~/.composer/vendor/bin:$PATH"
I have tried to:
Restart Nginx
Restart Valet
Unlink PHP#7.2 and link PHP#7.3with Homebrew:
Olivers-MacBook-Air:~ oliverbusk$ brew unlink php#7.2
Error: No such keg: /usr/local/Cellar/php#7.2
How can I get my actual valet site to use php#7.3?
Below simple fix worked for me.
rm ~/.config/valet/valet.sock
valet restart
In my case it worked after forcing the specific PHP version:
valet use php#7.4 --force
Good news, please upgrade to latest valet version, you can easily switch php version.
Source: https://laravel.com/docs/5.8/valet
PHP Versions
Valet allows you to switch PHP versions using the valet use php#version command. Valet will install the specified PHP version via Brew if it is not already installed:
valet use php#7.2
valet use php //without any specification, it will be using latest version
Something so basic as rebooting my Macbook solved this issue. Once rebooted, the correct version 7.3 showed in my phpinfo();
From MacBook pro (Mojave), with Laravel and Valet:
valet use php#7.2
To be able to effectively change the version of php on my machine I use the following script:
Add to your user's .bash_profile
Then use the following command to switch
switch-php7.x
switch-php() {
valet stop
brew unlink php#7.2 php#7.3 php#7.4
brew link --force --overwrite php#$1
brew services restart php#$1
composer global update
rm -f ~/.config/valet/valet.sock
valet install
}
https://gist.github.com/r1tt3r/e0f199eb274d5ff186b73956af594316
I am running linux valet on Ubuntu 20.04 , The following command works for me
valet use 8.0
Here, 8.0 refers to the php version.
NB: Tested this solution on Ubuntu 20.04 Desktop
If you are using Valet Linux Plus(Has more features than Valet Linux) Just do valet use {your PHP version} --update-cli. For instance to use php8.0 just run:
valet use 8.0 --update-cli
This will update both php-fpm version plus php-cli version too.
Basically the php valet uses and the one used by your macbook is different.
But as already mentioned by #Shiro and #Israel Alexis Palma Quezada, in newer versions valet use php73 would solve your problem.
If it's not working, try running composer global update to update your global packages, thus updating valet
To update the mac php version, execute the following lines:
export PATH="your/path/to/php#7.3/bin:$PATH"
export PATH="your/path/to/php#7.3/sbin:$PATH"
or simply add these two lines to your ~/.profile or ~/.bash_profile
Don't forget to run source ~/.profile or source ~/.bash_profile or whatever file you chose to edit.
Yesterday I encountered the same problem on Ubuntu 18.
At first I changed the PHP version:
$ sudo a2dismod php7.2
$ sudo a2enmod php7.3
$ sudo update-alternatives --set php /usr/bin/7.3
But valet was still showing the wrong PHP version. Rebooting did not work. In fact, phpinfo() was displaying PHP 7.1.
After run ps -aux | grep php I noticed few instances of php-fpm (5.6, 7.1 and 7.2) running.
I stopped them
$ sudo service php5.6-fpm stop
$ sudo service php7.1-fpm stop
$ sudo service php7.2-fpm stop
Then started 7.3
$ sudo service php7.3-fpm start
And now my phpinfo() display the correct version of PHP
I ran into this same problem while using valet plus today. When I switched PHP versions it was showing the previous one in my browser but the correct one in my terminal. Looking at the my brew services list:
brew services list
It showed that one of the valet-php services (valet-php#7.2) was not in the service list but somehow my valet was able to switch to it. Valet didn't install this PHP properly and that's what was causing the issue. I did the following to uninstall that PHP and reinstall it with brew.
brew uninstall valet-php#7.2
sudo rm -rf /usr/local/Cellar/valet-php#7.2/7.2.34_1
brew install valet-php#7.2
The PHP version that was once not showing in the brew services list now showed and I was able to "stop" that php version's service:
brew services stop valet-php#7.2
which made everything work properly again without a restart.
Related
I always get stuck on upgrading php... I have done:
brew link php#8.1 --force --overwrite
If I run it again I get
Warning: Already linked: /opt/homebrew/Cellar/php/8.1.9
When I run
valet use php#8.1 --force
and then
valet use php#8.1
I get
Valet is already using version: php#8.1
But when I run
php -v
I get
PHP 8.0.22
I have also done
valet restart
and restarted my computer.
Previously in my zshrc I had:
export PATH="/opt/homebrew/opt/php#8.0/bin:$PATH"
export PATH="/opt/homebrew/opt/php#8.0/sbin:$PATH"
I have commented these out and added:
export PATH="/opt/homebrew/sbin:$PATH"
and then
brew services restart php && valet restart
If I then run
brew doctor
I still get:
Warning: Homebrew's "sbin" was not found in your PATH but you have installed
formulae that put executables in /opt/homebrew/sbin.
Consider setting your PATH for example like so:
echo 'export PATH="/opt/homebrew/sbin:$PATH"' >> ~/.zshrc
The issue was that you have to restart the terminal before the new config changes take effect...
After Mac OS full reinstall I perform php 8.0 install by brew install php.
Unfortunately, brew didn't make this version active: php --version report about 7.3 (not recommended version).
I cannot unlink this version because it's not installed by brew, so brew link also doesn't have much sense.
How to bring latest php to system level and completely forget about php7.3 ?
You'll need to tell your terminal where to find your new installed php.
export PATH="/usr/local/opt/php#8.0/sbin:$PATH"
And you need to add it to the bash_profile if you want all terminals to keep using your installed version.
echo 'export PATH="/usr/local/opt/php#8.0/sbin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
This is for terminal use only. So not for your web servers.
In the future, when you install other versions, you can update the profile with:
nano ~/.bash_profile
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)
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.
My operating system is:Mac OSX 10.11
I'm trying to install Phabricator on my Mac, when I execute the command of
phabricator cpopt$ ./bin/phd start
I got an error:
"ERROR: The PHP extension 'pcntl' is not installed. You must install it to run daemons on this machine."
I've search this problem on google and I got lots of solutions,but they all don't work to me,I'm almost in despair.
How can I achieve that?
Do you have brew installed (read here to install http://brew.sh/)?
Try:
brew install php
or if you need to install PHP 5.6 with brew you could do this:
brew install php#5.6
Then to include it in your PATH (if it is not automatically added), it may be necessary to run the commands in the CLI you may need to update your path, e.g. (this is the case if you were to brew install php#7.1 but was not the case when I just tested with brew install php - if you are using bash instead of zsh, change .zshrc to .bashrc.
echo 'export PATH="/usr/local/opt/php#7.1/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php#7.1/sbin:$PATH"' >> ~/.zshrc
If that doesn't work, I wonder if phabricator is calling the right version of php.
Out of curiosity, what is the output you get from this? That is what phabricator is using to determine your php version.
/usr/bin/env php -v
Also... is your php.ini updated to have the pcntl extension? Run this to see your modules and look for pcntl:
php -i | grep pcntl
Double-check the php.ini that the php-cli is running:
php -i | grep php.ini
I had to do this to install the platform.sh command line tool. This was the top hit in Google so I'm adding this information. The process I followed was as below.
In Terminal:
Add yourself to the 'wheel' user group.
sudo dscl . append /Groups/wheel GroupMembership <username>
Grant group write access to /usr/local/bin
sudo chmod -R g+w /usr/local/bin
Link libpng for brew
brew link libpng
Install pcntl for php (5.6 in my case)
brew install homebrew/php/php56-pcntl
Just in case anyone else uses MAMP, I recently updated it to the latest version. Then I was getting the error
"ERROR: The PHP extension 'pcntl' is not installed. You must install it to run daemons on this machine."
I had not restarted my terminal since I updated it. After reloading the session everything worked fine.