Drupal: Difference between revisions

From 太極
Jump to navigation Jump to search
Line 21: Line 21:
** Search "sites" in the source code. The most reliable ways to show if a site is using Drupal is to check the source code. In the source code, check to see if important files are being loaded from the '''/sites/''' folder.
** Search "sites" in the source code. The most reliable ways to show if a site is using Drupal is to check the source code. In the source code, check to see if important files are being loaded from the '''/sites/''' folder.
** Search "drupal" in the source code
** Search "drupal" in the source code
= Composer =
<ul>
<li>[https://getcomposer.org/ Composer] is a '''dependency manager''' for '''PHP'''. Drupal core uses Composer to manage core dependencies like Symfony components and Guzzle.
* PHP has to be installed. Use ''php -v'' to check your PHP version.
<li>[https://www.drupal.org/docs/develop/using-composer/using-composer-with-drupal Using Composer with Drupal]
<li>'''You can use Composer to download and install Drupal core''', as well as contributed modules, themes, and their third-party dependencies.
<li>Composer can also be used to update Drupal and its dependencies.
<li>[https://getcomposer.org/doc/03-cli.md List of composer commands]
* composer install: This command reads the composer.json file from the current directory, resolves the dependencies, and installs them into the vendor directory.
* composer require: This command adds new packages to the composer.json file and installs them. For example, '''composer require drush/drush''' will install '''drush'''. We can use a similar command to install drupal.
* composer update: This command updates the dependencies to their latest versions according to the composer.json file.
* composer remove: This command removes packages from the composer.json file and reupdates the dependencies.
* composer list: list all commands
* composer self-update.
</li>
</ul>
== Install Drupal ==
* Installing Drupal, Drush and Console - from the course of [https://www.linkedin.com/learning/linux-for-php-developers/installing-drupal-drush-and-console Linux for PHP developers] (linkedin), although this is not a recommended installation way of WordPress and Drupal.


= DDEV and PHP =
= DDEV and PHP =
Line 43: Line 66:
* DDEV has built-in Composer commands
* DDEV has built-in Composer commands
* Commands: DDEV provides the ''ddev composer'' and ''ddev composer'' create commands. These run Composer inside the container.
* Commands: DDEV provides the ''ddev composer'' and ''ddev composer'' create commands. These run Composer inside the container.
</li>
</ul>
== Composer ==
<ul>
<li>[https://getcomposer.org/ Composer] is a '''dependency manager''' for '''PHP'''. Drupal core uses Composer to manage core dependencies like Symfony components and Guzzle.
* PHP has to be installed. Use ''php -v'' to check your PHP version.
<li>[https://www.drupal.org/docs/develop/using-composer/using-composer-with-drupal Using Composer with Drupal]
<li>'''You can use Composer to download and install Drupal core''', as well as contributed modules, themes, and their third-party dependencies.
<li>Composer can also be used to update Drupal and its dependencies.
<li>[https://getcomposer.org/doc/03-cli.md List of composer commands]
* composer install: This command reads the composer.json file from the current directory, resolves the dependencies, and installs them into the vendor directory.
* composer require: This command adds new packages to the composer.json file and installs them. For example, '''composer require drush/drush''' will install '''drush'''. We can use a similar command to install drupal.
* composer update: This command updates the dependencies to their latest versions according to the composer.json file.
* composer remove: This command removes packages from the composer.json file and reupdates the dependencies.
* composer list: list all commands
* composer self-update.
</li>
</li>
</ul>
</ul>

Revision as of 16:22, 10 January 2024

Resource

Websites by drupal

Composer

  • Composer is a dependency manager for PHP. Drupal core uses Composer to manage core dependencies like Symfony components and Guzzle.
    • PHP has to be installed. Use php -v to check your PHP version.
  • Using Composer with Drupal
  • You can use Composer to download and install Drupal core, as well as contributed modules, themes, and their third-party dependencies.
  • Composer can also be used to update Drupal and its dependencies.
  • List of composer commands
    • composer install: This command reads the composer.json file from the current directory, resolves the dependencies, and installs them into the vendor directory.
    • composer require: This command adds new packages to the composer.json file and installs them. For example, composer require drush/drush will install drush. We can use a similar command to install drupal.
    • composer update: This command updates the dependencies to their latest versions according to the composer.json file.
    • composer remove: This command removes packages from the composer.json file and reupdates the dependencies.
    • composer list: list all commands
    • composer self-update.

Install Drupal

  • Installing Drupal, Drush and Console - from the course of Linux for PHP developers (linkedin), although this is not a recommended installation way of WordPress and Drupal.

DDEV and PHP

  • DDEV is an open-source tool that makes it simple to set up local PHP development environments within minutes. It’s often used for Drupal development, and it has built-in support for Drush, the command-line utility and scripting interface for Drupal.
  • https://www.drupal.org/ddev. DDEV builds the DDEV-Local tool, which helps PHP developers remove the complexity of local containerized development across operating systems and hosting providers.
  • The software support Mac, Windows, Linux and Cloud.
    • Other than Drupal, it also supports other CMS and PHP frameworks such as WordPress, BackDrop, TYPO3, Magento, et al. CMS Quickstarts
    • Gitpod for cloud deployment
  • https://github.com/ddev/ddev
  • DDEV and Drush
    • Drush commands in DDEV: ddev exec drush --version
    • Drush Use with DDEV: drush site:set
    • Environment Variables in DDEV: you can set an environment variable in your .ddev/config.yaml
    • Performance Improvements
  • DDEV and Composer
    • DDEV has built-in Composer commands
    • Commands: DDEV provides the ddev composer and ddev composer create commands. These run Composer inside the container.

Drush

  • Drush, also known as the Drupal Shell, is a command-line utility and scripting interface for Drupal. It’s widely used in Drupal development and system administration. It’s recommended to use composer to install Drush inside your project.
    • Speeds up tasks: Drush can speed up installing, developing, debugging, and maintaining Drupal sites.
    • Generates boilerplate code: It’s capable of generating boilerplate code for custom developments.
    • Command-line interface: Rather than clicking through the admin interface to achieve something, you simply type in one command.
  • It’s recommended to use composer to install Drush inside your project. Local dev tools such as DDEV or Lando provide aliases to run Drush without path and from any directory.
  • Some drush commands
    # Commands list
    drush
    
    # Help about a command
    drush help cache:clear
    
    # Help about a more detailed topic
    drush topic [topic]
    
    # Empty cache (The most used command)
    drush cache:rebuild
    
    # The same with an alias
    drush cr
    

Install by Docker

  • Installing Drupal with Docker Compose on Debian 10
  • How to Install Drupal with Docker on Ubuntu 22.04
  • How To Develop a Drupal 9 Website on Your Local Machine Using Docker and DDEV 2020/8. Installation looks fine but I got a message '400 Bad Request The plain HTTP request was sent to HTTPS port' after I try to sign in. In fact, the operations still work. If I manually changed the URL from "http" to "https", it'll show the new results.
    ddev list  
    ┌────────┬─────────┬──────────┬──────────────────────────┬─────────┐
    │ NAME   │ STATUS  │ LOCATION │ URL                      │ TYPE    │
    ├────────┼─────────┼──────────┼──────────────────────────┼─────────┤
    │ d9test │ OK      │ ~/d9test │ https://d9test.ddev.site │ drupal9 │
    ├────────┼─────────┼──────────┼──────────────────────────┼─────────┤
    │ Router │ healthy │ ~/.ddev  │ http://127.0.0.1:10999   │ traefik │
    └────────┴─────────┴──────────┴──────────────────────────┴─────────┘
    
  • Bitnami package for Drupal. The username/password is user/bitnami. It worked.

Videos (youtube: ddev drupal)