Installing and updating Drupal 9 on a shared web hosting platform for Mac users (Part 1)

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.

Requirements:

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:

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).

SSH comes pre-installed on Mac and so is Git but you need to install Xcode. This is an Apple Mac development toolkit that comes free with 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. 

MAMP 5.7 PHP

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. 

phpmyadmin

 

phpmyadmin

Now that we have a new database ready, open up a terminal and change directory. To do this type:

cd /Applications/MAMP/htdocs

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

/Applications/MAMP/htdocs/test/web 

(this is Drupal's web root). 

Creating a vhost on MAMP Pro version

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: 

Creating a vhost on MAMP free version

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.

 

Joseph (not verified), 30 Sep 2020 - 6:11pm
Dear Author,

I thank you so much for your guidance. I follow very closely, but unfortunately, I got this error:

[ErrorException]
"continue" targeting switch is equivalent to "break". Did you mean to use "
continue 2"?
So, could you tell me what happened and how to solve this?

Thank you,

Joseph C. Pham
Duvien, 28 Feb 2021 - 3:57pm
I've never seen his error before but i'm guessing it has something to do with Composer? have you tried updating your composer installation. Run: composer self-update
Duvien, 01 Oct 2020 - 6:31pm
How far did you get and where did you encounter the error?
thierry (not verified), 25 Feb 2021 - 10:34am
hi Duvien and thanks for this very usefull posts serie. This topic is exactly my point of interrest. I am a drupal hobbist that used to use drupal 6/7 with the regular manual installing process. Nowdays i'am coming back to drupal 9 and i see that composer is alsmost the only way to go. With some difficulties i am now enough confident to install and deploy locally a composer based drupal site (and know i enjoy the convenience of composer). having said that I project myself to moving a local site to an online server. I gave a try with a regular mutual hosted server but faced constaints you described. I canceled my subscription (before reading your articles). Even though your tutorial exactly would help on this situation, i am now considering subscribing to a basic VPS offer. can you please confirm if with such solution I would have to only upload a composer based drupal structure as well as importing the mysql db, update the db connection settings, and define the subfolder public_html/web as the root for my domain and then it should be fine ?. will a VPS offer will give me an interface to do this "easily" (through the dasboard) ? Sorry for such a big post but I am in big need of clarification on this and i believe your insights will help me a lot ! ;-)
Duvien, 28 Feb 2021 - 3:44pm
There's a lot more manual process involved using a VPS server. You would need to manage most of it yourself, unless you opt for a managed VPS. There is were the hosting provider manages the VPS for you, however this is a more expensive approach. The other method would be to use an unmanaged VPS DigitalOcean (link in sidebar) is a good option. If you plan on using Composer on the VPS (which i don't by the way cos i check everything into Git and pull this into my live site so i only use Composer on local development), choose the plan with 2GB RAM that is how much Composer needs to run effectively, Next, you need to choose a drop to install. These are images that contain the full setup so you don't need to install each individually. So you can select a drop to setup a full working LAMP stack and be ready to setup live site. https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-20-04

Yes, you will still need to make /web the webroot but with a VPS with root access, it's much easier. You need to go into Apache config file and create a new rewrite rule to make /web serve as webroot so no messing with htaccess file (which isn't really recommended even though it works). This doc explains how: https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite

If in doubt, DigitalOcean has a wealth of easy to follow tutorials to get you started.
thierry (not verified), 28 Feb 2021 - 9:41pm
thanks very much for your complete response.
I have been playing around with self managed vps package for few days. The offer i took is 1 GIG of ram so non composer.
You confirmed in your post that composer can be used only locally and that the srtuture can me uploaded to the vsp virrtual website.
something I discovered is that you have to choose a "panel". I gave few tries and pretty much favorised Webmin/virtualmin and cyberpanel at these stage of my thinking.
surely i will read the content you suggest in your response. thanks again for sharing your knowledge.
Duvien, 01 Mar 2021 - 7:24pm
I don't recall mentioning that composer can _only_ be used locally? if i did, i apologise. You can use it on live site if you prefer but you need at least 2gb RAM to run efficiently (so it did work with 1gb RAM but you may experience timeout issues). When i use Git to version control, there are certain directories i tell git to ignore. These ignored directories are ones i manually upload via SFTP. I think that was i meant.
thierry (not verified), 01 Mar 2021 - 8:59pm
hi, sorry my english was confusing whilst yours was not. just for me i recap the point discussed.

- my vps offer is only 1 gb of ram so as you said composer is not the way to go.
-however since drupal pretty much "obliges" to use composer nowdays, I can do it on my local computer and once i 'am happy with my site i can upload the structure to my vps server (or not vps).
- the advantage beside higher performance of a vps will be to manage the domain direction to the drupal WEB home folder easily.
regards
B (not verified), 13 Jan 2022 - 1:38pm
It might be worth clarifying given the title that while yes it is possible it seems that for some hosts it is (still) not possible to install Drupal 9 on a shared hosting as their offer does not meet the minimum db requirements.

I have a D7 site which i have been unable to migrate to D8 so decided to start fresh on D9. The site is for an NGO with next to no budget (hosting costs come partly from my own pocket already). We have to use Drupal to access a very specific 3rd party module, so options are limited.

Our current host (fasthosts) have a woefully ancient version of MySQL and wont offer an alternative so i tried Bluehost (it being recommended by Drupal). However, on attempting to do an install i discovered the Bluehost also lacks the required version (D9 installs with errors), Bluehosts answer was that i should pay for a dedicated server. I have contacted A2 (noting you mention them above) to see what version they offer on their shared platform.

In any case, installing D9 on a shared platform is not limited to the lack of composer as an option (i've never used it). Minimum DB spec seems (in my limited experience) to be the main hurdle for us in the cheap seats!
The content of this field is kept private and will not be shown publicly.
Your email address will be kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.