How to install memcached with PHP55 - php

First my web server run on Redhat6.6 and I need to build PHP by my own to enable Sybase support.
Today I want to enable memcached support.
To my knowledge I can't use yum install php55-php-pecl-memcached.x86_64 because it would also install the default php package as dependency, and make memcached enable only for its php dependency.
I looked into PECL packages, but it seems to be available for PHP5.2 only.
I installed libmemcached-devel.x86_64 but I can't phpize it because it miss some files into libmemcached folder, it seems not to be sources that phpize needs...
What can I do more

Start from scratch and there is a good way of doing it.
Install memcached through RPM
The easiest way to install Memcached is through a package manager such as yum or apt (in your case yum because its redhat). However, Memcached is not available from the default collection of packages, so the first thing we need to do is add a new RPM (Red Hat Package Manager) server so that we can install Memcached through yum.
One of the best 3rd-party RPM servers is provided by Dag Wieers, which will provide us with up-to-date packages that are not provided by Red Hat directly. The one tricky part of setting up an RPM server is making sure you get the repository that matches your server version and architecture (32-bit or 64-bit). So we need to collect that information first.
From a shell prompt, get the CentOS/RedHat version number:
$ cat /etc/redhat-release
CentOS release 5.3 (Final)
Then get the server architecture information. This is a typical response for a 32-bit machine:
$ uname -a
Linux server1.example.com 2.6.18-92.1.13.el5 #1 SMP Wed Sep 24 19:33:52 EDT 2008 i686 i686 i386 GNU/Linux
Or if you have a 64-bit machine you will probably get something like this:
$ uname -a
Linux server.example.com 2.6.18-53.1.21.el5 #1 SMP Tue May 20 09:35:07 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux
Now install the RPM server that matches your architecture and CentOS version from http://dag.wieers.com/rpm/FAQ.php#B2.
The server I was using when I wrote this was a 32-bit machine running CentOS version 5.x. So my particular server was:
http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
To install a new RPM server, we can just use the rpm command. Note that you must find the RPM server string that matches your architecture and software. Do not use the URL unless you have a 32-bit machine running CentOS 5.x, instead get the server that's appropriate from http://dag.wieers.com/rpm/FAQ.php#B2.
$ rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
Now we can simply use yum (or apt) to install Memcached:
$ yum install memcached
Afterwards you can confirm memcached is up and running by calling it.
$ memcached -h
memcached 1.2.6
Install the Memcache PECL Extension
Even though memcached is happily running on the server, it's not accessible from PHP without the PECL extension. Fortunately this is a very easy process, just use the pecl command.
$ pecl install memcache
Then add the memcache extension to your php.ini file, usually at /etc/php.ini.
extension=memcache.so
And finally restart Apache so that it will pick up the new extension:
$ /etc/init.d/apache2 restart
Running phpinfo() on your webserver should now confirm that memcache is installed:
The output of phpinfo() showing that memcache is successfully installed
Set up Memcached as a service
Just having memcache installed will not do anything by itself, we need to actually start up some instances of it for our web server to connect to, and we need memcached to automatically start up when the server restarts.
For this we need to install a new script at /etc/init.d/memcached. For this I usually use a custom script that's a bit crude, since it assumes that memcached is being used exclusively for our web server. However, most of the time this is true and it works just fine.
Download the memcached script (rename to just "memcached").
So simply load this script into /etc/init.d. Then set the permissions on it to make it executable:
$ chmod 755 memcached
Then register the script to start up with the server:
$ chkconfig --add memcached
Now you can start up memcached as a service.
$ service memcached start
And you can confirm that memcached has fired up several instances by checking ps.
$ ps -e | grep memcached
22805 ? 00:00:59 memcached
22807 ? 00:00:58 memcached
22809 ? 00:01:16 memcached
22811 ? 00:00:55 memcached
22813 ? 00:00:01 memcached
22815 ? 00:01:02 memcached
22817 ? 00:00:27 memcached
22819 ? 00:00:35 memcached
22821 ? 00:00:01 memcached
22823 ? 00:00:01 memcached
22825 ? 00:00:01 memcached

Related

Site in Laravel Valet can't find Memcache, but I see the process running—what now?

I have a local WP site that depends on Memcached. The readme says "Use memcached and the PECL memcache extension to provide a backing store for the WordPress object cache."
As a far as I can tell, my config meets those requirements. But when I attempt to access the application, I get:
Fatal error: Uncaught Error: Class 'Memcache' not found in. . .
I'm running php 7.3 installed via Homebrew, and Memcached 3.1.3, installed via PECL. Memcached 3.1.3 says it's compatible with php 7.3, and I followed these instructions to add Memcache as an extension to my php server. If I start php via Homebrew, I can see the Memcache process when I run ps -ef | grep -i memcached, and the config appears when I run php --info | grep memcached\\. But, I can't connect to Memcached through my Valet app or through Telnet.
If I run Memcached through Homebrew, I get a different version, 1.5.13, which I think predates php 7.3. As I understand Homebrew only installs stable releases. When the Homebrew Memcache is running I can connect via Telnet, but not through the Valet app.
What's different about the Homebrew install of Memcached? I assume Homebrew must somehow make Memcache externally accessible but I don't know what's going on behind the scenes.
Worked for me:
brew install libmemcached
brew install pkg-config
pecl install memcached
Push Enter to all question
Then:
cd /usr/local/etc/php/7.3
sudo vim php.ini
[memcached]
extension=/usr/local/Cellar/php/7.3.5/pecl/20180731/memcached.so
Replace path parts accordingly to your system
Finally:
brew services restart php
php -m

Could not establish Memcached connection

I'm trying to create a connection from my PHP application to Memcache, however I keep getting the error 'Could not establish Memcached connection'.
Here's my package version information
Laravel Version: 5.0.32
PHP Version:5.4.39-0+deb7u2
Database Driver & Version:mysql Ver 14.14 Distrib 5.5.31
Server&Version :Debian:7.1.
-memcached:1.4.13-0.2
-php5-memcached:2.0.1-6
I have ensured that memcached is running, as executing service memcached status yields "memcached is running".
I have two servers where my project is deployed:
ubuntu, with memcached:2.1.0 installed
debian, with memcached:2.0.1 installed
Is there a version conflict?
Fixed by myself.
My solution as follow:
1.delete memcache file and apc file in config dir
2.restart php5-fpm and memcached service.
Although issue is fixed, but I'm still not figure out why it was triggered.
This issue only occurs on the server with Debian os installed rather than the other server which with ubuntu os installed.
Hope help somebody~
i solved the problem with
sudo apt-get install memcached
sudo service memcached status
sudo service memcached start
You need to first install memcached :
sudo apt install memcached
Then you need to start it :
sudo service memcached start
After that it will connect. I resolve it by above step in my case.

memcached igbinary support

Below is my phpinfo() output for memcached
memcached
memcached support enabled
Version 2.1.0
libmemcached version 1.0.4
Session support yes
igbinary support no
json support no
I'm using an AWS Linux AMI which is redhat based I believe and uses YUM.
How can I get igbinary support enabled?
Does this have to happen at memcached installation time? I have memcached already working so is there a way I can add this support in now?
thank you
I used to compile the memcached stack manually, which included igbinary. This was before I started using the remi repo, which provides updated packages without all the overhead of manual compilation.
Here are the notes I used when I used to compile igbinary manually:
Had to scp the source from another computer due to lack of direct links, the next steps assume pecl/memcached files are local and extracted
$ -> wget http://pecl.php.net/get/igbinary-1.1.1.tgz
$ -> tar -xzvf igbinary-1.1.1.tgz
$ -> cd igbinary-1.1.1
$ -> phpize
$ -> ./configure # No need for extra config params
$ -> make
$ -> make install # This should copy the resulting .so file to the php dir where all modules are stored
$ -> /etc/init.d/httpd restart # I remember having to do this for phpinfo to reflect the setting correctly after the udpate
Now, if you view your phpinfo (or php -i from cli) igbinary support should be set to yes.
-- Update --
Be sure you have the following line in php.ini or igbinary.ini where php can read it:
; Enable igbinary extension module
extension=igbinary.so
-- Update #2 --
Forgot to mention, you need to compile memcached with the following flag in order for it to use igbinary:
--enable-memcached-igbinary
-- Update #3 --
In case anyone stumbles across this in the future. Manually maintaining the PHP stack along with commonly used extensions is a pain, and usually not worth the extra effort. You are better off using your distro's package manager to handle all the heavy lifting, an example of installing php with memcached with igbinary support would look like:
yum install php php-cli php-pecl-memcached php-pecl-igbinary
If your distro's upstream version of php is older and you wish to use a newer version, take a look at the REMI repo: http://blog.famillecollet.com/pages/Config-en
Another option, if you don't want to set it up manually, is to use PECL.
Here's an example in Amazon Linux 2:
yum -y install php-pecl-igbinary libmemcached-devel
# Install igbinary first
yes "" | pecl install igbinary
sed -i -e '/extension="igbinary.so"/d' /etc/php.ini
echo 'extension="igbinary.so"' > /etc/php.d/41-memcached.ini
# Then install memcached, being sure to set the enable-memcached-igbinary option to yes
pecl install --configureoptions 'with-libmemcached-dir="no" with-zlib-dir="no" with-system-fastlz="no" enable-memcached-igbinary="yes" enable-memcached-msgpack="no" enable-memcached-json="no" enable-memcached-protocol="no" enable-memcached-sasl="yes" enable-memcached-session="yes"' memcached
sed -i -e '/extension="memcached.so"/d' /etc/php.ini
echo 'extension="memcached.so"' >> /etc/php.d/41-memcached.ini

Good EC2 Image with memcache and php

I'm planning to use the following setup on EC2: PHP (recent version) plus memcached on an ec2 instance, and using Amazon's RDS service for the MySQL database.
Is there a recommended instance that has PHP and Memcached installed with the most often used php extensions? I am not much of a sysadmin and would prefer one that is already configured.
I don't know of any image that comes only with LAMP and memcached - but I setup something a while back - on a Amazon Linux AMI (which is a cut down centOS distro). You can always use this as a guide and set it up yourself (and create your own image afterwards).
DISCLAIMER: I'm doing this off memory- I might have missed a step or two here so read the error messages and figure out what is missing.
Install Apache, PHP, mySQL:
yum -y install httpd php mysql mysql-server php-mysql
Make sure this services start when you start your instances:
chkconfig httpd on
chkconfig –add mysqld
chkconfig mysqld on
Start apache and mySQL:
service httpd start
service mysqld start
Login to mysql and setup a root account. Create your DBs, setup users, remove test db etc.
Before we install memcached, you need to add EPEL repo to yum for extra centOS packages and then install some dependencies:
Create a new file /etc/yum.repos.d/epel.repo and paste:
[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=0
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 5 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch/debug
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-5&arch=$basearch
failovermethod=priority
enabled=0
gpgcheck=0
[epel-source]
name=Extra Packages for Enterprise Linux 5 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/5/SRPMS
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-5&arch=$basearch
failovermethod=priority
enabled=0
gpgcheck=0
Install dependencies:
yum groupinstall "Development Tools"
yum install openssl-devel openssl
Now try installing memcached:
yum install memcached
Hope it helps

Can I install the memcached PHP extension with PECL?

I'm having trouble installing the "memcached" PHP extension from PECL, though I can successfully installed the "memcache" extension. (They are separate PHP extensions.)
For example, these commands work okay:
$ sudo pecl install memcache
$ sudo pecl install APC
$ sudo pecl install oauth
However, attempting to install memcached causes errors:
$ sudo pecl install memcached
...
ld: library not found for -lmemcached
collect2: ld returned 1 exit status
make: *** [memcached.la] Error 1
ERROR: `make' failed
I'm using pecl, memcached, and libmemcached from Mac Ports (macports.org) on a recent Intel Mac. The libmemcached libraries can be found in /opt/local:
/opt/local/include/libmemcached
/opt/local/include/libmemcached/libmemcached_config.h
/opt/local/lib/libmemcached.2.0.0.dylib
/opt/local/lib/libmemcached.2.dylib
/opt/local/lib/libmemcached.a
/opt/local/lib/libmemcached.dylib
/opt/local/lib/libmemcached.la
Any idea what I may be doing wrong?
Andrei Zmievski (developer of the memcached plugin) kindly answered my email request with the following instructions:
$ pecl download memcached
$ tar zxvf memcached-1.0.0.tgz (or whatever version downloads)
$ cd memcached-1.0.0
$ phpize
$ ./configure --with-libmemcached-dir=/opt/local
$ make
$ sudo make install
This worked perfectly.
same situation here. i had to do the above, but with explicit path names (i run my php etc. out of /opt/local)
/opt/local/bin/pecl download memcached
tar zxvf memcached-1.0.0.tgz
cd memcached-1.0.0
/opt/local/bin/phpize
./configure --prefix=/opt/local --with-php-config=/opt/local/bin/php-config --with-libmemcached-dir=/opt/local
make
make install
normally this kind of stuff is pretty simple on os x with macports, but there is no php5-memcached package yet (only one for the older, memcache (no "d") package). oh, an i also had to install an older version of libmemcached, since the latest version didn't compile on os x 10.5.8 for me. oy!
As you've seen, the new memcached extension, uses libmemcached to do the heavy lifting. If it were Linux, I'd say that it was possible that you don't have /opt/local/lib/ listed in ld.so.conf (and run 'ldconfig').
MaxOSX doesn't use that though. It is, however installable from 'ports' apparently. http://lsimons.wordpress.com/2008/05/01/serious-php-part-1/
Well, after many tries only this solution works for me.
Install XAMPP
Install brew (https://github.com/Homebrew/homebrew/wiki/Installation)
$ brew
install libmemcached
cd /Applications/XAMPP/xamppfiles/bin/
$ sudo ./pecl install memcached
Build process completed successfully Installing
'/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/memcached.so'
install ok: channel://pecl.php.net/memcached-2.2.0 configuration
option "php_ini" is not set to php.ini location You should add
"extension=memcached.so" to php.ini
VOILA !!

Categories