My existing version was php8.1 using Laravel Valet 3.3.2. I did a brew php install and the php version was updated to php8.2
The site loaded fine on php8.2. When I switched to use the older version using
valet use php#8.1
I get this error
Warning: require(/MY_LARAVEL_PROJECT/public/index.php): Failed to open stream: Operation not permitted in /MY_DIRECTORY_NAME/.composer/vendor/laravel/valet/server.php on line 250
Fatal error: Uncaught Error: Failed opening required '/MY_LARAVEL_PROJECT/public/index.php' (include_path='.:/usr/local/Cellar/php#8.1/8.1.15/share/php#8.1/pear') in /MY_DIRECTORY_NAME/.composer/vendor/laravel/valet/server.php:250 Stack trace: #0 {main} thrown in /MY_DIRECTORY_NAME/.composer/vendor/laravel/valet/server.php on line 250
However, these scenarios below worked fine
valet use php#8.0
valet use php
valet use php#8.1
valet stop
php artisan serve
For this last one, the site could work if I used artisan serve instead of valet and loaded the page via 127.0.0.1:8000
I have tried most of the solutions I could find online. The most comprehensive being to uninstall and reinstall everything related to valet.
valet uninstall --force
sudo brew services stop nginx
sudo brew services stop php
sudo brew services stop dnsmasq
brew uninstall nginx
brew uninstall composer
brew uninstall php
brew uninstall php#8.1
brew uninstall php#8.0
brew uninstall dnsmasq
rm -rf ~/.config/valet
And then reinstall php, composer and valet. I tried this a few times using different combinations and ensuring the config files are removed when prompted by brew.
I've also tried setting the public folder and index.php file to 777.
The problem still persisted.
On console, when doing
php -v
I get
PHP 8.1.15 (cli) (built: Feb 3 2023 12:44:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.15, Copyright (c) Zend Technologies
with Zend OPcache v8.1.15, Copyright (c), by Zend Technologies
So it seems that this error occurs under the scenario when valet uses php8.1, which was my previous default php version. Probably some config or links related to valet that was not updated / removed.
I would appreciate if anyone can point me in any direction to investigate further. Thanks in advance!
Related
General
I am using macOS 10.13.6
So, what I want is to work with laravel 8, which requires php 8, and what I did was installing php#8.0 via homebrew:
$ brew update
$ brew tap shivammathur/php
$ brew install shivammathur/php/php#8.0
PHP 8 was installed successfully and after that, I ran this command:
$ brew link --overwrite --force php#8.0
Linking /usr/local/Cellar/php/8.0.9... 24 symlinks created.
After that I went to .bash_profile and exported /usr/local/Cellar/php/8.0.9/bin and /usr/local/Cellar/php/8.0.9/sbin to the $PATH sysvar, saved the changes and executed the command:
$ source .bash_profile restart
$ php -v
PHP 7.1.33 (cli) (built: Jan 18 2020 13:49:07) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
What I did next
Then I decided to check StackOverflow to find some useful info that could help me out.
Here it said:
tell your terminal where to find your new installed php.
export PATH="/usr/local/opt/php#8.0/sbin:$PATH"
Since /usr/local/opt/php#8.0 is a pointer to /usr/local/Cellar/php/8.0.9/, it must work as well (but it does not). Messing up with $PATH for some time has lead to nothing but a strong headache, so I decided to continue my search… Here it said:
You have to make your Apache use the PHP that you just downloaded.
I didn't know if I really needed that, but just in case I did, I added
LoadModule php8_module /usr/local/Cellar/php/8.0.9/lib/httpd/modules/libphp.so
to the apache httpd.conf file and ran:
$ sudo apachectl restart
Nothing happened. Another one contained the list of instructions, which looked like this:
brew install php#<desired_package>
brew link --force php#<desired_package>
brew services start php#<desired_package>
export PATH="/usr/local/opt/php#<desired_package>/bin:$PATH"
export PATH="/usr/local/opt/php#<desired_package>/sbin:$PATH"
That one did not work either. I'm stuck. I do not know what to do. Please, help. Thanks in advance.
EDIT: These steps did work for php#7.4 actually. Seems one cannot upgrade to php 8 on a machine running macOS High Sierra…
Add the bin directory in Homebrew's prefix to your path, then the linked PHP version should work.
echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile && source ~/.bash_profile
Also, please upgrade your macOS. Homebrew does not support High Sierra now.
I have High Sierra installed and it comes with php 7.1. During the environment I ended up being able to upgrade to php7.2 but wasn't able to document it, so I dont exactly know what I did. Now, I am trying to switch to php 7.3
Using brew, I ran the following commands:
brew unlink php#7.2
brew services install php#7.3
brew link php#7.3
If I restart my terminal and check for the php version:
php -v
I still see 7.2.25 version and not 7.3 as I desire
I also tried with a node package that I found in this link here but no success.
How do I successfully switch between php versions?
Here is my installation script:
brew install php#7.2
brew link --force php#7.2
brew services start php#7.2
export PATH="/usr/local/opt/php#7.2/bin:$PATH"
export PATH="/usr/local/opt/php#7.2/sbin:$PATH"
Now my output would be as:
$ php -v
PHP 7.2.25 (cli) (built: Nov 22 2019 10:27:28) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.25, Copyright (c) 1999-2018, by Zend Technologies
I think the PATH environment setup is something matters. And it does show in instructions as part of the installation process though.
Hope it helps resolving your issue.
Since I had to face this issue as well, let me share how to make this work.
If you have to switch back and forth on mac then this is what works for me.
Let's say you have multiple PHP versions installed 7.2 and 7.4
Now my current PHP version is 7.4 & I have to switch back to 7.2, steps will be.
brew unlink php#7.4 && brew link php#7.2 --force
nano ~/.zshrc -> Update Export Path From 7.4 to 7.2
Save It.
brew services stop php#7.4
brew services start php#7.2
Voila.
To go back to 7.4 Run brew unlink php#7.2 && brew link php#7.4 --force & uncomment export files. That's it.
Until I restarted Terminal I kept seeing the old version.
Open the terminal then run
nano ~/.zshrc
In the file that you open, you'll find the exported path of PHP as follows:
#export PATH="/usr/local/opt/php#7.4/bin:$PATH"
#export PATH="/usr/local/opt/php#7.4/sbin:$PATH"
export PATH="/usr/local/opt/php#8.2/sbin:$PATH"
Then comment the old version by adding # at the first of line and save file CTRL+x
after that close the terminal or open new one then get the php version again
php --version
I hope you have completely switched to the new PHP version
#chenrui's is perfect. I just had to create the sbin directory additionally as well.
You can find it [question]: brew link php71: Could not symlink sbin/php-fpm
When trying to run artisan commands I get the following error
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Memcached' not found
I had recently been been working on another project that used Lumen 5.3 and had no problem running artisan commands. Both projects are on the same virtual box and apart from the Lumen versions there is no differences in server setup.
I've checked that Memcached is running and there is no problems.
I've tried composer dump-autoload, deleting the vendor folder and re-installing but none of these have made a difference.
I'd prefer not to have to go back to 5.3 if possible.
Is there a way to solve this issue?
Had the same problem.
Check if you have the memcached extension installed for the php version that you're using, and check also if it is correctly configured in the php.ini file (it could be looking in the wrong directory).
looks like your memcahed is not installed or not properly configured.
for quick solution ,
use file cache driver instead of memcached
CACHE_DRIVER=file
Ubuntu 16.04 LTS, try this:
sudo apt-get install php-memcached
Just to add to the os specific responses. Here is the one using OS/X and homebrew.
First you have to determine which version of PHP you're using locally.
$ php -v
PHP 7.0.19 (cli) (built: May 21 2017 11:56:11) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
$ brew search memcached
homebrew/php/php53-memcached homebrew/php/php70-memcached
homebrew/php/php54-memcached homebrew/php/php71-memcached
homebrew/php/php55-memcached libmemcached ✔
homebrew/php/php56-memcached memcached ✔
Since I'm running PHP 7.0 I chose to install homebrew/php/php70-memcached
$ brew install homebrew/php/php70-memcached
If you don't have homebrew installed go to https://brew.sh/ and install it to use these instructions. This was the command last time I used it.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Once I was done with all that then I tested by clearing the cache.
$ php artisan cache:clear
Cache cleared successfully.
$
Cheers, this fixed it for me for local development.
If you are on Mac OSX, you will need to install Memcached and its PHP dependencies via Homebrew.
brew update
brew doctor
brew install memcached
Then check your PHP version and install your relevant PHP hooks for Memcached.
php -v
in my case...
PHP 7.1.4 (cli) (built: Apr 14 2017 15:02:16) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
So I used:
brew install php71-memcached
But you can lookup your required version using
brew search memcached
Once you have performed these steps you will probably get a new error
No Memcached servers added.
So fire it up with
brew services restart memcached
Done!
The problem:
I have installed Composer and followed the Quick start guide in the Laravel 4 documentation.
I get the following error when I run composer install or composer update:
Script php artisan optimize handling the post-install-cmd event
returned with an error...
I tried to run the following composer command:
composer create-project laravel/laravel myproject --prefer-dist
Or use their laravel.phar:
laravel new myproject
Or get the zip version from git: https://github.com/laravel/laravel?source=c
And I still fail to update via composer.
Additional information:
My PHP version on my Mac is:
PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0,
Copyright (c) 1998-2013 Zend Technologies
PHP version on MAMP: 5.4.10
I found some solutions on Google / Stack Overflow but those did not work well in my case.
It says:
MCrypt PHP extension required
So it looks like you're missing the Mcrypt extension, which is required by Laravel (actually, I think it's used only by the Authentication class for password handling, not for the rest of the components of the framework).
I haven't got a Mac, but the command to install it should be something like this, using Homebrew
brew tap josegonzalez/php
brew install mcrypt php54-mcrypt
These links might help you:
http://www.jorble.com/2013/04/install-php-mcrypt-in-macosx/
http://coolestguidesontheplanet.com/install-mcrypt-php-mac-osx-10-9-mavericks-development-server/
Having the setting xdebug.scream = 1 in the configuration was the cause of the problem for me. I fixed it by doing the following:
Find XDebug configuration file.
$ sudo find / -name xdebug.ini
Edit file using any text editor.
$ sudo vi /your_path/xdebug.ini
Set xdebug.scream = 0
Reload the server (Apache/Nginx/whatever).
$ sudo service nginx reload
You might have Mcrypt installed already on your computer, if you are using MAMP or any other application. So, you don't need to install Mcrypt again. Add the following code to a php file and place it in your htdocs directory. See the info about the PHP you are running. You can see whether Mcrypt is already installed or not.
<?php
phpinfo();
If it shows Mcript, then do the following:
Check which PHP version you are using. You can see different directories for different PHP versions in this directory: /Applications/MAMP/bin/php/.
Move to the user's home directory. Use this command on terminal: cd ~.
Edit (or create a new one if not exists) .bash_profile file.
Add the following line:
where php5.5.10 is the directory of the PHP version you are using.
export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH
Now restart your computer. And you can use php artisan command of Laravel.
Source of information: Laravel requires the Mcrypt PHP extension
I am getting a 502 Bad Gateway on my Laravel projects running Laravel valet.
I have tried many of the solutions online and with no success. i.e. https://gist.github.com/adamwathan/6ea40e90a804ea2b3f9f24146d86ad7f
At the moment the error I see is 502 bad gateway and an error in my command line when running valet install is an error when it gets to the updating PHP configuration. It gives the following error:
Warning: file_get_contents(/usr/local/etc/php/7.3/php-fpm.d/www.conf): failed to open stream: No such file or directory in /Users/username/.composer/vendor/laravel/valet/cli/Valet/Filesystem.php on line 112
Warning: file_get_contents(/usr/local/etc/php/7.3/php-fpm.d/www.conf): failed to open stream: No such file or directory in /Users/username/.composer/vendor/laravel/valet/cli/Valet/Filesystem.php on line 125
Has anybody had similar issues?
Thanks
If you're anyone like me who're seeing 502 Bad Gateway while using Laravel Valet after updating it composer global update to the latest version, you most probably forgot to run valet install command. Laravel Valet requires (in most cases) to run valet install command after updating to the latest version.
in most cases running valet install will solve the issue.
Had the same symptoms after updating to php 7.3 and then installing a new Laravel project.
It appears that brew install php73 doesn't install php-fpm
Solution is to uninstall php
brew uninstall php73
brew uninstall php72
brew uninstall php71 ... whatever versions you have
brew uninstall --force php
Now reinstall php
brew install php --build-from-source
I encountered permission errors mkdir: /usr/local/etc/php/7.3/php-fpm.d: Permission denied so sudo chown -R: <yourusercode> /usr/local/etc/php fixed that and then brew install php --build-from-source again. Once it builds php 7.3 successfully reinstall valet:
valet install
None of the above answers worked for me, but found the solution here: https://janostlund.com/2019-06-20/502-bad-gateway-laravel-valet
~/.config/valet/Log/nginx-error.log shows:
[error] 17423#0: *1 upstream sent too big header while reading response header from upstream [...]
Solved by adding two lines to http in /usr/local/etc/nginx/nginx.conf
http {
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
//...
}
and then running valet restart
I solved this by doing:
php -v
PHP 8.0.1 (cli) (built: Jan 8 2021 09:07:02) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.1, Copyright (c) Zend Technologies
with Zend OPcache v8.0.1, Copyright (c), by Zend Technologies
followed by:
valet use php#8.0 --force
Unlinking current version: php
Linking new version: php#8.0
Updating PHP configuration...
Restarting php...
Restarting nginx...
Valet is now using php#8.0.
Valet seemed to be confused over which PHP it was using.
I ran into the same problem with Laravel 8. Both Valet and Expose seemed to work, but the webpage always gave a 502 response.
The solution I found when I updated composer and tried to reinstall Valet was that Valet didn't know which version of php to use.
To fix this, use the following command to tell valet which version of php to use.
valet use php#7.4
Try this
brew services start php
If it didn’t work, try to reinstall php from source
brew uninstall php
brew install php --build-from-source
valet install
Source: laravel/valet github issues
Well, normally "valet install" solves the issue but for me it was different.
For my case, I was using valet isolate for a different project with different PHP versions. So, I have to do the binding process again.
I did,
valet install
valet isolate php#7.1 (Here you have to use the selected version)
this solves the issue for me.
In my case I reinstalled different version of php. I just run
valet install
and it worked fine.
I had the same problem. I solved it by upgrading mariadb. brew upgrade mariadb
Following the config above, but put it in the file.
~/.valet/Nginx/all.conf
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
This did catch on all the sites "Im use Valet plus"
If the valet restart or valet install didn't work, try to change the PHP version.
valet use php#7.4
Or
valet isolate php#7.4
My nginx-error.log file was full of messages like this
*3 connect() to unix:/home/oakbox/.valet/valet.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1
It took me too long to figure out that php-fpm was running, but that Nginx could not 'see' that socket. Look in your Nginx configuration file for the line that starts with
fastcgi_pass unix:/home/oakbox/.valet/valet.sock;
And then look to see if that socket actually exists. In my setup, an update of my system moved my default PHP installation from version 8.1 to 8.2. The actual socket file was renamed from valet.sock to valet82.sock.
I edited my Nginx configuration files to point to the real location of the socket
fastcgi_pass unix:/home/oakbox/.valet/valet82.sock;
A restart of Nginx and my 502 Bad Gateway went away.