How to use Composer on 000webhost

Almost! Except we won’t use composer directly on 000webhost.

Composer requires SSH access. In other words, the ability to connect to a server using ssh username@hostname and run commands on the remote server.
SSH is unfortunately not supported on 000webhost due to the potential abuse that can be derived from it (SSH is, on the other hand, available on our premium plans - grab one now here!).

So, were you lying to us?

No, not really. While it is true that we cannot use composer on 000webhost, nothing stops us from using this essential tool on our local computer (just like nothing’s stopping you from learning Laravel, a powerful PHP Framework that simplifies your development :wink: )
Anyway, back to the main subject. To get started, you will first need to install composer (preferably version 2 at the time of writing) on your local machine (this assumes you already have PHP installed on your machine).
The installation is quite straightforward, but if you like being held in the hand and guided, here’s a how-to for the most common computer operating systems:

Windows

Before I show you the Windows installation steps, please note that using Ubuntu or any other Linux distribution for PHP development is recommended. You can develop on Linux while booted into Windows by using WSL2
If you don’t want to use WSL2:

Linux
  • Open your terminal
  • Copy and paste the following code which can be found on this page, Command-line installation section
  • Run the following command to make the composer command available globally:
sudo mv composer.phar /usr/local/bin/composer

Perfect! You have successfully installed composer on your local machine!

Sounds great, is that all?

Not quite. Now that you have composer installed on your computer, use it like you normally would to install PHP packages.

Before we continue, quick note

If you’re not developing locally then uploading to 000webhost once you’re done, I strongly recommend starting to do so - developing directly via the 000webhost File Manager and/or via FTP is a terrible practice. Here are some cons to not developing locally:

  • Waste of bandwidth
  • Inability to develop offline
  • Using an IDE with FTP is too slow

So please, if you’re still developing locally, stop right here and spin up a local environment (we’ll probably release a tutorial for that later on, you’re on your own for the moment).
While on that subject, make use of git, it might be difficult at first, but it will extremely help you later on (especially when you move to premium hosting/VPS hosting as your project grows).

Alright, I’ve installed my composer packages

Phenomenal! It’s time to zip all your local files (including the vendor directory) and throw them onto your 000webhost website (via FTP or the File Manager) while making sure to delete the old files (unless you’ve figured out a way to use git on 000webhost, if so then kudos to you! You can skip this step). Once you’re done, unzip the file (directly from the File Manager by right clicking the ZIP file, or by using the PHP Unzipper script).

Are we finally done?

Yes. Please note however that this solution is far from perfect. Some composer packages might not work on 000webhost since we do not enable all PHP features and functions. Since we’re running composer locally then uploading, composer has no way to tell us if the functions our packages need are installed on our shared hosting environment.

2 Likes