-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to override / set php options for Drush 9+? #3294
Comments
Interestingly running:
Then running:
So, the php cli is seeing the php option but |
Drush 9 is now out of the business of setting up your PHP environment. It got too complex to maintain this. Drush does create subprocesses for some commands (sql-sync, updb, config-pull, ...). Those subprocesses probably dont see the -c option so the subprocess gets memory starved. Thats my guess. That doesn't really answer your question. For right now, Drush9 is declaring the question "out of scope". At minimum, I'd like to add some docs to help people who are using a constrained php environment like you are. |
Thanks @weitzman for the reply. I tried everything I could think of my greatest hope was a bash alias for php that added the php.ini via the -c option but as you said it seems the sub processes do not see it. I was able to get the memory_limit on the VPS PHP configuration raise to an acceptable level so I am back in business. However I do hope that a solution to this for others can be found. |
Update: An alternative PHP_INI_SCAN_DIR approach is documented below I think the best way to do this is to insure that the PHPRC environment variable is set to the directory containing the desired php.ini. Subprocesses get the same environment so the change persists there. You can set the variable just for one request. See
|
now documented in install docs |
@weitzman This works on linux in a normal bash shell but not in a Cpanel bash jailedshell. To test on both servers I created a /tmp/php.ini file that sets the memory_limit = 128M. Normal Linux User: $ PHPRC=/tmp env | grep PHPRC
PHPRC=/tmp
$ PHPRC=/tmp drush st
Drupal version : 8.4.4
Site URI : default
DB driver : mysql
DB hostname : db
DB port : 3306
DB username : user
DB name : default
PHP binary : /usr/bin/php7.1
PHP config : /tmp/php.ini
PHP OS : Linux
Drush script : /home/user/docker/l2mch/vendor/bin/drush
Drush version : 9.1.0
Drush temp : /tmp
Drush configs : /home/user/docker/l2mch/vendor/drush/drush/drush.yml
/home/user/docker/l2mch/drush/drush.yml
Drupal root : /home/user/docker/l2mch/docroot
Site path : sites/default
$ drush --version
Drush Launcher Version: 0.5.1
Drush Commandline Tool 9.1.0
$ Cpanel Jailed shell user $ PHPRC=/tmp env|grep PHPRC
PHPRC=/tmp
$ PHPRC=/tmp drush st
$ The $ PHPRC=/tmp vendor/bin/drush st
Fatal error: Uncaught Error: Call to undefined function Drush\Preflight\ctype_alpha() in /home/user/example.com/releases/20180205-090119-live-0.2.0/vendor/drush/drush/src/Preflight/ArgsRemapper.php:49
Stack trace:
#0 /home/user/example.com/releases/20180205-090119-live-0.2.0/vendor/drush/drush/src/Preflight/ArgsRemapper.php(32): Drush\Preflight\ArgsRemapper->checkRemap('st', false)
#1 /home/user/example.com/releases/20180205-090119-live-0.2.0/vendor/drush/drush/src/Preflight/ArgsPreprocessor.php(55): Drush\Preflight\ArgsRemapper->remap(Array)
#2 /home/user/example.com/releases/20180205-090119-live-0.2.0/vendor/drush/drush/src/Preflight/Preflight.php(163): Drush\Preflight\ArgsPreprocessor->parse(Array, Object(Drush\Preflight\PreflightArgs))
#3 /home/user/example.com/releases/20180205-090119-live-0.2.0/vendor/drush/drush/src/Preflight/Preflight.php(229): Drush\Preflight\Preflight->preflightArgs(Array)
#4 /home/user/example.com/releases/20180205-090119-live-0.2.0/vendor/drush/drush/src/Runtime/Runtime.php(58): Drush\Preflight\Preflight->prefl in /home/user/example.com/releases/20180205-090119-live-0.2.0/vendor/drush/drush/src/Preflight/ArgsRemapper.php on line 49
$ drush --version
Drush Launcher Version: 0.5.0
Drush Commandline Tool 9.0.0-rc1
$ Let me know if there is any more information that I can supply or test I can run to help fix this. |
Do you think the version of the Drush command line tool has anything to do with it? Just saw that one is an RC and the other is a stable release version. |
Seems like the original question has now been answered. could you edit this line and add a `\ before ctype_alpha. that may fix it. I'm not clear when that's needed since php has a fallback policy. |
And yeah, 9.0.0-rc1 is quite old. Tha could be contributing to the problem. Hard to say. |
@weitzman I made the modification that you suggested above adding if (!$sawCommand && /ctype_alpha($arg[0])) { I also updated Drush before:
However still got no ouput when I run |
slash needs to go in other direction - |
Sorry, I tried it again with the line |
Sounds like your PHP does not have the ctype extension. Thats quite rare. |
I landed here searching for how to deal with this in Drush 9 and settled on this so I didn't have to maintain a physical file for my override:
|
Note that if you simply want to modify a few of the php.ini parameters, then rather than using the PHPRC environment variable to specify a completely new php.ini file, there's a simple way to specify an additional '.ini' file which contains just your customisations. After php has loaded the php.ini file located in the directory indicated by the PHPRC For example, create a directory /home/myname/mydrush, and in this put a file named drush.ini, containing the custom initialisation commands you require. Then you can call drush with:
The colon at the front of the assignment causes the directory you specify to be added to the end of the list of additional directories that php searches looking for .ini files when it starts up. (In Ubuntu 18.04, for example, php 7.3 will scan for additional .ini files in the directory /etc/php/7.3/cli/conf.d) You can get a confirmation of exactly which .ini files php is loading using a command such as:
Note that with php 7.3.16, this command will show:
This is misleading - it doesn't list the names of the other "additional" directories that are scanned prior to your custom one. But you can easily reassure yourself that they are in fact being scanned, because the command goes on to list "Additional .ini files parsed: ", and there you'll see the complete list of .ini files loaded. For more on PHP_INI_SCAN_DIR, see https://www.php.net/manual/en/configuration.file.php |
Great tip! I added a link to it from the comment above thats linked in the install docs. |
I can't get this to work, hope you can help me with this: Then when I try So it looks like it is looking at the right php.ini file but still I get this message even though have removed all disable_functions from this specific file. What am I doing wrong? |
This only causes the value of PHPRC to be set for the single command "env". If you want the setting of PHPRC to apply when you call drush, you either need to do the setting on the same line where you invoke drush, e.g.
Or, you can make the setting persist in your current shell environment by doing:
|
Thanks, but unfortunately this doesn't work as expected: Outputs:
So it does find my custom php.ini file but still doesn't work. And when removing the Disable Functions via Direct Admin (just for testing) it does work...? |
Hi StudioVDS, |
Hi, I'm using the drush.ini file I used for Drush 7. You can see it here. When I use
But still I get this message: About the |
Hi StudioVDS, I'm pretty confident that your .bash_profile file is not being loaded by your webserver, but if you want to be sure, just make a short php script that runs phpinfo(); put it in your docroot, and load it through a web browser. This will show you what ini files are loaded. (Delete the script when you're done - it can be a security risk otherwise.) |
With the move to Drupal 8.4 I switched one of my sites to a site installed Drush 9. I also installed the Drush launcher.
I have the following environmental variables related to Drush set:
This is on a server where the php.ini for the cli sets
memory_limit=32M
. With Drush 8 globally installed I could use~/.drush/drush.ini
to setmemory_limit=512M
.I did see in issue #2934 that the drush.ini file is ignored and that that the drush launcher does not handle drush.ini either.
I have tried unsuccessfully to run Drush 9 and increase the memory limit. Here is what I have tried using the updb to test the memory_limit=32M:
It appears that --php-options is not a valid option with Drush 9 as it spits out the default help text after the above console output.
So setting the PHP options in a file does not seem to work either. I made a copy of the default php.ini and then increased memory_limit=512M.
So, is there a way to set php options for Drush 9? And is is also possible to use the Drush launcher with this too?
The text was updated successfully, but these errors were encountered: