How to install Drupal into a custom directory clearly. What to do if you use a certain directory structure on hosting, or just want to adhere to your standard of directories naming?
We will use Composer for the installation process.
For example, we want to use the directory htdocs.
By create-project, we will fetch and pre-install a standard Drupal project template with a "relocated document root", in this case with the name web.
composer create-project drupal/recommended-project ./
Now let's change this folder for our one.
In order for the composer to do this automatically for us, it is necessary to edit the file composer.json.
cat composer.json > composer.bak
cat composer.bak | sed 's/"web\//"htdocs\//g' > composer.json
rm composer.bak
Let's create the new required directories, htdocs for our "relocated document root" and tmp for Drupal needs.
mkdir htdocs tmp
Now we must move the contents of the default directory to the newly created one.
mv web/.??* htdocs
mv web/* htdocs
Removing an unnecessary directory
rm -r web
In order for the composer to make the necessary changes due to a change of the document directory, we should run install
composer install