I had a few clients that did not want to run Drupal on VPS server as they were on a very tight budget so preferred to opt for a shared hosting platform such as A2Hosting. Personally, I believe if you are serious about your business, it is recommended to go with a VPS server for the flexibility and better site performance. DigitalOcean offers VPS at a very affordable price.
Is it possible to run Drupal 8 or 9 on a shared hosting platform? the short answer is yes.
So what is the best way to install, update and manage a Drupal installation on a shared hosting platform when Composer is not available. Composer is the recommended way to install and manage Drupal 8/9 and its 3rd party dependencies libraries.
How do we get around this issue if we cannot use Composer on shared hosting platform to manage the updates, modules and dependencies? There are different methods to tackle this but generally, it would be to run Composer locally on your machine to manage your local Drupal site and then either SFTP or Rsync your local copy to your live site. This can be time consuming and you need to make sure it is manually properly copied over to avoid making any mistakes. Therefore, using Git is probably a better solution to speed up the process and ensure it is less prone to errors. You also have a backup copy to refer back to in case you mess things up by accident. There are many other great advantages using Git as a version control system but for this article, we'll keep stick with the basics.
Ok, enough rambling. let's get to work.
This article aims to install, update and manage your Drupal site for those that still choose to use a shared hosting platform. Note: A2Hosting do offer Composer on their shared hosting plan but it can timeout and kill the process when trying to update. This is caused by insufficient memory and increasing the memory often don't help either (Composer requires at least 2G of memory). However, it does have a better performance than most other web hosting service providers.
I think it would be easier to break this article into a few parts. It is assumed that you are comfortable using Composer, command line and Git. You don't need to be an expert, just some basic knowledge should be sufficient. It is also assumed you are using an Apple Mac and running MAMP since these are the development tools used in this tutorial but i do hope this tutorial may also be useful for MS Windows users.
To begin, we need to make sure it meets all the requirements to run Drupal.
For Drupal 8/9:
- Apache 2.4.7+
- MySQ, Percona 5.7.8 or MariaDB 10.3.7+
- PHP 7.3 or higher
Tools used for this development process:
- MAMP 5.7 (this is the latest version as of writing this article)
- Composer manager
- Git and Github
To install Composer, you can follow this guide at: https://duvien.com/blog/installing-composer-mac-osx (Note: the article is outdated. Some things may have changed since then so read the comments if you experienced issues trying to install Composer on Mac OS).
Installing a local copy of Drupal 8/9
Open up MAMP and start the server. Click on PHP in the sidebar and change the version to 7.3.9 or higher. i'm using MAMP Pro, if you are using the free version, click on PHP tab and select a version.
Next, click on 'Webstart' to open up the MAMP webpage start page. Click on the tool menu and click phpmyadmin. We will use this tool to setup a new database. On the sidebar of phpmyadmin, you will see a tree style listing all the databases. Click on new (at the top) to create a new database. Enter a name for your database and click on create.
Now that we have a new database ready, open up a terminal and change directory. To do this type:
This takes us into the web root directory of MAMP. We can now install Drupal using this command:
composer create-project drupal/recommended-project test
Note: test is the directory i want to install Drupal into. It is up to you whatever name you want to give your installation root directory. /test directory will contain files that should be outside of your web root and not accessible by the web server. The web root will be /test/web
Composer will fetch the latest version. During this writeup, Drupal version 9.0.1 was the latest.
If for some reason you want to install a specific version of Drupal, you append the version number like this:
composer create-project drupal/recommended-project:8.9.1 test
This will fetch and download Drupal 8.9.1 instead.
Once Composer has completed downloading Drupal, you will now have a new directory that contains Drupal in it. In my case, the new directory was /test (remember you can provide your own name for the directory). You will also find a sub directory inside /test called /web This is the Drupal web root directory. It is important to understand this so that when creating a host it will makes sense to you.
Next, setup a vhost so we can serve the site as root from a sub directory acting as the main domain. On MAMP Pro, click on 'Host' in the sidebar. In the middle of the window pane, you will see a list of host. At the bottom of this pane there is + and - sign, click on the + sign to add a new host. Give your vhost a name (this is used as the url address to access your website). Next, select the sub directory for this vhost. For example, I selected
(this is Drupal's web root).
Open up a web browser and visit: http://test/ (I named my host 'test', your host will be whatever name you provided).
If you are using the free version of MAMP, you'll need to setup vhost manually. This video tutorial below should help you:
Again, open up a web browser and visit: http://test/ (I named my host 'test', your host will be whatever name you provided).
If all goes well, you should be presented with Drupal's installation page. This means you are ready to install Drupal.
Go through the standard installation process. Select 'Standard' as the installation profile.
For database configuration:
Database name: test Database username: root Database password: root
Database name is the name of the new database you setup using phpmyadmin. In my case, it was 'test'.
Database username is the database user that has full permission to the database. By default, 'root' user is used.
Database password is the database user's password. By default, the root password is 'root'.
Important notice: do not allow your web server to serve webpages externally on the web. Only run it locally on your machine, otherwise you must change the root user password for stronger security protection. MAMP should only be ran locally on your Apple computer.
Finally, complete all the fields in the 'configure site' page. We have now completed the installation.
In the next part of this tutorial, we will setup Git and Github.
- Installing and updating Drupal 9 on shared web hosting platform for Mac user (part 1)
- Installing and updating Drupal 9 on shared web hosting platform for Mac user (part 2)
- Installing and updating Drupal 9 on shared web hosting platform for Mac user (part 3)
- How to handle Git submodules in my Drupal repository