Class "Memcached" not found on Heroku - php

I am faced with this problem when I run any artisan commands on Heroku. Its a Lumen-PHP Project. I have added the "ext-memcached" to the require section of the composer.json but still gets the same result.
Screenshot of my terminal

I finally got my hands around this and thanks to the Heroku Docs on Memcached. I quote Heroku Docs:
The php-memcached client is not a pure PHP client but a PECL extention that makes use of libmemcached. You thus need to install php-memcached via your OS package manager.
Make sure you have Memcached Installed on your local machine. You can check a gist I created on how to do this for Mac OSx. I will post it here anyways.
brew install libevent
brew install autoconf
brew install libmemcached
//go to
cd /Applications/MAMP/bin/php/php{{VERSION}}/bin
//compile memcached
./pecl install memcached
//go back
cd ../
//Add the memcached.so extension to your php.ini file
echo -e "\n[memcached]\nextension=memcached.so" >> conf/php.ini
//start memcached server
memcached -m 24 -p 11211 -d
//restart MAMPP
You’ll need to modify your composer.json file to include the module:
{
"require": {
"php": ">=7.0.0",
"ext-memcached": "*"
}
}
Ensure that your new requirements are “frozen” to composer.lock by running:
composer update
Afterwards, commit your changes and run
git push heroku master
Thats it!!

Related

Having Difficulty getting Mongodb to work with PHP

I have installed mongodb on a newly installed Ubuntu 18.04 server, and while I am able to work with mongo on the command line, I cannot seem to connect to it using PHP.
I've been following the process as per https://www.youtube.com/watch?v=RQcQ5tvb5E8&t=620s:
apt install mongodb-server
apt install php-pear # to get PECL
apt install php7.2-dev # to get phpize
pecl install mongodb
phpinfo() shows extension_dir=/usr/lib/php/20170718, and mongodb.so is indeed in that directory, with the same ownership and permissions as all other files. php -i | grep extension_dir shows extension_dir => /usr/lib/php/20170718 => /usr/lib/php/20170718
I then added extension=mongodb.so to /etc/php/7.2/apache2/php.ini, in the same location as the other extensions are listed. There is also a php.ini file under /etc/php/7.2/cli/, so I added the line there to. I then restarted the apache2 service.
I created a test file under /var/www/html/mongo.php
<?php
$m = new Mongo();
var_dump($m);exit;
When I browse to that page I get a 'This page isnt working; HTTP ERROR 500' message in Chrome. I have also tried Mongodb();, MongoClient();, MongodbClient();, mongo();, mongodb();, and mongodbclient();, but all to no avail.
Please make sure you have also installed the mongodb php driver. Please confirm the php version first.
On Ubuntu you can just do:
sudo apt-get install php-mongodb
or the same for specific PHP version:
sudo apt-get install php5.6-mongo
or
sudo apt-get install php7.0-mongodb
And then restart the service.
sudo systemctl reload nginx
You should to try some of these
https://docs.mongodb.com/ecosystem/drivers/php/
https://www.php.net/manual/en/mongodb.tutorial.library.php
they should work fine with php7 + composer
Actually with composer is pretty easy(something like this):
`$ composer require mongodb/mongodb
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing mongodb/mongodb (1.0.0)
Downloading: 100%
Writing lock file
Generating autoload files
Create a File: test.php (in the same location where you ran composer)
<?php
require 'vendor/autoload.php'; // include Composer's autoloader
$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->demo->beers;
$result = $collection->insertOne( [ 'name' => 'Hinterland', 'brewery' => 'BrewDog' ] );
echo "Inserted with Object ID '{$result->getInsertedId()}'";
?>
That should be enough

Composer Install (own Container) with Docker missing PHP Extensions

I am currently learning about Docker, and using it for 2 weeks. Now i have a very simple task, installing PHP Libraries via Composer. That is usually, when working without Docker:
composer install
Now since i am using Docker, i found there is a Docker Container, that is holding composer for me:
docker run --rm -v $(pwd):/app composer/composer install
This is working pretty good, but there is some libraries out there, that require specific php libraries to be installed, like bcmath, so i add this to my Dockerfile
FROM php:7.0-apache
RUN docker-php-ext-install bcmath <-- added this line
COPY . /var/www/html
WORKDIR /var/www/html
EXPOSE 80
When i rebuild my container, this code returns true
var_dump(extension_loaded('bcmath'))
Hooray! BCMath is installed correctly, but composer does not recognize it, because the library is not installed in the composer container!
Now i could ignore that by using
docker run --rm -v $(pwd):/app composer/composer install --ignore-platform-reqs
but this is, in my opinion, a dirty workound, and composer can not validate my platform. Is there any clean solution, besides downloading composer in my Dockerfile and not reusing an existing container?
You may use platform settings to mimic your PHP container configuration. This will work similar to --ignore-platform-reqs switch (it will use PHP and extensions configured in composer.json instead of real info from current PHP installation), but it gives you more granular control. Instead of "ignore all platform requirements checks" you may say "I really have bcmath installed, trust me". All other requirements will be checked, so you still be warned if new requirement will pop-up.
"config": {
"platform": {
"php": "7.1",
"ext-bcmath": "*"
}
},
You need PHP + PHP Extensions + Composer in the same(!) container = DevContainer.
Simply install Composer using the command provided here.

Why cant I run bin/behat?

I am trying to run behat on my vendor folder. I have installed composer globally, have installed the behat package, but every time I run bin/behat I keep getting this message from composer
You must set up the project dependencies, run the following commands:
curl -s http://getcomposer.org/installer | php
php composer.phar install
I am not sure how to fix this. I see the files are in the vendor folder, and when I type "composer" on the terminal, I see the manual.
If anyone can help me resolve this I would really appreciate it. Thanks!
There are several possible problems leading to this situation:
Make sure that composer is installed in your $PATH. That is, running composer at a command prompt should work, and you shouldn't need to run an explicit path like ~/Downloads/composer.phar
Execute the composer install instruction as the error message suggests. A common error is the message
Mcrypt PHP extension required
in which case you need to install the specified extension. For example, brew install php56-mcrypt on a Mac or sudo apt-get install php5-mcrypt on Ubuntu.

Composer could not find a composer.json

I tried to install composer via brew per:
In usr/local/bin (which was not on Mavricks and I had to make personally) I did.
brew tap josegonzalez/homebrew-php
brew install josegonzalez/php/composer
I can run php composer.phar, but when I do php composer.phar install, I get the error:
Composer could not find a composer.json file in /usr/local/bin
To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section
So I go to the https://getcomposer.org/doc/00-intro.md. CTRL+F ".json" and nothing's there. Seriously composer?
EDIT:
What I was trying to do was to have composer executable vs php composer.phar. This works at this point from this now.
To install composer and add to your global path:
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
run these in terminal. It does say if you get an error that usr doesn't exist, you do need to manually make it. I know an answer was selected, so this is for anyone who may see this in the future, as i am sometimes, and don't want to be advised to visit yet another site. Its simple just two lines, might have to be in sudo if you have permission error
You are in wrong directory. cd to your project directory then run composer update.
In my case, I did not copy all project files to the folder where I was running composer install. So do:
Copy your project files (including the composer.json) to folder
open CMD (I am using ConEmu), navigate to the new folder, run composer install from there
It should work or throw errors in case the json file is not correct.
If you just want to make composer run, create a new composer.json file with for example:
{
"require": {
"php": ">=5.3.2"
}
}
Then run composer install.
The "Getting Started" page is the introduction to the documentation. Most documentation will start off with installation instructions, just like Composer's do.
The page that contains information on the composer.json file is located here - under "Basic Usage", the second page.
I'd recommend reading over the documentation in full, so that you gain a better understanding of how to use Composer. I'd also recommend removing what you have and following the installation instructions provided in the documentation.
I encountered the same error, and was able to solve it as follows:
composer diagnose to see if something is wrong with the version of composer installed
composer self-update to install the latest version
composer update to update your composer.json file.
Simple solution is install via this command :
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
To install package it's very simple :
composer global require "phpunit/php-invoker=1.1.*"
Ref : composer web site.
In my case, I am using homestead. cd ~/Homesteadand run composer install.
You could try updating the composer:
sudo composer self-update
If that doest works remove composer files & then use:
SSH into terminal & type :
$ cd ~
$ sudo curl -sS https://getcomposer.org/installer | sudo php
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo ln -s /usr/local/bin/composer /usr/bin/composer
If you face an error that says: PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1
To install package use:
composer global require "package-name"
In my case I'm in wrong directory,
My directory Path
eCommerce-shop/eCommerce
I am in inside eCommerce-shop and executing this command composer intsall so that't it throwing this error.
If you forget to run:
php artisan key:generate
You would be face this error : Composer could not find a composer.json
2 things to notice; (i did mistake and corrected with step2)
might be wrong path of compose.json in docker file. ex; if your compose.json file is not in root of repo.
OR
if using any tools to build image, specify relevant path in context.
Create a file called composer.json
Make sure the Composer can write in the directory you are looking for.
Update your composer.
This worked for me

install debian package with change configuration

I need to install php5 source debian package with zend thread safety enable (ZTS=1)
but in default this config is disable.
how can rebuild package with my configuration ?
Download and extract package sources with apt-get source php5
Edit debian/rules file and add --enable-roxen-zts or --enable-maintainer-zts to COMMON_CONFIG (confirm which one you need with ./configure --help).
sudo apt-get build-dep php5 to install build dependencies.
From directory where package source were extracted run dpkg-buildpackage -uc -b.
Optionally if you have devscripts package installed you may run debuild -uc -b instead of dpkg-buildpackage -uc -b.
Dont worry, it really takes a long time for the package build, and it also looks like it is in loop, but it will come to an end, eventually.

Categories