Class Memcached Not Found Lumen 5.4 - php

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!

Related

POPOS: How to revert PHP to 8.0

I use PopOs for work. PopOs has released version 22.4 but it comes with PHP 8.1 and our development project (Laravel) uses php_cs_fixer and it currently only supports PHP 8.0. I was tasked to test if we should upgrade to PopOs 22.4 yesterday. I tested phpbrew and homebrew. Neither of them worked well. phpbrew doesn't work once I upgrade to PHP 8.1 (it has a single deprecated function in it, everywhere). Homebrew didn't seem to work and recommended editing the apache2 httpd.conf file, but our project isn't using Apache. I currently have PHP 8.0 installed (found at /usr/bin/php8.0) but the cli still says I'm using PHP 8.1.7. I used update-alternatives --set php /usr/bin/php8.0 to try and change the version the cli is using but that doesn't seem to work although when I when I execute update-alternatives --display php it reports that my link is pointing to /usr/bin/php8.0. Yet, php -v returns:
PHP 8.1.7 (cli) (built: Jun 7 2022 18:21:38) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.7, Copyright (c) Zend Technologies with Zend OPcache v8.1.7, Copyright (c), by Zend Technologies
I'm desperate, this is my work computer and I need to get this working. How does one literally revert from PHP 8.1 back down to version 8.0?
You can uninstall the php 8.1 directly through the terminal.
sudo apt remove php8.1
sudo apt autoremove
Hope this help you.

Can't update from PHP 7.1 to PHP 7.2 on Mac

To be more precise, I don't even see where PHP 7.1 is installed.
When I run php -v in the terminal, I get:
PHP 7.1.23 (cli) (built: Feb 22 2019 22:19:32) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
So I thought I would use Homebrew to unlink 7.1 and install 7.2. Should be straightforward. However, running brew unlink php71 returns an error saying:
No such keg: /usr/local/Cellar/php71
And, indeed, in /usr/local/Cellar there is nothing resembling a PHP version.
I tried running brew update and brew upgrade just in case, but it didn't help.
I also tried running a PHP application locally and did phpinfo() within the application, and I got the same version info I got in the console.
When I ran whereis php it gave me the result /usr/bin/php. When I ran whereis php71 it came up with nothing which, I suppose, is to be expected in this situation.
The question is, how do I replace PHP 7.1 with 7.2 in the least painful way? Ideally, I would like to get brew to do this so I can update future version through brew as well.
Mac OS has its own PHP version installed, which is complete independent from brew.
You need to force link your brew version.
brew link php#7.2 --force

Installing Missing Dependencies For Laravel on MacOS

If I open Terminal on my MacOS and view my php version the result is:
Jacks-MBP:Projects jackrobson$ php -v
PHP 7.2.12 (cli) (built: Nov 29 2018 01:59:12) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.12, Copyright (c) 1999-2018, by Zend Technologies
I'm also running httpd as my Apache server:
Jacks-MBP:Projects jackrobson$ httpd -v
Server version: Apache/2.4.37 (Unix)
Server built: Nov 8 2018 08:13:24
However, upon trying to configure Laravel of which I did by running this command without any errors:
composer create-project laravel/laravel demowebsite
And configure my vhost, I see this error when I view demowebsite.test:
Parse error: syntax error, unexpected '=' in /Users/jackrobson/Projects/demowebsite/vendor/laravel/framework/src/Illuminate/Support/Arr.php on line 384
I think maybe this because I don't have the dependencies needed?
Is that true or would the composer install of laravel failed?
I'm trying to figure out if the dependencies are missing.
Weirdly, upon looking at phpinfo from the base of the laravel demosite it says:
PHP Version 7.0.32
Not sure why it's not using version 7.2 as is visible in my Terminal.
Maybe that is issue.
I will investigate further and update but anyone with more wisdom who understands this, I'd appreciate a point in the right direction.
Many thanks
Edit:
Following user Caddy DZ's suggestion "Try configuring httpd to use php 7.2 instead or remove version 7.0 completely"
I was able to switch php versions using a script I initially configured php, apache, etc. last year
$ curl -L https://gist.githubusercontent.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw > /usr/local/bin/sphp
$ chmod +x /usr/local/bin/sphp
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
If that doesn't work for any observers, try this additional command:
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
This script made it easy for me to change httpd php version with the command:
Jacks-MBP:Projects jackrobson$ sphp 7.2
Sorry, but php#7.2 is not installed via brew. Install by running: brew install php#7.2
Jacks-MBP:Projects jackrobson$ brew install php#7.2
Which ran without errors and now httpd is using 7.2 and the Laravel install no longer shows the syntax error. Huzzah!
Thank you for your assistance Caddy DZ. :)
I hope these notes prove helpful to anyone who encounters a similar issue.
Try configuring httpd to use php 7.2 as the default fpm instead or uninstall version php 7.0 completely if you don't need it.
Hope this helped

Install php 5.4 on Ubuntu 16.04 Xenial

I want to install php5.4 on Ubuntu 16.04 (Xenial). I know it's obsolete but I came across an old application which I need test before updating the code to be compatible on php7.
When I do the following:
apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php5-oldstable
sudo apt-get update
sudo apt-get install -y php5
and check with php -v, it shows php5.6 installed.
This is the output from php -v:
PHP 5.6.28-1+deb.sury.org~xenial+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.5.0rc1, Copyright (c) 2002-2016, by Derick Rethans
(Steps followed as at http://tecadmin.net/install-php5-on-ubuntu/)
Is there a way I can force php5.4 to be installed instead of letting it chose whatever php5 package it finds?
I have tried with apt-get install -y php5.4 but that does not work.
Edit: Since the app was going to be used for a long time, I decided to change the whole application to php7-ready code instead. If anyone else wants to do this, be careful to test the application on different browsers and also on the OS you will be hosting the application (very important!). Took me some time but I guess it's worth it in the long run! Thanks for your help!
**EDIT:**Scratch My suggestion below. It doesn't declare the Ubu image in the Vagrantfile. Oops. Like I said, I'm a wee bit wet under the wings in all things *nix.
I'll still leave just in case it causes you to think of something.
If you run vagrant, you might be able to swap Trusty for Xeny in the scotch.io box Vagrantfile (github link) and spin it up. It's still on PHP 5.6. I've only been on linux for a month or so, so not sure how universal Vagrantfile scripts are across Ubu versions. I'm running Trusty in Azure and Xeny in Vultr and locally on desktop and laptop and haven't seen any big differences regarding web dev stuff.
https://box.scotch.io/
https://github.com/scotch-io/scotch-box
git clone https://github.com/scotch-io/scotch-box.git my-project
Features
Server Stuff
Ubuntu 14.04 LTS (Trusty Tahr)
PHP 5.6
Ruby 2.2.x
Vim
Git
cURL
GD and Imagick
Composer
Beanstalkd
Node
NPM
Mcrypt
Database Stuff
MySQL
PostreSQL
SQLite
MongoDB
Caching Stuff
Redis
Memcache and Memcached
Node Stuff
Grunt
Bower
Yeoman
Gulp
Browsersync
PM2
Laravel Stuff
Laravel Installer
Laravel Envoy
Blackfire Profiler
Mailcatcher
First: `vagrant ssh`
Run: `mailcatcher --http-ip=0.0.0.0`
Then visit: http://192.168.33.10:1080
Other Useful Stuff
WP-CLI
No Internet connection required
PHP Errors turned on
No Internet connection required
Laravel and WordPress ready
Operating System agnostic

Laravel 5.1 with php 5.5 to update to php 7 issue on OSX

I'm currently running a Laravel 5.1 app with php 5.5 and nginx on my Mac OSX, I want to update php to php 7.0 so I typed the following in terminal:
brew unlink php55
brew uninstall php55
brew install --with-fpm --with-mysql php70
It works and after that,
php -v
gives me the following response:
PHP 7.0.0RC4 (cli) (built: Oct 5 2015 03:44:48)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies
I then restarted nginx, but when I tried to echo phpinfo in my existing Laravel app, it still says current version of php is 5.5, what else do I need to setup for Laravel 5.1 to run on top of my newly installed php 7.0?
Well, turns out I didn't restart php-fpm, so after killed the old php-fpm and then
php70-fpm start
nginx -s reload
Everything worked out perfectly.

Categories