Note: If you need to install multiple sites using multiple installations of Drupal 10 on a shared web hosting plan, please refer to "How to build multiple Drupal 10 sites directly on the web server using Composer, on a shared web hosting plan, without using git or localhost".
One of the best CMS, Drupal 7 is nearing its end of life on January 2025. The switch to Drupal 10 and later to Drupal 11 is inevitable for all developers who want a solid content management framework, and not just a blogging software (you know which one!) for their projects.
Installing Drupal 10 on a shared web hosting, which requires the Composer, can often be an intimidating task for new developers, as Drupal 7 did not require the PHP Composer. If you refer to the official documentation available on Drupal.org, it is likely that a new developer may take months together just to learn to install Drupal 10, as Composer is a must for building as well as managing Drupal 10 based sites, and the documentation is often confusing. Unfortunately, the official documentation as well as many tutorials available on the web, more or less insists that the developer builds a local or a test site on localhost or git, then push it to the live server for the production site, and that the Composer should never be used on the production site!
However, a developer may use the Composer on live server and on a production site, and we have been doing the same for 4 of our Drupal 10 based sites.
In this tutorial, we will tell you how to install Drupal 10 directly on the web server using Composer, on a shared web hosting plan Composer, without using localhost or git.
- Prerequisite: Composer - Since the installation of Composer on a shared hosting plan itself is an onerous task for a new developer, one may get a shared web hosting plan with Composer pre-installed. Please refer to the best shared web hosting providers with Composer installed by default.
- At the outset, you need to enable the SSH on your hosting plan, by following the procedure mentioned in the knowledgebase provided by the web hosting service provider, and get it activated by contacting their tech support.
- Create a MySQL database, using database wizard or phpMyAdmin on the cpanel, allow the necessary permissions for the database, and note down the credentials, like database user name and database password.
- Connect to the server using SSH, while using a client like PuTTY.
- At home (not at web or public_html) on the command prompt of SSH, execute the command "composer create-project drupal/recommended-project drupfolder --no-interaction --no-install". This creates a folder by name "drupfolder" and two files composer.lock and composer.json in that folder.
- Using the File Manager in cpanel, move the two files thus created, composer.lock and composer.json, to home (outside the webroot), so that the folder structure is:
| -drupfolder (with nothing inside)
| -vendor (will be created later, after installation is complete)
| -composer.json
| -composer.lock
| -public_html
i.e., two directories - drupfolder, vendor, and two files - composer.json, composer.json are at home, not under
public_html (under which all other drupal system files and folders will be placed later, after installation).
- Using the File Manager in the cpanel, edit the file composer.json, and exactly at 9 (nine) locations, where the web root is referred in the file, replace "web" with "public_html" at 9 occurrences.
- Visit SSH again, and at home, run the command "composer install".
- Visit the browser, type the url of the domain, and install Drupal 10 using the interactive installer as usual.
Once installed, the "Vendor" directory will be at home, not under "public_html" or web root as recommended by Drupal documentation.
This tutorial best works for the websites where you have only one website built using Drupal 10 on the web server.