Skip to main content
Home
Drupal life hacks

Main navigation

  • Drupal
  • React
  • WP
  • Contact
  • About
User account menu
  • Log in

Breadcrumb

  1. Home

To create a custom ddev command for running php bin/magento in a Magento project

By admin, 26 January, 2025

To create a custom ddev command for running php bin/magento in a Magento project, follow these steps:


1. Open the .ddev/commands/web or .ddev/commands/host directory

This is where custom commands for ddev are stored.


2. Create a new file for the command

Create a file named .ddev/commands/web/magento (no file extension) and add the following content:

#!/bin/bash

# Runs php bin/magento inside the web container
php bin/magento "$@"

3. Make the file executable

Run the following command to give execution permissions:

chmod +x .ddev/commands/web/magento

4. Apply the changes

Restart your ddev project to load the new command:

ddev restart

5. Use the command

You can now run any Magento command using ddev:

ddev magento cache:flush
ddev magento setup:upgrade

Explanation

  • "$@" ensures all arguments passed after ddev magento are forwarded to php bin/magento.
  • Placing the script in .ddev/commands/web/ makes it available inside the container, while placing it in .ddev/commands/host/ makes it available on your local machine.

And that's it! 🎉 Now you can easily run Magento commands with ddev.

Tags

  • DDEV
  • Magento

Comments

About text formats

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
Powered by Drupal