Problem:
If the PHP configuration has magic_quotes_gpc set to On, then drush commands fail with the following error:

PHP's 'magic_quotes_gpc' and 'magic_quotes_runtime' settings are not supported and must be disabled.Drush command terminated abnormally due to an unrecoverable error.   [error]

Some pre-built environments (notably MAMP) default to magic_quotes_gpc = On. To make things even more difficult, some MAMP environments seem to ignore -d and ini_set for magic_quotes_gpc, and only seem to respond to changes in php.ini.

Suggested Workaround(s):

  • Explicitly set all magic_quotes_* settings to Off in php.ini
  • Explicitly set all magic_quotes_* settings to Off in drush.ini
  • Explicitly set all magic_quotes_* settings to 0 in php.ini
  • Explicitly set all magic_quotes_* settings to 0 in drush.ini

Suggested Improvement:

Find some way for drush to consistently force magic_quotes_gpc = Off. If we cannot force it off on some platforms, identify what it is about those platforms and update the documentation to match.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

boran’s picture

Interesting, I also got hit by this at dc munich during the sprint :-)
Probably due something to D8. Don't get that warning for d7.

I disabled gpc options in /etc/php.ini, and /Applications/MAMP/bin/php/php5.3.6/conf/php.ini

see #532818 which explains to use php --ini to find which ini file is being used.

greg.1.anderson’s picture

Status: Active » Needs review
FileSize
763 bytes

I believe that the message shown in #0 is the result of Drush showing all of the watchdog messages (did not explicitly try to reproduce this, though). It would be hard for Drush to parse the Drupal error message for the purpose of enhancing them, but one thing that we could do is deny magic_quotes_gpc and magic_quotes_runtime in Drush, before we try to bootstrap Drupal. With the attached patch, Drush will then print out the following message:

The following restricted PHP modes have non-empty values: 
magic_quotes_runtime. This configuration is incompatible with drush. 
Please check your configuration settings in /etc/php5/cli/php.ini or
in your drush.ini file; see examples/example.drush.ini for details.

This patch does this invariantly, not just for Drupal 8. I presume that this is okay (i.e., there is no reason why someone would need to run with these settings enabled).

blackra’s picture

This patch appears to solve the problem by allowing drush to get far enough to print out its php.ini path.

Since I'm new to Drupal and this was my first experience of applying a patch, I think somebody else should look at it too...

blackra’s picture

BTW, that should have explicitly said I tested it and it looks good to me.

Cameron Tod’s picture

Version: 7.x-5.7 » 7.x-5.8
Status: Needs review » Reviewed & tested by the community

Tested locally, and still applies cleanly to the 8.x-6.x and 7.x-5.x branches, and allows for a very useful error message.

greg.1.anderson’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 8.x-6.x and 7.x-5.x. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

moshe weitzman’s picture

Assigned: Unassigned » greg.1.anderson
Status: Closed (fixed) » Active

Perhaps we could do better here? I'm thinking that the bash script `drush` could always add magic_quotes_gpc=Off when it executes drush.php

moshe weitzman’s picture

I'm come across this message twice in a week so thats why its on my mind.

greg.1.anderson’s picture

This setting is deprecated in php 5.3, and removed in 5.4. Do we really want to explicitly turn it off on every call? Since magic_quotes_gpc=on seems like such an imprudent setting, I'm surprised that it defaults to on so commonly. All the same, I am reluctant to hardcode this in the drush script unless it is causing serious problems ... well, I'm not sure unless what. Unless everyone feels strongly that we should, I guess.

http://php.net/manual/en/security.magicquotes.php

moshe weitzman’s picture

I don't see why not. we are currently forcing users to do exactly that with a drush.ini file. They get lost with that process. There is no performance impact so why not? It isn't like we are affecting other php requests.

greg.1.anderson’s picture

Status: Active » Needs review
FileSize
1.61 KB

I considered removing all of the mode testing in _drush_environment_check_php_ini(), and adding a define to disable each of these options on the commandline, just as is done with magic_quotes, but somehow felt that wasn't quite appropriate. There is no protection in drush.bat, and some folks may still be using the deprecated technique alias drush=php ... drush.php. So I kept it simple.

Sam Moore’s picture

Version: 7.x-5.8 » 8.x-6.x-dev

Hope this isn't too tangential, but I'm putting it here in case it might help someone.
In getting drush for D8 going under MAMP, I ran into the magic_quotes warnings, and found that setting all the magic_quotes values to "Off" didn't help.

I had to put the following in a drush.ini to make drush happy:
magic_quotes_gpc = 0
magic_quotes_runtime = 0
magic_quotes_sybase = 0

If this belongs somewhere else, please kindly let me know.

Cheers

greg.1.anderson’s picture

Status: Needs review » Fixed

Committed to 8.x-6.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

greg.1.anderson’s picture

Status: Closed (fixed) » Patch (to be ported)

I guess this should have gone into 7.x-5.x. See: #1977626: magic_quotes_gpc and magic_quotes_runtime non-empty values

greg.1.anderson’s picture

Status: Patch (to be ported) » Needs review
FileSize
1.1 KB

Always disable magic_quotes_gpc et. al. when launching Drush

greg.1.anderson’s picture

Version: 8.x-6.x-dev » 7.x-5.x-dev

#17 is a little simpler than what is currently in 8.x-6.x; if it works for folks on the 7.x-5.x branch, we could commit it both places.

I will commit to both branches in a couple of days if there are no comments.

jonhattan’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

I've also suffered this warning just now. Patch in #17 solves it.

Updating issue priority since it is a regresion in 5.9.

greg.1.anderson’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x-5.x, and also made the same simplification in 8.x-6.x.

greg.1.anderson’s picture

Note: if you feel inclined to re-open this issue because it breaks unit tests, please note that the issue in question actually dates back to #1332818: Shell aliases starting with a ! don't pass along options and arguments, which I have re-opened with a patch.

Anonymous’s picture

#13 worked for me. MAMP PRO 2.1.2, PHP 4.3.20, Drush 5.9, Drupal 7.22

electrokate’s picture

#13 worked for me too! Using MAMP PRO, Drush 5.9. Thank you so much! You guys rock. :)))

greg.1.anderson’s picture

In theory, #13 is not necessary under the latest Drush 7.x-5.x-dev (but -is- helpful for Drush 5.9). Re-open if this is not the case, though.

xmacinfo’s picture

@greg.1.anderson: Most users, like me, will use pear upgrade to a release version of Drush. So it might be easier to apply the patch than to install the dev version of Drush.

Jooblay.net’s picture

We upgraded from drush 5.6 to 5.9 on our LAMP stack and received this error. After looking at our php.ini file the Magic quotes were Off but ; commented out. By turning turning them off and removing the ; all is well.

fmilland’s picture

Got the same error

php.ini file at /Applications/MAMP/bin/php/php5.2.17/conf/php.ini was like this

; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = On

; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
magic_quotes_runtime = Off

; Use Sybase-style magic quotes (escape ' with '' instead of \').
magic_quotes_sybase = Off

Changed it to

; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off

; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
magic_quotes_runtime = Off

; Use Sybase-style magic quotes (escape ' with '' instead of \').
magic_quotes_sybase = Off

And error went away,

Any comments?

Jooblay.net’s picture

Yes #27 that did the trick for us.

conniemh’s picture

My php.ini had all the magic_quotes settings set to "Off" but I was still getting that error message when running drush. There is another related thread for drush errors for versions used in D8, but I went ahead and took a chance and created a drush.ini file as instructed here. Worked like a charm.

This worked with a PHP version 5.3.19 and Drush version 5.9 (for D7)

Hope this helps others,
Connie Harich

pasive’s picture

In my /Applications/MAMP/bin/php/php5.3.6/conf/php.ini

I had magic_quotes_sybase = Off commented in, commented out the resolved the problem and disappearance of error messages.

John Bickar’s picture

Ugh, annoying MAMP.

In /Applications/MAMP/bin/php/php5.3.20/conf/php.ini I had:

; Magic quotes
;

I tried setting the following in drush.ini:

magic_quotes_gpc = 0
magic_quotes_runtime = 0
magic_quotes_sybase = 0

And still got the error.

The fix was to explicitly set magic_quotes_gpc to Off in php.ini:

; Magic quotes
magic_quotes_gpc = Off

(This is a MAMP problem, not a drush problem, IMO. Just documenting here in case someone else encounters the same issue.)

greg.1.anderson’s picture

Drush 8.x-6.x-dev, and Drush 7.x-5.x-dev both automatically set magic_quotes_gpc=0, not Off. It would be helpful if folks who find that 0 does not work for them, but that Off does could also try the latest dev version of Drush, and see if it solves their problems. If Drush needs to switch to Off instead of 0, we should figure that out and fix it now. I understand the point in #25, but if no one has time to test dev, then the problem will persist 7.x-5.10.

John Bickar’s picture

Sorry, forgot to add that: my comment in #31 was against 8.x-6.x-dev.

greg.1.anderson’s picture

Status: Fixed » Needs work

Great; that is helpful. Let's set status.

greg.1.anderson’s picture

Version: 7.x-5.x-dev » 8.x-6.x-dev
Status: Needs work » Needs review
FileSize
838 bytes

Per #31 and http://www.php.net/manual/en/security.magicquotes.disabling.php, use "Off" instead of "0" for the various magic_quote settings.

John Bickar’s picture

Status: Needs review » Needs work

Hesitant to set this to CNW because I still think it's a MAMP issue, and I have a workaround, but the patch does not solve my issue (with MAMP).

With patch applied, nothing in my drush.ini, and with the following in my php.ini for MAMP:

; Magic quotes
; magic_quotes_gpc = Off

I get:

machine: /Applications/MAMP/htdocs/d8$ dr6 st
The following restricted PHP modes have non-empty values:            [error]
magic_quotes_gpc. This configuration is incompatible with drush. 
Please check your configuration settings in
/Applications/MAMP/bin/php/php5.3.20/conf/php.ini or in your
drush.ini file; see examples/example.drush.ini for details.
PHP's 'magic_quotes_gpc' and 'magic_quotes_runtime' settings are not supported and must be disabled.Drush command terminated abnormally due to an unrecoverable error. 

I'm running drush 6 through PHP 5.3.20 on MAMP:

machine: ~$ alias | grep dr6
alias dr6='/Applications/MAMP/bin/php/php5.3.20/bin/php ~/dr6/drush.php'
machine: ~$ /Applications/MAMP/bin/php/php5.3.20/bin/php -i | grep magic
magic_quotes_gpc => On => On
magic_quotes_runtime => Off => Off
magic_quotes_sybase => Off => Off

When I change my php.ini for MAMP to:

; Magic quotes
magic_quotes_gpc = Off

I get:

machine: /Applications/MAMP/htdocs/d8$ dr6 st
 Drupal version                 :  8.0-dev                                                                        
 Site URI                       :  http://default                                                                 
 Database driver                :  mysql                                                                          
 Database username              :  d8                                                                             
 Database name                  :  d8                                                                             
 Database                       :  Connected                                                                      
 Drupal bootstrap               :  Successful 

(etc.)

And then php -i shows magic_quotes_gpc = Off:

machine: ~$ /Applications/MAMP/bin/php/php5.3.20/bin/php -i | grep magic
magic_quotes_gpc => Off => Off
magic_quotes_runtime => Off => Off
magic_quotes_sybase => Off => Off
greg.1.anderson’s picture

It's possible that this is a 'can not fix' for MAMP, if the -d values to php are somehow ignored. Let's leave this at 'needs work' for a while, though, and see if there are any MAMP users who can come up with a better solution.

If we can't fix is in the drush script, we can at least update the docs in the README about MAMP.

xmacinfo’s picture

Using the trick in #31 made Mamp work with Drush 7.x-5.9.

I did not try to force it using the ini_set('magic_quotes_gpc', 'off'); in the settings.php file, though. That might work.

greg.1.anderson’s picture

Yes, this is fixable by changing your configuration settings; however, this issue is about whether we can make it possible to run without configuring settings by turning off magic_quotes_gpc & c. in the drush script, as php is called.

John Bickar’s picture

I spent some time on the Googles this afternoon on this one, and the best I could come up with was this PHP bug, which says:

But when PHP has no configuration file (which happens to be the case for CLI in some bundles/distros; e.g., MAMP), then the evil feature is unexpectedly enabled.

Unsurprisingly, my Google-fu fails to return meaningful results for "-d", and the above doesn't really answer Greg's question in #37 as to whether MAMP ignores the "-d" flag (which it appears to be doing, given the patch in #35).

So far, I see that we have a workaround (w00t!) but not closure.

The issue summary could use some refreshing (I'll try to hit this in tomorrow's sprint), and the patch in #35 could use testing on platforms other than MAMP (if those platforms are experiencing the same issue).

greg.1.anderson’s picture

If ini_set('magic_quotes_gpc', 'off'); works in settings.php, then Drush could call ini_set on these three properties first thing. ini_set does not work for some values after php has been launched, but it seems like an easy test someone could do.

greg.1.anderson’s picture

Status: Needs work » Needs review
FileSize
2.09 KB

Let's try to fix this with ini_set. If these values can be changed by ini_set, this is probably the most stable solution.

greg.1.anderson’s picture

Issue tags: +Release blocker

Since so many people are posting here, we should probably make this a Release Blocker for Drush 6.

John Bickar’s picture

Status: Needs review » Needs work

Sorry :(

Tested on MAMP with patch in #42, same results as in #36.

greg.1.anderson’s picture

That's too bad. Maybe a documentation patch is the best we can do here for MAMP.

Cameron Tod’s picture

It seems ok here, without the patch:

$ php -i | grep magic_quotes
magic_quotes_gpc => On => On

$ php -r 'echo ini_get("magic_quotes_gpc");'
1

$ which php
/Applications/MAMP/bin/php/php5.3.14/bin/php


diff --git a/drush b/drush
-exec "$php" $php_options "$SCRIPT_PATH" --php="$php" --php-options="$php_options" "$@"
+echo "$php" $php_options "$SCRIPT_PATH" --php="$php" --php-options="$php_options" "$@"

 $ /tmp/drush/drush
/Applications/MAMP/bin/php/php5.3.14/bin/php -d magic_quotes_gpc=0 -d magic_quotes_runtime=0 -d magic_quotes_sybase=0 /private/tmp/drush/drush.php --php=/Applications/MAMP/bin/php/php5.3.14/bin/php --php-options= -d magic_quotes_gpc=0 -d magic_quotes_runtime=0 -d magic_quotes_sybase=0

/tmp/drush/drush ev "echo ini_get('magic_quotes_gpc');"
0

This is against a45a79b.

greg.1.anderson’s picture

Status: Needs work » Needs review
FileSize
3.21 KB

Here is our best-effort fix, plus a documentation patch to catch folks who still have troulbe with magic_* setting despite our attempts to disable them.

moshe weitzman’s picture

Status: Needs review » Fixed

Committed to 5.x and 6.x. Thanks.

Jooblay.net’s picture

Great work:) means more then you I can ever express... @greg.1.anderson @moshe weitzman what is the best method to donate $cash to the drush project?

greg.1.anderson’s picture

I would think that the best thing to do would be to make a donation to the Drupal Association. If enough people donated, then perhaps they could sponsor a Drush sprint in the future. If just a few people are donating, though, perhaps it is best to not earmark it, and just thank the whole community through the DA. Kind words go a long way too, so thanks!

geerlingguy’s picture

I upgraded to 7.x-5.9 and then to 8.x-6.x (latest checkout from git), and I still had too add the following before the errors went away; I was using MAMP, and couldn't find any php.ini that was enabling any of the values (all were Off. The error didn't come up until I upgraded MAMP, and with it, 5.3.14 to 5.3.20. Weird.

; Added these to squelch annoying errors.
magic_quotes_gpc = 0
magic_quotes_runtime = 0
magic_quotes_sybase = 0

(I added the above code block to the bottom of 'drush.ini', which I copied from 'example.drush.ini' in the drush installation folder to my username/.drush folder.)

greg.1.anderson’s picture

Component: Core Commands » Documentation
Status: Fixed » Active

Seems folks are using drush.ini as a basis for getting Drush to work on MAMP.

See: http://workingmatt.blogspot.co.uk/2013/05/using-drush-to-sync-live-and-d...

We should add magic_ settings to this file and make it all ready for drop-in use.

Jooblay.net’s picture

:) absolutely agree... will fire the rockets and motivate more donations:)

We are LAMP strapped so I can not speak to the MAMP but it seems magic_quotes are packed uncommented and Off. Which is why we ran across this issue off a modified php.ini file.

Thanks to everyone for all their hard work... it truly inspires another conciousness...

greg.1.anderson’s picture

Status: Active » Needs review
FileSize
920 bytes

Here is some better documentation for drush.ini.

ShaunDychko’s picture

Status: Needs review » Active

Well, I tried most of the above without success since I think there is an extra quirkiness with the PRO version of MAMP. I'm on Mac OSX Lion 10.8.3, MAMP 2.1.4 PRO, Drush 5.9. I think the reason I needed a different solution is because I was making changes to php.ini through the File -> Edit Template -> PHP -> PHP 5.3.20 php.ini menu provided by MAMP PRO. This php.ini file (which I suppose is dynamically generated by MAMP after making changes to the 'template'), according to phpinfo() resides in /Library/Application Support/appsolute/MAMP PRO/conf/php.ini, but drush wasn't picking this up. Drush was instead using, quite sensibly since I have /Applications/MAMP/bin/php/php5.3.20/bin in my PATH variable, the php.ini file located at /Applications/MAMP/bin/php/php5.3.20/conf/php.ini. This file, however, doesn't contain any of the changes made through the MAMP PRO edit template menu! Furthermore, it doesn't contain anything about magic_quotes_gpc (neither On nor Off). I wonder if this is why placing a drush.ini file in ~/.drush/drush.ini didn't work, since it can only override variables that have already been specified, but not introduce new ones? Anyhow, here's the fix for my setup:

The fix

cd /Applications/MAMP/bin/php/php5.3.20/conf
In case this file is useful for something, move instead of delete
sudo mv php.ini php.ini-original
Create symlink to the php.ini file that's actually being used
sudo ln -s /Library/Application\ Support/appsolute/MAMP\ PRO/conf/php.ini php.ini

As explained above, the following lines should should exist via the MAMP PRO edit template:

; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off

; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
magic_quotes_runtime = Off

; Use Sybase-style magic quotes (escape ' with '' instead of \').
magic_quotes_sybase = Off

All is well! A drush.ini file is not being used in this approach, and here's the output from drush status

 PHP configuration     :  /Library/Application Support/appsolute/MAMP 
                          PRO/conf/php.ini                            
 Drush version         :  5.9                                         
...
greg.1.anderson’s picture

Status: Active » Needs review

Are there any actionable changes to #54 in #55, or elsewhere? If not, #54 is still 'needs review'.

ShaunDychko’s picture

How about the attached patch which documents #55? MAMP PRO users will still be stuck after applying #54.

Notes:

I tried to get export PHP_INI='/Library/Application\ Support/appsolute/MAMP\ PRO/conf/php.ini' to work in ~/.bashrc since that seems more elegant, but couldn't make this work due to the spaces in the path. The command drush status kept returning something like Could not open input file: Support/appsolute/MAMP\ depending on which technique I tried using to escape the spaces.

For testing #54, I added magic_quote_gpc = On through the php.ini MAMP PRO template editor, while having the attached drush.ini file in ~/.drush, and drush status reported the following:

PHP Deprecated:  Directive 'magic_quotes_gpc' is deprecated in PHP 5.3 and greater in Unknown on line 0
The following restricted PHP modes have non-empty values:            [error]
magic_quotes_gpc. This configuration is incompatible with drush. 
Please check your configuration settings in /Library/Application
Support/appsolute/MAMP PRO/conf/php.ini or in your drush.ini file;
see examples/example.drush.ini for details.
 PHP configuration     :  /Library/Application Support/appsolute/MAMP      
                          PRO/conf/php.ini /Users/sdychko/.drush/drush.ini 
 Drush version         :  5.9
...

which means that drush.ini is not overriding the magic_quotes_gpc variable as expected.

greg.1.anderson’s picture

Status: Needs review » Needs work

Per #36 and #37, -d does not seem to work for setting php.ini values on MAMP. If we are going to document MAMP changes in drush.ini, then we should say that drush.ini does not (always?) work on MAMP. I say "always?" because I believe some folks do use drush.ini on MAMP, but I am not sure.

Anyone have definitive answers regarding php.ini settings (esp. w/ -d) and MAMP?

xmacinfo’s picture

@Shaun Dychko: Eventhough MAMP Pro uses it's own php.ini file, the Drush status command always mentionned which php.ini it is using:

PHP configuration     :  /Applications/MAMP/bin/php/php5.3.20/conf/php.ini 
 Drush version         :  5.9

You just need to apply the fix documented earlier in 31 in that PHP file.

It does not matter that Drush uses one php.ini file and that Drupal, through MAMP Pro, uses another PHP configuration.

ShaunDychko’s picture

@xmacinfo Thanks, and you're totally correct. I suppose the issue comes down to personal preference, and maybe we should just go ahead with #54, but there is still a niggling issue here for MAMP PRO users: /Applications/MAMP/bin/php/php5.3.20/conf/php.ini doesn't contain any PHP configuration options selected in the MAMP PRO UI or the Edit Template menu. The issue here is definitely with MAMP PRO, and not with Drush. The fix I mentioned in #55 allows making PHP changes in the MAMP PRO UI and the 'File -> Edit Template -> PHP -> PHP 5.3.20 php.ini' menu, for what it's worth. Maybe we should just say MAMP PRO tries too hard to be 'convenient' in this particular case, and let the comments in this issue queue suffice for anyone having similar difficulties?

ShaunDychko’s picture

If MAMP PRO users could specify a custom php.ini file to Drush, that would go a long way toward solving this, and would take only one line of documentation to explain it. The problem is that the PHP_INI path in ~/.bashrc can't contain spaces, and I filed a separate issue for this here: https://drupal.org/node/2009840

JadH’s picture

Patch #54 worked for me.

// Update
// -------------------

Patch #54 did not work.
The same error is showing again.

I am using XAMPP on my macbook Pro and I have Mamp Pro installed.

On the other hand, I am trying to figure out which php.ini the system is using to know if it is from Xampp or Mamp, but IT IS NOT showing in Terminal.

ShaunDychko’s picture

@JadH, are you running MAMP PRO? If so, which version?

C13L0’s picture

I apologize in advance if this is in the wrong issue. I am working on a shared GoDaddy server and am not able to edit the php.ini so a patch is my only option (I think). Drush works fine but the error is super annoying...would love to get rid of it. The drush.ini file is empty. Is there something that should be in there?

The following restricted PHP modes have non-empty values: [error]
magic_quotes_gpc. This configuration is incompatible with drush.
Please check your configuration settings in /web/conf/php5.ini or in
your drush.ini file; see examples/example.drush.ini for details.
PHP configuration : /web/conf/php5.ini
Drush version : 5.9
Drush configuration :

ShaunDychko’s picture

Try the patch in comment #54

greg.1.anderson’s picture

You also have to copy drush.ini to ~/.drush/drush.ini.

C13L0’s picture

Thank you Shaun and Greg for super fast replies! I applied the patch, copied example.drush.ini to ~/.drush and renamed it drush.ini. I am probably doing something wrong but it still isn't working. If I am reading drush status correctly, drush.ini isn't over-riding php5.ini. I then copied the php5.ini file to /drush, changed +magic_quotes_gpc = Off. This also did not work. Have I tried everything possible or will it be best to wait for a new version of drush?

PHP configuration : /web/conf/php5.ini
/home/content/14/8477914/.drush/drush.ini
Drush version : 5.9

xmacinfo’s picture

@C13L0: I am curious. Can you add ini_set('magic_quotes_gpc', 'off'); in your settings.php file and report if Drush detects that setting?

JadH’s picture

Finally it worked, I am not getting the error anymore.

This is what I did:
Under .drush/ I have initially the drush.ini file.

I renamed it to php.ini file.

I just tried this based on the help in the drush.ini file.

; To fully specify the value of all php.ini variables,
; copy your webserver php.ini file to one of the
; locations mentioned above (e.g. /etc/drush/php.ini)
; and edit it to suit.

JadH’s picture

Issue summary: View changes

Updated based on comments in #31-40.

greg.1.anderson’s picture

I updated the summary for this issue. The problem is, some platforms seem to ignore -d and ini_set for magic_quotes_gpc. In these instances, php.ini must be used.

It would be great if we could figure out which platforms have this problem, so that we could document it. Failing that, I suppose we could change the documentation so that it says "if this does not work, edit php.ini."

C13L0’s picture

@xmacinfo - I added to the settings.php file of one of the drupal sites (there are several sites on the same server, some are drupal and some aren't). There is no change

/**
 * Test to see if drush detects magic_quotes_gpc setting
 */
ini_set('magic_quotes_gpc', 'off');
JadH’s picture

Hi All,

Even though I stopped getting the error with the magic_quotes, I am not being able to use drush.

I assume it is a bad environment installation on OSX 10.8.

I am using drush installed with Acquia, and now I don't know if I should uninstall everything and re-install and configure everything from scratch.

An example of some of the errors I am getting, maybe you can guide me if I should keep and it is a matter of some configurations or not.

Command make-generate needs a higher bootstrap level to run - you will need to invoke drush from a more functional Drupal environment to run this command. [error]
The drush command 'generate-makefile template.make' could not be executed. [error]
Drush was not able to start (bootstrap) the Drupal database. [error]

N.B. If it is not related, please let me know so I remove this from the queue here.

greg.1.anderson’s picture

#72: Please post in a separate issue. In this thread, we would like to determine under what circumstances -d and ini_set do not work to set magic_quotes_gpc.

geerlingguy’s picture

I figured out the problem on my computer (finally); for an earlier version of MAMP, I had copied out the MAMP php.ini and pasted it into ~/.drush/php.ini, and it had the wrong path to the PHP binary inside (as well as some other old, stale values).

I deleted the new drush.ini file I had added, and also updated the php.ini file inside .drush with the latest (5.3.20) php.ini from MAMP, and now I don't get the warning anymore.

C13L0’s picture

Since this is a fact finding mission, I wanted to note this is a GoDaddy shared server which is CentOS release 5.5 (Final)

serialbob’s picture

#51 work for me, i think it's php version or server dependant.
In my case Debian 5 / php 5.2.x

Thanks

dddbbb’s picture

#51 worked for me (MAMP Pro).

Michael-IDA’s picture

#73 Hi Greg,

From http://php.net/manual/en/security.magicquotes.disabling.php

Disabling Magic Quotes

The magic_quotes_gpc directive may only be disabled at the system level, and not at runtime. In otherwords, use of ini_set() is not an option.

Best,
Sam

Michael-IDA’s picture

Hi Greg, et. all,

Question / Footnote on the whole Magic Quotes:

I have multiple machines / hosting accounts running PHP 5.3.x, which have "magic_quotes_gpc => On" but "magic_quotes_runtime => Off" , using Drush versions < 5.8. [one is pasted below]

I just purchased a new VPS w/ 6 Cores, 24 Gigs RAM, 24 Gigs Swap, etc., blah. to move/consolidate clients too. It has the exact same Magic Quotes setup.

Drupal 5, 6, and 7 have never had a problem with Magic Quotes. Drush 5.7 (and lessor) never reported an error. Drush 5.9 now spits that error, which I have to question, “Is it truly an error?”

And, as an old business programmer, I'd rather not break working D5, D6, and D7 sites to add an error message or error check for an item that showed no destructive behavior. Alternatively you could say, “Even if it is a bug, it's been working correctly for the last 5 to 10 years.”

Especially since Magic Quotes will be removed entirely as of PHP 5.4.

Unfortunately, I don't really have a constructive suggestion. Just the question, “Can't we just leave it alone to die a natural death?” [, and spend our time working on something more productive?]

Best Regards,
Sam

From http://www.php.net/manual/en/security.magicquotes.what.php

magic_quotes_gpc Affects HTTP Request data (GET, POST, and COOKIE). Cannot be set at runtime, and defaults to on in PHP. See also get_magic_quotes_gpc().

magic_quotes_runtime If enabled, most functions that return data from an external source, including databases and text files, will have quotes escaped with a backslash. Can be set at runtime, and defaults to off in PHP.

$ php -ini | grep magic
Configure Command =>  './configure'  '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib64' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-xpm-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--with-kerberos' '--enable-ucd-snmp-hack' '--enable-shmop' '--enable-calendar' '--without-sqlite' '--with-libxml-dir=/usr' '--enable-xml' '--with-system-tzdata' '--enable-force-cgi-redirect' '--enable-pcntl' '--with-imap=shared' '--with-imap-ssl' '--enable-mbstring=shared' '--enable-mbregex' '--with-gd=shared' '--enable-bcmath=shared' '--enable-dba=shared' '--with-db4=/usr' '--with-xmlrpc=shared' '--with-ldap=shared' '--with-ldap-sasl' '--with-mysql=shared,/usr' '--with-mysqli=shared,/usr/lib64/mysql/mysql_config' '--enable-dom=shared' '--with-pgsql=shared' '--enable-wddx=shared' '--with-snmp=shared,/usr' '--enable-soap=shared' '--with-xsl=shared,/usr' '--enable-xmlreader=shared' '--enable-xmlwriter=shared' '--with-curl=shared,/usr' '--enable-fastcgi' '--enable-pdo=shared' '--with-pdo-odbc=shared,unixODBC,/usr' '--with-pdo-mysql=shared,/usr/lib64/mysql/mysql_config' '--with-pdo-pgsql=shared,/usr' '--with-pdo-sqlite=shared,/usr' '--with-sqlite3=shared,/usr' '--enable-json=shared' '--enable-zip=shared' '--without-readline' '--with-libedit' '--with-pspell=shared' '--enable-phar=shared' '--with-tidy=shared,/usr' '--enable-sysvmsg=shared' '--enable-sysvshm=shared' '--enable-sysvsem=shared' '--enable-posix=shared' '--with-unixODBC=shared,/usr' '--enable-fileinfo=shared' '--enable-intl=shared' '--with-icu-dir=/usr' '--with-enchant=shared,/usr' '--with-recode=shared,/usr'
magic_quotes_gpc => On => On
magic_quotes_runtime => Off => Off
magic_quotes_sybase => Off => Off

$ drush status
 PHP configuration     :  /etc/php.ini 
 Drush version         :  5.7          
 Drush configuration   :               
greg.1.anderson’s picture

The intention here was to attempt to automatically disable magic_quotes_* in Drush via -d options to php (per #78, the idea to use ini_set cannot work by design). As far as I know, this is only to benefit D8; I don't think that D6 or D7 have a problem with magic_quotes_*. The open issue we still have here is that some systems (usually MAMP?) do not allow -d to affect the magic_quotes_* values.

It also seems that some mistakes were made here. #35 was never committed. (To be fair, I am not sure if this is because it was unnecessary, or if it was just missed, but I suspect the later.) #47 seems to not fix the problem, as it accidentally removes the key portion of the new behavior:

--- a/drush
+++ b/drush
@@ -120,9 +120,6 @@ if [ -n "$PHP_OPTIONS" ] ; then
   php_options="$php_options $PHP_OPTIONS"
 fi
 
-# Always disable magic_quotes_gpc and friends
-php_options="$php_options -d magic_quotes_gpc=0 -d magic_quotes_runtime=0 -d magic_quotes_sybase=0"
-

Adding magic_quotes_* to php_option is the main thing we were trying to accomplish here, so that should not have been removed.

Regarding #79, I don't know how much value there is to adding magic_quotes_* to our ini checks. Doing this might help some MAMP folks for whom the -d fix does not work, iff they are using D8, as without it, Drupal might fail later if their config is wrong, and this might be hard to diagnose. For all others, it adds a spurious error.

I will make a patch that re-applies the code that shouldn't have been removed in #47, but it uses 'Off' instead of '0', like 35, and remove the magic_quotes_* items from our ini checks during bootstrap.

greg.1.anderson’s picture

Status: Needs work » Needs review
FileSize
2.13 KB

Here is the aforementioned patch. It looks like #47 actually switched from -d to ini_set, which does not work. Sorry about that.

byronveale’s picture

For what it's worth...

I was getting this error using drush 5.9 with the Acquia dev desktop 7.22.23 (Drupal 7.22) on Mac OS X 10.8.4:

The following restricted PHP modes have non-empty values: magic_quotes_gpc and magic_quotes_runtime. This configuration is incompatible with drush. Please check your configuration settings in or in your drush.ini file; see examples/example.drush.ini for details.

Copied drush/example.drush.ini into ~/.drush/drush.ini, and copied this into that file:

magic_quotes_gpc = 
magic_quotes_runtime = 
magic_quotes_sybase = Off

No more error message!

Probably don't need that last line...

Hope this helps someone else getting this error message; I got tired of seeing it every time I typed a drush command!

Michael-IDA’s picture

Hi Greg,

> “As far as I know, this is only to benefit D8”

I use Drush everyday (okay, that might be stretching it a little) on numerous hosts, having to patch every Drush install above 5.8/5.9 is problematic. [In truth, I've just regressed to 5.7. Time benefit analysis and such.]

I hit the error message with Recommended releases, Drush version 7.x-5.9, which does not support Drupal 8 (well per the Drush project page). Drush 6.x will support Drupal 8.

Can we then remove this from the Drush 5.x series? And, leave whatever Drupal 8 needs in the Drush 6.x series?

Best,
Sam

[Lord help me, I've probably typo'd a Drupal for a Drush somewhere]

greg.1.anderson’s picture

I think #81 will address your issues; it can be backported to Drush-5 after it is committed to Drush 6. I don't know why the magic-quotes stuff was backported to Drush 5; maybe I'm wrong about this only being for D8. I didn't do the research to see when it was actually introduced.

moshe weitzman’s picture

Status: Needs review » Fixed

Committed to 6. Should we also now remove the mention of these ini settings from README.txt? I left it since it sounds like some platforms don't honor -d

greg.1.anderson’s picture

Status: Fixed » Patch (to be ported)

I think that the README.txt instructions are necessary to help folks who are on a platform where -d does not work.

Should this be backported to Drush 5?

greg.1.anderson’s picture

Status: Patch (to be ported) » Needs review
FileSize
4.54 KB

Here is a backport to 7.x-5.x.

greg.1.anderson’s picture

Version: 8.x-6.x-dev » 7.x-5.x-dev

Setting version.

jonhattan’s picture

Status: Needs review » Fixed

Tested and committed to 5.x

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Some platforms do not respect -d or ini_set for magic_quotes_gpc.

josericardo’s picture