How to enable the memcached PHP extension after installing with homebrew? - php

I recently installed memcached with homebrew, I'm not entirely sure how to enable it on my PHP envirionment since I added extension=memcached.so in /etc/php.ini in Lion OS X.
Even I restarted apache too, nothing is still loaded.
If I call get_loaded_extensions(), I do not see memcached in the list, how can I enable it when installed from homebrew?
EDIT:
What I did in Terminal was:
$ brew install memcached
It installed just fine, now I went to /etc/php.ini and appended:
extension=memcached.so

Install Memcached:
# lists all memcached related packages
brew search memcached
# install memcached as well as memcached extension for PHP
brew install memcached
brew install php54-memcached
# start memcached daemon with 24MB on port 11211 (default)
memcached -d -m 24 -p 11211
Add to your php.ini file to add:
extension=memcached.so
Restart php or php5-fpm and your server. Verify:
php -i | grep memcached
# should show memcached version, etc.

Install:
brew install memcached
OR
sudo pecl install memcached
Add this line to /etc/php.ini:
extension = memcached.so
OR
extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/memcached.so"
If you are having trouble finding where it lives do
mdfind memcached.so -name
=> /usr/lib/php/extensions/no-debug-non-zts-20090626/memcached.so
Make sure it is running as a daemon (-d):
/usr/local/bin/memcached -d
Restart apache:
sudo apachectl restart

You'll need to install libmemcached with homebrew, not just memcached. Do this:
brew install libmemcached
Then try recompiling your memcache PHP module. Should be good to go

First, install memcached library with:
sudo pecl install memcached
Then, add this line to /etc/php.ini:
extension = memcached.so
That's it.

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/memcached.so'
That's the information PHP is giving you, stick to it.
It's either:
The file you have specified does not exists. Check your file-system.
The file you've specified can not be read by PHP, check the rights of the file.
The file you've specified is incompatible with your PHP binary. Check if you have compiled the right sources and compilation went well.

In Mac OS X El Capitan you can use
brew install homebrew/php/php55-memcached

You can install the memcache.so module the following way:
brew install memcached-php
(Note the above is currently broken if you don't have the right Xcode version)
Then go to your php.ini file and add the following (Replace VERSION with the correct value):
extension="/usr/local/Cellar/memcached-php/VERSION/memcached.so"
Then restart apache:
sudo apachectl restart
If you can't figure out which php.ini file is being used, try calling the phpinfo() command. It will tell you exactly which php.ini file it's using.

Related

Install postgresql with apache on Mac OSX

I am trying to make postgresql work with apache on my Mac OSX. I use homebrew to manage all my dev features, so I replace the default php version provided by apache and download a homebrew version, this part works really fine. The problem is when I want to install the postgresql extension..
I have done this :
brew install postgresql
brew install php55 --with-postgresql
brew install php55-pdo-pgsql
And then edit the /etc/apache2/httpd.conf file to replace LoadModule php5_module libexec/apache2/libphp5.so by LoadModule php5_module /usr/local/opt/php55/libexec/apache2/libphp5.so.
Then when I exec the phpinfo() command, I can't see the postgresql extension installed in the PDO section. I only have this :
If anyone can help ;) Thank you all !
Possible solution :
- First install all packets like this : brew install postgresql php55 php55-pdo-pgsql
- Then brew reinstall php55 --with-postgresql
And it works.. I did this before (maybe not the same order) and it didn't work, I do not know why it works now !
Solution
When you watch the phpinfo() result, you should see something something like Loaded Configuration File and *Scan this dir for additional .ini files *. The thing is there is a global php.ini file and a .ini file per extension you install.
The value for *Scan this dir for additional .ini files * is where the .ini file for the extension must be located. So just need to create a ext-pdo_pgsql.ini and load the extension with extension="path to your/pdo_pgsql.so" (mine was /usr/local/opt/php55-pdo-pgsql/pdo_pgsql.so).
And for the installation just need brew install php55 php55-pdo-pgsql postgresql
Run php -m | grep pgsql to know if pgsql exists
Follow the example in this answer. Jump to note if you have a problem with the instruction there corresponding to number 4 here.
Enter ./configure --with-pdo-pgsql="path to postgres" and return. Mine is at "/usr/local/bin".
Enter make && sudo make install and return.
Add the extension to php.ini with sudo echo "extension=pdo_pgsql.so" >> path to php.ini. Find the path using php -i | grep php.ini
That should install pdo driver for postgres
Note
It is possible that sudo make install doesn't work. It might be due to an OSX feature known as csrutil. Reboot your machine and hold down cmd + R. From the recovery inteface run csrutil disable from terminal.
Reboot again and perform the make install. Repeat same process as in the paragraph above to enable csrutil by running csrutil enable at the recovery interface's terminal.

How to install and activate PDO for PHP 7? [duplicate]

I am trying to setup webserver with PHP 7 RC3 + Nginx on Ubuntu 14.04 (for test purposes).
I installed Ubuntu in Vagrant using ubuntu/trusty64 and PHP 7 RC 3 from Ondřej Surý (https://launchpad.net/~ondrej/+archive/ubuntu/php-7.0).
I can not find the way to install MySQL PDO (PHP sees PDO class but not anything related to MySQL, like PDO::MYSQL_ATTR_DIRECT_QUERY etc.)
Looks like there is no lib php7.0-mysql (by analogy with standard php5-mysqlnd and php7.0-fpm etc. from Ondřej)
Section PDO in phpinfo():
PDO support enabled
PDO drivers no value
How can I get it?
For thoses running Linux with apache2 you need to install php-mysql
apt-get install php-mysql
or if you are running ubuntu 16.04 or higher just running the following command will be enought, no need to edit your php.ini file
apt-get install php7.2-mysql
If you are running ubuntu 15.10 or below:
Edit your php.ini file, it's located at /etc/php/[version]/apache2/php.ini and search for pdo_mysql
you might found something like this
;extension=pdo_mysql.so
Change it to this
extension=pdo_mysql.so
Save the file and restart apache
service apache2 restart
Check that it's available in your phpinfo()
First install php-mysql
sudo apt-get install php7.0-mysql
//change the version number based on the php version
then enable the module
sudo phpenmod pdo_mysql
and restart apache
sudo service apache2 restart
On ubuntu 18.04 following works for me
type this in your terminal
For php7.3
sudo apt-get install php7.3-gd php7.3-mysql
For php7.0
sudo apt-get install php7.0-gd php7.0-mysql
For php5
sudo apt-get install php5-gd php5-mysql
First, check if your php.ini has the extension enabled "php_pdo_mysql" and "php_mysqli" and the path of "extension_dir" is correct. If you need one of above configuration, then, you must restart the php-fpm to apply the changes.
In my case (where i am using the Windows OS in the company, i really prefer OSX or Linux), i solved the problem putting this values in the php.ini:
; ...
extension_dir = "ext"
; ...
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
; ...
I hope this helps.
Since eggyal didn't provided his comment as answer after he gave right advice in a comment - i am posting it here: In my case I had to install module php-mysql. See comments under the question for details.
If you are on windows, and your php folder is not in your PATH, you have set the absolute directory in your php.ini
for example:
extension_dir = "C:/php7/ext"
and uncomment
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
Restart apache2.4 and it should work.
I hope it helps.
download the source code of php 7 and extract it.
open your terminal
swim to the ext/mysqli directory
use commands:
phpize
./configure
make
make install (as root)
enable extension=mysqli.so in your php.ini file
done!
This worked for me
I had, pretty much, the same problem. I was able to see that PDO was enabled but I had no available drivers (using PHP 7-RC4). I managed to resolve the issue by adding the php_pdo_mysql extension to those which were enabled.
Hope this helps!
I resolved my problem on ubunto 20.4 by reinstalling php-mysql.
Remove php-mysql:
sudo apt purge php7.2-mysql
Then install php-mysql:
sudo apt install php7.2-mysql
It will add new configurations in php.ini
Had the same issue, resolved by actually enabling the extension in the php.ini with the right file name. It was listed as php_pdo_mysql.so but the module name in /lib/php/modules was called just pdo_mysql.so
So just remove the "php_" prefix from the php.ini file and then restart the httpd service and it worked like a charm.
Please note that I'm using Arch and thus path names and services may be different depending on your distrubution.
I'll start with the answer then context NOTE this fix was logged above, I'm just re-stating it for anyone googling.
Download the source code of php 7 and extract it.
open your terminal
swim to the ext/pdo_mysql directory
use commands:
phpize
./configure
make
make install (as root)
enable extension=mysqli.so in your php.ini file
This is logged as an answer from here (please upvote it if it helped you too): https://stackoverflow.com/a/39277373/3912517
Context:
I'm trying to add LimeSurvey to the standard WordPress Docker. The single point holding me back is "PHP PDO driver library" which is "None found"
php -i | grep PDO
PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_odbc' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc.so (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning: Module 'mysqli' already loaded in Unknown on line 0
PDO
PDO support => enabled
PDO drivers => sqlite
PDO Driver for SQLite 3.x => enabled
Ubuntu 16 (Ubuntu 7.3.0)
apt-get install php7.0-mysql
Result:
Package 'php7.0-mysql' has no installation candidate
Get instructions saying all I have to do is run this:
add-apt-repository -y ppa:ondrej/apache2
But then I get this:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 223: ordinal not in range(128)
So I try and force some type of UTF:
LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/apache2
and I get this:
no valid OpenPGP data found.
Follow some other instructions to run this:
apt-get update
and I get this:
Err:14 http://ppa.launchpad.net/ondrej/apache2/ubuntu cosmic/main amd64 Packages
404 Not Found
Err:15 http://ppa.launchpad.net/ondrej/php/ubuntu cosmic/main amd64 Packages
404 Not Found
and - I think because of that - I then get:
The repository 'http://ppa.launchpad.net/ondrej/apache2/ubuntu cosmic Release' does not have a Release file.
By this stage, I'm still getting this on apt-get update:
Package 'php7.0-mysql' has no installation candidate.
I start trying to add in php libraries, got Unicode issues, tried to get around that and.... you get the idea... whack-a-mole. I gave up and looked to see if I could compile it and I found the answer I started with.
You might be wondering why I wrote so much? So that anyone googling can find this solution (including me!).
['class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost:3306;dbname=testdb',
'username' => 'user',
'password' => 'password',
'charset' => 'utf8',]
It's simple:
Just provide the port number along with the host name
and set default sock path to your mysql.sock file path in php.ini which the server is running on.
Just as an update for those working with installing Linux programs, please note, that things such as 'php7.0-common' are now simply known as 'php-common'.

call to undefined function mb_strimwidth

Months ago I made a short code that uses mb_strimwidth() to exactly fit some text into a table cell, putting dots at the end of a truncated string.
Now, after some times, I tried to execute that same code and it went out with this error:
Fatal error: Call to undefined function mb_strimwidth() in ...
I tried to find the mbstring.php file, and when I found the mb_strimwidth() function, I discovered that it is not implemented anymore. How is that possible?
But my main question is: how can I get the same result as mb_strimwidth()?
I thought to rewrite the function using a loop and mb_strwidth(), but ALL the functions in that mbstring.php file are empty.
All mb_* functions are provided by a PHP extension called Multibyte String, internal name mbstring
You probably don't have the extension active or installed. On most Linux distros you can install the package php-mbstring to install and activate this extension.
Apache needs to be restarted afterwards if you are using mod_php
Just got this issue, if you are using linux just install the package php-mbstringand restart Apache.
sudo apt-get install php-mbstring
sudo service apache2 restart
If you are using specific PHP version, you may need to run the following:
sudo apt-get install php7.x-mbstring
sudo service apache2 restart
Replace 7.x by the exact PHP version.
u need to install php-mbstring package try.
check php version
php -v
then check mbstring already install and enable
php -i | grep mbstring
if not installed run this command
sudo apt-get install php-mbstring
if you are php other version example : 7.1, 7.2, 7.0 based on
run command like this :
sudo apt-get install php7.1-mbstring
if you are using nginx server for run laravel .. then check nginx configration file which version u have loaded in conf file..
go to cd /etc/nginx/sites-available and open your configuration file..
if you are loading php7.2 version in nginx conf file..
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
then u need to install 7.2 mbstring package..
sudo apt-get install php7.2-mbstring
and restart apache2 server
sudo service apache2 restart
if you already installed mbstring then you have to call this extension on php.ini file.
First, detect where is your php-fpm.ini file or php.ini.
run command
php -i | grep php.ini
it returns you path of php.ini file.
for example
/etc/php.ini
then open file with VIM or another editor
vim /etc/php.ini
and then add mbstring extension to php.ini file
extension=mbstring.so;
finally, restart php-fpm
systemctl restart php-fpm

can't find mcrypt => Call to undefined function Laravel\mcrypt_create_iv()

Trying to set up Laravel and keep getting hit with this error. I installed mcrypt through brew and it is located in /usr/local/Cellar. Any thoughts? .. It's not showing up in terminal command php -m either, if that matters. I'm running Mountaion Lion with macs native web server.
Ubuntu or any Debian based Linux users can install the required package with apt-get:
sudo apt-get install php5-mcrypt
Remember to restart the web server afterwards:
sudo service apache2 restart
If it still doesn't work, try to link the configuration file to the appropriate configuration folder for the web server. Thanks to dave1010 for this hint in the comments.
sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/apache2/conf.d/ # for Apache
sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/cli/conf.d/ # for CLI
And again, restart the web server:
sudo service apache2 restart
Perhaps, if not working yet, you need also the line showed by #RahulPrasad, with php5enmod mcrypt.
You need to enable it in your php.ini file as well and probably restart Apache.
In php.ini you will find ;mcrypt.so and remove the ; from it.
Or, if it's not in there, just add mcrypt.so somewhere.
Also the salt option has been deprecated as of PHP 7.0.0. It is now preferred to simply use the salt that is generated by default.
Try sudo php5enmod mcrypt && sudo service apache2 restart
You've installed mcrypt when you actually wanted the php56-mcrypt php module.
You stated in your question that you can see mcrypt installed in /usr/local/Cellar and that you're using OSX. So, the easiest way to install the mcrypt PHP module on OSX using Homebrew is:
// assuming you have php56
brew install php56-mcrypt
If homebrew can't find the correct package you may need to tap the PHP repositories found on GitHub:
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
Now when you issue the command brew search mcrypt, you should see something like:
libtomcrypt mcrypt php53-mcrypt php54-mcrypt php55-mcrypt php56-mcrypt
Several other posters have mentioned the need to edit your php.ini file. This will be unnecessary as homebrew will take care of activating the module for you. It places the configuration file at /usr/local/etc/php/5.6/conf.d/ext-mcrypt.ini
You don't have the mcrypt PHP extension installed.
For a Mac, I followed these instructions:
mcrypt on Mac 10.7 or 10.8.
They look like a lot, but it's not, it's very easy to follow in it works!
You may have installed mycrypt but not have the php_mcrypt module installed / enabled.
Just a note for people who have recently upgraded to PHP 7 - The MCRYPT library has been deprecated. If you upgraded to PHP 7 and are now seeing this error, that is why. You should switch to an alternative library, some alternatives are mentioned in this thread.
Go to the CLI folder in your php instalation, and find php.ini in there and enable mcrypt. Terminal sometimes uses another php.ini, which is usually in the CLI folder.
I installed php and mcrypt with Homebrew, but I still experienced this error after doing brew update a few times. I think my setup has just gotten a bit borked over time.
It turns out my php was being configured from /private/etc/php.ini, not /usr/local/etc/php/5.4/php.ini as Homebrew recommends. Mcrypt is not even being included from /usr/local/etc/php/5.4/ext-mcrypt.ini which doesn't make a lot of sense considering php -i produces this for me:
Configuration File (php.ini) Path => /usr/local/etc/php/5.4
Loaded Configuration File => /usr/local/etc/php/5.4/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php/5.4/conf.d
Additional .ini files parsed => /usr/local/etc/php/5.4/conf.d/ext-mcrypt.ini
My solution:
Edit /private/etc/php.ini as a superuser
Add extension="/usr/local/Cellar/php54-mcrypt/5.4.28/mcrypt.so" and save
Restart Apache with sudo apachectl restart
This is what finally worked for me:
brew reinstall --with-homebrew-curl --with-httpd php56
brew reinstall --build-from-source php56-mcrypt
I also had to do sudo chmod 777 /usr/local/etc/php/5.6/conf.d because I got errors when the second brew reinstall tried to add the ext-mcrypt.ini to that directory.

What's needed for PHP's mcrypt_decrypt()?

I have a script that uses mcrypt_decrypt() function, but I get the following error
Fatal error: Call to undefined function mcrypt_decrypt()
What modules/libraries do I need to include to use this function? Or is there another reason I'm getting the error?
Thanks
sudo apt-get install php5-mcrypt
works on ubuntu.
Please see:
Mcrypt Requirements
Mcrypt Installation
You need to compile your PHP with --with-mcrypt[=DIR] and have libmcrypt Version 2.5.6 or greater on your machine.
Configure php5-mcrypt with php5-fpm (Ubuntu 14.04)
I’m going to assume you already have nginx and php-fpm installed and running.
php5-mcrypt should be installed already (it comes bundled with php5-fpm). Just for safety,
apt-get install php5-mcrypt
Create symlink to mods-avaliable,
ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/mcrypt.ini
Enable it.
php5enmod mcrypt
Restart php-fpm,
service php5-fpm restart
Restart nginx,
service nginx restart
Done!
From the manual:
You need to compile PHP with the
--with-mcrypt[=DIR] parameter to enable this extension. DIR is the
mcrypt install directory. Make sure
you compile libmcrypt with the option
--disable-posix-threads.
Generally if PHP says a function is undefined, it means you need to compile in some library.
I above doesn't work, you can try this:
create mcrypt.ini file in /etc/php5/conf.d with content
extension=mcrypt.so
I upgraded PHP to 5.4 via http://php-osx.liip.ch/ and it worked.
for php 5.3.X
depends on availability of yum mcrypt package , you could use yum packeages
like this :
yum install php53-mcrypt
and restart httpd
And be carefull about the folder in the phpinfo page : "Scan this dir for additional .ini files" and the next : "Additional .ini files parsed ".
After upgrading to php 5.4 running (Works)
sudo php5enmod mcrypt
sudo service apache2 restart

Categories