ServerCommand command fails if not excecuted from Drupal root

Created on 9 June 2020, over 4 years ago
Updated 18 January 2024, 11 months ago

Problem/Motivation

php core/scripts/drupal server will fail with the following error if it is not executed from Drupal's root directory:

In Connection.php line 123:
                                                     
  SQLSTATE[HY000] [14] unable to open database file  
                                                     

In Connection.php line 119:
                                                     
  SQLSTATE[HY000] [14] unable to open database file

Steps to reproduce

Install Drupal via Composer using the drupal/recommended-project template .

composer create-project drupal/recommended-project:^9.0.0 drupal9
cd drupal9
php web/core/scripts/drupal quick-start
# Press Ctrl-C to quit the Drupal development server.
php web/core/scripts/drupal server
# Command fails with above error.

The ServerCommand command does not fail if executed from the web directory.

composer create-project drupal/recommended-project:^9.0.0 drupal9
cd drupal9/web
php ./core/scripts/drupal quick-start
# Press Ctrl-C to quit the Drupal development server.
php ./core/scripts/drupal server
# Command works.

Proposed resolution

Similar to the InstallCommand, change directory to Drupal's root early in the execute method.

Remaining tasks

  • Write test.

Results of manual testing

@adhershmnair successfully manually tested the proposed resolution.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Other 

Last updated about 4 hours ago

Created by

🇳🇮Nicaragua dinarcon

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇦Ukraine pingwin4eg Zaporizhia 🇺🇦

    Trying to run php web/core/scripts/drupal server in D11 I get another error:

    The service file "core/core.services.yml" is not valid.

    The patch applies and fixes the error.

    The only remaining task is probably to write a test case. I'm not sure about the directory structure in the testing environment, is there a "web" (or another docroot) directory?

Production build 0.71.5 2024