I'm working on a Drupal 8 site which is deployed on Heroku, how would I run Drush or Drupal commands on here? When I try it with the built in command line on the Heroku site it complains about MySQL not being present. Is it possible to run Drush or Drupal commands on Heroku? Could I run the commands locally but somehow connect to the Heroku boxes?
1 Answers
I got in touch with Heroku support and managed to resolve the problem, in order to install MySQL you have to use their buildpacks.
If you go to your App > Settings > Buildpacks section you can add https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku-community/apt.tgz
which from what I understand allows you to install packages using an Aptfile in your repository.
Once that Buildpack has been added in the root of your code that's deployed to Heroku add a file named "Aptfile", no extension and add the following two lines to it:
mysql-common
mysql-client
I'm not sure if mysql-common
is needed but mysql-client
certainly is. Deploy this to your Heroku environment and you should be able to run Drush commands now, be sure to add that Buildpack before adding the Aptfile
as adding the Buildpack only adds it on the next environment build which happens with a new commit.
Running Drush is pretty easy ones you've done this. To do it via the web interface click the "More" button near the top right of the screen when you're looking at your app in Heroku and select "Open Console" then enter bash in the new panel and click "Run". Now you should be able to run Drush commands from here.
If you want to run the from your local terminal use https://devcenter.heroku.com/articles/one-off-dynos#an-example-one-off-dyno
in the Heroku CLI (which you'll have to install). You may have to use the --dyno
or --app
flags to run Drush in the correct place.
drush status
on the root document return ? – GiorgosK[warning] The command 'mysql' is required for preflight but cannot be found. Please install it and retry.
as an error message but as far as I understand it I cannot install MySQL on to a Heroku box for it to use the mysql command. – Neil Nandwhereis mysql
and add the path to your PATH maybe drush can pick it up from there. Look here for more information unix.stackexchange.com/questions/26047/… – GiorgosKsudo apt-get -yqq install mysql-client
orsudo apt-get -yqq install mariadb-client
. – leymannx