5

I am trying to setup php memcached extension on mac OS High Sierra. I am running php 7.2

Output of php -v:

PHP 7.2.6 (cli) (built: May 25 2018 06:18:43) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.6, Copyright (c) 1999-2018, by Zend Technologies

I installed memcached via pecl without any error:

pecl install memcached

It is enabled in php.ini file:

extension="memcached.so"

When I run <?php echo phpinfo();?> on my Apache server. I can see session configured:

session.save_handler    memcached   memcached

My symfony application gives me still this error:

(1/1) ClassNotFoundException
Attempted to load class "Memcached" from the global namespace.
Did you forget a "use" statement?

EDIT:

My apache is running a different version of php (PHP Version 7.1.16) I don't know why but I think this cannot be a problem.

In info file I can see in the CORE section that php extension dir is "/usr/local/lib/php/pecl/20170718". When I open that directory there is memcached.so file. The path is correct.

EDIT 2:

In my apache logs I see warning:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/pecl/20170718/memcached.so' - dlopen(/usr/local/lib/php/pecl/20170718/memcached.so, 9): Symbol not found: _zend_empty_string\n  Referenced from: /usr/local/lib/php/pecl/20170718/memcached.so\n  Expected in: flat namespace\n in /usr/local/lib/php/pecl/20170718/memcached.so in Unknown on line 0
Joozty
  • 460
  • 2
  • 12
  • 40
  • 1
    "on my Apache server. I can see memcached enabled" is wrong. What you see is that you set session save handler to memcached. You should see a separate memcached block in phpinfo output, i.e. a separate table with those purple and grey colours. Check which ini file Aapache mod is using, it's also in there. – marekful Jun 14 '18 at 09:56
  • In that case I don't see it but I can see memcached extension when I run this command `php -m | grep memcached` – Joozty Jun 14 '18 at 09:59
  • Have you verified that the ini file phpinfo is telling is in use is the one you are editing? Are you sure php -m lists 'memcached' and not 'memcache'? – marekful Jun 14 '18 at 10:02
  • Yes I have. My apache is using different `php.ini` file in `/etc/php.ini` but it is enabled there as well and yes it is memcached not memcache. – Joozty Jun 14 '18 at 10:06
  • Surely, PHP isn't loading those ini files in which the module is enabled since then you would see the memcached block in phpinfo output. It is quite clear from the values in 'Loaded Configuration File' and 'Additional .ini files parsed' which files are loaded. – marekful Jun 14 '18 at 10:08
  • Yes you are right but I am 100% sure that I am editing right `php.ini`. `Loaded Configuration File /etc/php.ini`. Maybe there can be a problem with php version. My php -v shows 7.2.6 but apache shows 7.1.16? is it possible to change it? – Joozty Jun 14 '18 at 10:27
  • For using memcache with PHP we also need php-memcached – SynapseIndia Jun 14 '18 at 10:52
  • Check out https://stackoverflow.com/questions/42909397/laravel-5-4-on-php-7-0-pdo-exception-could-not-find-driver-mysqlc/42925908#42925908 . You seem to be using a different PHP configuration on CLI and Apache. You need to make sure you're using the same ones – apokryfos Jun 25 '18 at 15:58

1 Answers1

1

So. Apache and SLI php version use diferent php.ini files. For examle on my Debian 9 it use /etc/php/7.2/apache2/php.ini and /etc/php/7.2/cli/php.ini

I believe your problem is that you are using a different version of PHP.

Just try comands below:

$sudo a2dismod php7.1
$sudo a2enmod php7.2
$sudo service apache2 restart

If you still get same Error try create info.php in your www root dir thich conteint next code:

<?php
phpinfo();

And check Memcache are loaded.

Lakremon
  • 787
  • 1
  • 8
  • 26
  • Thanks but these commands doesn't exist on MacOS. I am getting `sudo: a2dismod: command not found` – Joozty Jun 20 '18 at 12:38
  • So, ok! Can you create info.php which conteint " – Lakremon Jun 20 '18 at 12:50
  • Did you used brew to install apache & php? – Lakremon Jun 20 '18 at 12:53
  • I already did it. My php.ini is located in `/etc/php.ini`. In that file I added `extension="memcached.so"` and restarted Apache. But it didn't work. When I run Symfony built-in server (on the php7.2) everything works fine and memcached is loaded. – Joozty Jun 20 '18 at 12:54
  • Apache was preinstalled. And I upgraded php via brew. – Joozty Jun 20 '18 at 12:55
  • Which php apache modules availible in your /etc/httpd/httpd.conf? It showld be something like 'LoadModule php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so'. – Lakremon Jun 20 '18 at 13:00
  • I'm pretty sure your cli and apache use different php.ini files. If your apache use `/etc/php.ini` and you added extension line it mean you have't memcache.so in your php7.1 version extension_dir. – Lakremon Jun 20 '18 at 13:10
  • `LoadModule php7_module libexec/apache2/libphp7.so` Yes, you are right and I mentioned it in my description of problem. My extension_dir is correct for apache configuration - `/usr/local/lib/php/pecl/20170718`. I edited my question with log from apache. – Joozty Jun 20 '18 at 13:18
  • What returns `pecl version` ? – Lakremon Jun 20 '18 at 13:25
  • `PEAR Version: 1.10.5 PHP Version: 7.2.6 Zend Engine Version: 3.2.0` - but this is from my CLI. – Joozty Jun 20 '18 at 13:27
  • Let's try reconfig your cli PHP version. What returns `ls -Al /usr/bin | grep php`? – Lakremon Jun 20 '18 at 13:33
  • `-rwxr-xr-x 1 root wheel 11157808 30 May 00:36 php` – Joozty Jun 20 '18 at 13:40
  • Bad case. =) Let's try `php --ini`. – Lakremon Jun 20 '18 at 13:50
  • `Configuration File (php.ini) Path: /usr/local/etc/php/7.2 Loaded Configuration File: /usr/local/etc/php/7.2/php.ini Scan for additional .ini files in: /usr/local/etc/php/7.2/conf.d Additional .ini files parsed: /usr/local/etc/php/7.2/conf.d/ext-opcache.ini` – Joozty Jun 21 '18 at 12:16
  • Ok! As you can see your php7.2 placed in /usr/local/. Let's try `grep -r "libphp7.so" /usr/local` or `grep -r "apache2/libphp" /usr/local` – Lakremon Jun 21 '18 at 13:48
  • What am I looking for? There were more grep matches. – Joozty Jun 21 '18 at 15:40
  • We are looking for a libphp7.so file for which allow us configure apache2 with php7.2 version. it should be some thing like this - `#LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so`. Also we can try reinstall apache2 via brew. (https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions) – Lakremon Jun 22 '18 at 03:22