'How can I add to the $PATH in the DDEV-Local web container? (for drush, for example)
I need an additional directory to appear in my $PATH in the ddev web container, for example, /var/www/html/bin, and I need it to show up not just when I ddev ssh (which could be done with ~/.homeadditions/.bashrc) but also when I use ddev exec. This came to a head with ddev v1.17, where drush launcher was removed from the web container and so ddev exec drush and ddev drush no longer found the drush command in my nonstandard composer install.
Solution 1:[1]
Edited for DDEV v1.19+:
There's a new and efficient/flexible way to add to the $PATH now.
mkdir -p .ddev/homeadditions/.bashrc.d
cd .ddev/homeadditions/bashrc.d
then just edit a file named path.sh (name isn't important) and add to it something that changes the $PATH, for example export PATH=$PATH:/var/www/html/somewhereelse/vendor/bin
See docs.
--------- Original answer below ------------
There are at least two ways to extend the $PATH in the web container. Here we'll add /var/www/html/something to the standard $PATH.
Either of these options will work:
- Mount a replacement commandline-addons.bashrc with a docker-compose.path.yaml:
.ddev/docker-compose.path.yaml:
version: '3.6'
#ddev-generated
services:
web:
volumes:
- ./commandline-addons.bashrc:/etc/bashrc/commandline-addons.bashrc
.ddev/commandline-addons.bashrc:
export PATH="$PATH:/var/www/html/vendor/bin:/var/www/html/something"
- Add /editthe commandline-addons.bashrc in a .ddev/web-build/Dockerfile. (If you use this option, the custom Dockerfile overrides
webimage_extra_packagesin .ddev/config.yaml, so you'll have to use workarounds in docs)
ARG BASE_IMAGE
FROM $BASE_IMAGE
RUN echo 'export PATH="$PATH:/var/www/html/vendor/bin:/var/www/html/something"' >/etc/bashrc/commandline-addons.bashrc
Both of these options require a ddev restart after adding them.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
