Installing memcached on Amazon Linux - php

I am trying to use memcached for PHP on a Amazon Linux EC2 instance. In my PHP script when I call $mc = new Memcached(); the following error gets thrown in /var/log/php-fpm/www-error.log:
[06-Sep-2020 00:49:44 UTC] PHP Fatal error: Uncaught Error: Class 'Memcached' not found in /var/app/current/memcached.php:8
Stack trace: #0 {main}
thrown in /var/app/current/memcached.php on line 8
Calling php -m I do not see memcached listed, which I assume means it is not installed.
So, first I tried:
sudo yum install memcached
sudo yum install php70-pecl-memcached
along with edits to /etc/php.ini to include
session.save_handler = memcached
session.save_path = "127.0.0.1:11211"
as outlined here but no luck.
So next, I tried the suggestion as outlined by AWS support here for Amazon Linux EC2 v1. Looking through cfn-init-cmd.log, the package libmemcached is installed successfull, however, the script fails when it tries to install memcached as it is unable to find /use/bin/pecl7 as per the command 01_install_memcached. For reference, my full script in .ebextensions/memcache.config was:
packages:
yum:
libmemcached-devel: []
commands:
01_install_memcached:
command: /usr/bin/yes 'no'| /usr/bin/pecl7 install memcached
test: '! /usr/bin/pecl info memcached'
02_rmfromphpini:
command: /bin/sed -i -e '/extension="memcached.so"/d' /etc/php.ini
03_createconf:
command: /bin/echo 'extension="memcached.so"' > /etc/php-7.3.d/41-memcached.ini
test: '/usr/bin/pecl7 info memcached'
Any ideas on how to resolve?

So this slightly revised .ebextension script worked. I'm no AWS/Linux/PHP expert, so there is probably a more correct way to approach this.
packages:
yum:
libmemcached-devel: []
commands:
01_install_memcached:
command: /usr/bin/yes 'no'| /usr/bin/pecl install memcached
test: '! /usr/bin/pecl info memcached'
02_rmfromphpini:
command: /bin/sed -i -e '/extension="memcached.so"/d' /etc/php.ini
03_createconf:
command: /bin/echo 'extension="memcached.so"' > /etc/php.d/41-memcached.ini

I solved this by adding memchache directly into installation
packages:
yum:
libmemcached-devel: []
memcached
commands:
01_rmfromphpini:
command: /bin/sed -i -e '/extension="memcached.so"/d' /etc/php.ini
02_createconf:
command: /bin/echo 'extension="memcached.so"' > /etc/php.d/41-memcached.ini

Related

How to Install PHP IMAP Extension on AWS Elastic Beanstalk Using Configuration Files (.ebextensions)?

Does anyone know how to install and enable PHP IMAP Extension on AWS Elastic Beanstalk using configuration files (.ebextensions)?
I'm using 64bit Amazon Linux 2017.03 v2.4.0 running PHP 7.0.16
I've tried several ways as follow:
1st Way
I've tried using files in configuration file but it doesn't work, the configuration filename is phpini.config in .ebextensions directory with below setup:
files:
"/etc/php.d/phpimap.ini":
mode: "000755"
owner: root
group: root
content: |
extension=imap.so
The additional .ini files parsed into phpinfo() by displaying /etc/php-7.0.d/phpimap.ini but the IMAP won't installed.
2nd Way
Using container_command to install php-imap but i'm getting error.
container_commands:
install_php_imap:
command: yum install php55-imap
Error as image below:
3rd Way
Using combined commands & files, it is only success installing IMAP and the dependencies (php common) but it doesn't activate the IMAP
a. Create installdependencies.config in my .ebextensions by adding bellow script:
commands:
install_phpcommon:
test: '[ ! -f /etc/php.d/curl.ini ] && echo "php common not installed"'
command:
yum -y install https://archipelagointernational.s3.amazonaws.com/libs/php70w-common-7.0.16-1.w6.x86_64.rpm
b. Create phpini.config in my .ebextensions by adding bellow script:
commands:
install_phpimap:
test: '[ ! -f /etc/php.d/imap.ini ] && echo "php imap not installed"'
command:
yum -y install https://archipelagointernational.s3.amazonaws.com/libs/php70w-imap-7.0.16-1.w6.x86_64.rpm
files:
"/etc/php.d/imap.ini":
mode: "000755"
owner: root
group: root
content: |
extension=imap.so
4th Way I'm testing by adding upload_max_filesize, post_max_size and extension=imap.so to zzzphp.ini and only two values are included that are upload_max_filesize and post_max_size. The extension=imap.so not included into zzzphp.ini file.
Below are the script phpini.config in .ebextensions:
commands:
install_phpimap:
test: '[ ! -f /etc/php.d/imap.ini ] && echo "php imap not installed"'
command:
yum -y install https://archipelagointernational.s3.amazonaws.com/libs/php70w-imap-7.0.16-1.w6.x86_64.rpm
files:
"/etc/php.d/zzzphp.ini":
mode: "644"
content: |
upload_max_filesize = 50M
post_max_size = 58M
extension=imap.so
Any suggestions?
Thanks in advance.
Finally it's work
Create two files inside .ebextensions as follow:
installdependencies.config, install php common if it is required
commands:
01_install_phpcommon:
command:
sudo yum -y install php70-common
phpini.config, install php imap and enable imap
commands:
02_install_phpimap:
command:
sudo yum -y install php70-imap
files:
"/etc/php.d/zzzphp.ini":
mode: "644"
content: |
extension=imap.so
For me, below code in phpini.config solved the issue. Please notice the folder names as per php version. My php version is 7.2 hence below code works:
commands:
install_phpimap:
test: '[ ! -f /etc/php-7.2.d/imap.ini ] && echo "php imap not installed"'
command:
sudo yum -y install php72-imap
files:
"/etc/php-7.2.d/imap.ini":
mode: "000755"
owner: root
group: root
content: |
extension=imap.so
You’re including the php-imap extension in php’s configuration file, but that’s not sufficient to install it.
You’re going to have to pass something to your EBS provisioning method of choice telling it to install php-imap (or whatever it’s called in that environment) at the system level.
I followed all of the suggestions here but my commands kept on failing because my composer required imap support and the container commands are run after...
Here's what worked for me:
packages:
yum:
php72-imap.x86_64: []
This works for me, using ebextensions too (I'm running a container with PHP 7.2, it should work for your environment, replace accordly):
packages:
yum:
php72-imap: []

Solr Solarium and Curl throwing an error

I recently installed Solarium (with Java 8 on Ubuntu 14.04, PHP 5.5).
I created a core called test :
$ sudo -u solr /opt/solr-6.5.1/bin/solr create -c test
Then I indexed in it the "techproducts" example :
$ bin/post -c test example/exampledocs/*.xml
So I then tried to execute a PHP file given as an example with Solarium. In SSH I do :
$ php 1.2-basic-select.php
And it works, it shows the content indexed.
But, when I open this same PHP file with a browser, I've got an error :
Fatal error: Uncaught exception 'Solarium\Exception\RuntimeException' with message 'cURL is not available, install it to use the CurlHttp adapter' in /var/www/html/cvrecruteur.com/slr/vendor/solarium/solarium/library/Solarium/Core/Client/Adapter/Curl.php:228
Curl and php-curl are installed and up to date so I don't really know what's the deal here.
try to install PHP5 CURL by typing sudo apt-get install php5-curl
If you're really sure that php5-cur are installed, try to restart your apache instance.

CQLSH client - module' object has no attribute 'parse_options

I'm trying to access my Cassandra server through a CQLSH client to import a huge CSV file. I'm getting a module' object has no attribute 'parse_options error.
I run the follow command:
cqlsh XXX.XXX.XX.XX XXXX --cqlversion="3.4.2" --execute="copy evolvdso.teste from '2016-10-26 15:25:10.csv' WITH DELIMITER =',' AND HEADER=TRUE --debug";
This is the debug and error message that follows:
Starting copy of evolvdso.teste with columns ['ref_equip', 'date', 'load', 'ptd_assoc'].
Traceback (most recent call last):
File "/usr/local/bin/cqlsh", line 1133, in onecmd
self.handle_statement(st, statementtext)
File "/usr/local/bin/cqlsh", line 1170, in handle_statement
return custom_handler(parsed)
File "/usr/local/bin/cqlsh", line 1834, in do_copy
rows = self.perform_csv_import(ks, cf, columns, fname, opts)
File "/usr/local/bin/cqlsh", line 1846, in perform_csv_import
csv_options, dialect_options, unrecognized_options = copyutil.parse_options(self, opts)
AttributeError: 'module' object has no attribute 'parse_options'
Has the same issue when I use cqlsh from pip install cqlsh.
Try just use cassandra's tool cqlsh
sudo docker run -it cassandra /usr/bin/cqlsh
Refer to jira
I met a similar problem, the reason for my scenario is that the default cqlsh path is /usr/local/bin/cqlsh. (check with command $ which cqlsh)
Solution: using Cassandra shipped /usr/bin/cqlsh to connect the Cassandra server or run some command. For example, connect to Cassandra server using command:
$ /usr/bin/cqlsh <cassandra_listen_ip>
OR run command with
$ /usr/bin/cqlsh <cassandra_listen_ip> -e "<command>"
Looks like the pip version has some issues, you should install via the official packages instead like:
apt install wget apt-transport-https
wget -q -O - https://www.apache.org/dist/cassandra/KEYS | apt-key add -
sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'
apt update
apt install -y cassandra
Note this will also include the cassandra services, so if you don't want those to be running you may have to manually disable them.
Answer in 2020:
To use cassandra's cqlsh use docker run -it cassandra /opt/cassandra/bin/cqlsh
If you are using bitnami's cassandra image, cqlsh is located at /opt/bitnami/cassandra/bin/cqlsh
And then COPY keyspace.table TO '/tmp/my_table.csv';

How do I uninstall a PHP module?

I bumped into this bit of instructions while installing an addon for a PHP framework:
Make sure you don't have the PHP module installed. This is a Debian/Ubuntu example:
sudo apt-get purge php5-geoip
I am working on Windows PC with a Virtual Machine running Laravel Homsetead. I am using Git Bash command window. When I enter the above command I get:
bash: sudo: command not found
If I remember correctly, sudo is an Apple-related command so I tried dropping it like this:
apt-get purge php5-geoip
but I get
bash: apt-get: command not found
What command do I need to use to purge php5-geoip?
EDIT: echo $PATH gives out:
$ echo $PATH
/c/Users/Arthur/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/
bin:/c/Users/Arthur/bin:/c/ProgramData/Oracle/Java/javapath:/c/Windows/system32:
/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/
c/Program Files (x86)/Intel/OpenCL SDK/2.0/bin/x86:/c/Program Files (x86)/Intel/
OpenCL SDK/2.0/bin/x64:/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/c
/Program Files/MATLAB/MATLAB Production Server/R2015a/runtime/win64:/c/Program F
iles/MATLAB/MATLAB Production Server/R2015a/bin:/c/Program Files/MATLAB/MATLAB P
roduction Server/R2015a/polyspace/bin:/c/Program Files (x86)/Skype/Phone:/c/PHP:
/c/ProgramData/ComposerSetup/bin:/c/Users/Arthur/AppData/Roaming/Composer/vendor
/bin:/c/HashiCorp/Vagrant/bin:/c/Program Files/nodejs:/c/Users/Arthur/AppData/Ro
aming/npm:/usr/bin/vendor_perl:/usr/bin/core_perl

installing PHP module from Elastic Beanstalk

I am trying to configure my AWS Elastic Beanstalk to work with mongo, all I need to do is install the mongo driver for PHP and update the php.ini file
To do this, usually I would ssh into the EC2 and run:
sudo pecl install mongo
But this would require using a custom AMI which isnt the best way to go.
It is better to use config files to install the software required onto the standard AMI.
So to do this, I have done the following:
created directory .ebextensions
created file mongo.config
in it I have put the following:
packages:
pecl: install mongo
However upon deployment, I get the following error:
"option_settings" in one of the configuration files failed validation. More details to follow.
and
'null' values are not allowed in templates
So I am wondering how this config file needs to be laid out in order to install the mongo extension?
I have read the info here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
but I am not quite understanding how to do this specific task
Help would be appreciated , thanks! :)
pecl is not a valid package manager on Amazon Linux and therefore cannot be used under the packages key of an .ebextensions config.
To install a PECL package it is enough to add a single command under the commands key. To avoid that Beanstalk tries to install the extension twice on follow-up deployments add a PHP console command to the test key that checks if the extension is already installed:
commands:
install_mongo_driver:
command: pecl install mongo
test: "php -r \"exit(extension_loaded('mongo') ? 1 : 0);\""
If the test result is true, i.e. exit(0), then the command gets executed - otherwise not. Please note that a exit code of 0 means "No errors" in a shell context.
See also the description at http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-commands.
I have figured it out and thought I would share what I found. Thanks to Hudku (http://blog.hudku.com/2013/02/innocuous-looking-evil-devil.html#elastic-beanstalk.config) for the excellent article:
1) Create myapp.config
2) enter the following into it
packages:
yum:
dos2unix: []
container_commands:
01-command:
command: rm -rf /myapp/ebextensions
02-command:
command: mkdir -p /myapp/ebextensions
03-command:
command: cp -R .ebextensions/* /myapp/ebextensions/
04-command:
command: dos2unix -k /myapp/ebextensions/mongo.sh
05-command:
command: chmod 700 /myapp/ebextensions/mongo.sh
06-command:
command: bash /myapp/ebextensions/mongo.sh
Then create mongo.sh file and put in it something like:
#!/bin/bash
if [ ! -f /mongostatus.txt ];
then
pecl install mongo
echo "mongo extension installed" > /mongostatus.txt
apachectl restart
fi
This will install mongo php extension and restart apache so the install takes affect.
I just accomplished the same thing thanks to the answer above, and figured out it can be done with less lines and less files for those interested...
# ~/project/.ebextensions/project.config
# Logger messages can be viewed in /var/log/messages
files:
"/tmp/test.sh":
content: |
# This file will be created and can then
# be executed by a command call below.
logger TEST FILE CALLED
commands:
01-command:
command: logger CALLING TEST FILE; sh /tmp/test.sh;

Categories