If your host has PHP and MySQL, then there is a good chance that they can run Laravel. There are a few other requirements, such as certain PHP extensions, but those are fairly common. The only real issue is Composer. If your host can’t (or won’t) run Composer, then forget about it. 🙁

But if they can, then most likely you can install Laravel. 🙂

If they have Composer already installed, then you’re all set. If not, then you must install yourself, but it’s not too hard. The directions on the Composer Download page are great and they work on many machines. For shared hosting, however, you probably will need to make some small changes.

If you’re using CiviHosting, we of course install Composer for you, but here is the code we use to do it and you can use those on other hosts. It’s from the GetComposer site:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

To get the command composer to work (instead of php ~/private/composer.phar) use this:

echo "alias composer='php71.cli ~/private/composer.phar'" >> ~/.bashrc

Now to install Laravel, we just use Composer, by first downloading Laravel:

composer global require "laravel/installer"

and then making a new Laravel installation with this command:

laravel new blog

But that only works if have you have an alias to the laravel executable, which you may not have. At CiviHosting, we don’t have (nor need) that. And even if you do, then there is the pesky sh: composer: command not found problem that doesn’t always have a solution. 🙁

Therefore the simplest way is to install Laravel via the Composer create-project command:

composer create-project --prefer-dist laravel/laravel blog

What this does is creates a new Laravel install in a subdirectory called blog. Yes, that’s kind of a silly example but that’s the one used online so we just copied it. In practice, you might want to use this:

composer create-project --prefer-dist laravel/laravel .

which installs Laravel in the current directory.

What this does is give you a set of files and directories:

$ ls -l
total 192
drwxr-xr-x  6 civihosting civihosting   4096 May 11 08:42 app
-rwxr-xr-x  1 civihosting civihosting   1646 May 11 08:42 artisan
drwxr-xr-x  3 civihosting civihosting   4096 May 11 08:42 bootstrap
-rw-r--r--  1 civihosting civihosting   1300 May 11 08:42 composer.json
-rw-r--r--  1 civihosting civihosting 122432 Jul 18 11:52 composer.lock
drwxr-xr-x  2 civihosting civihosting   4096 May 11 08:42 config
drwxr-xr-x  5 civihosting civihosting   4096 May 11 08:42 database
-rw-r--r--  1 civihosting civihosting   1062 May 11 08:42 package.json
-rw-r--r--  1 civihosting civihosting   1055 May 11 08:42 phpunit.xml
drwxr-xr-x  4 civihosting civihosting   4096 May 11 08:42 public
-rw-r--r--  1 civihosting civihosting   3420 May 11 08:42 readme.md
drwxr-xr-x  5 civihosting civihosting   4096 May 11 08:42 resources
drwxr-xr-x  2 civihosting civihosting   4096 May 11 08:42 routes
-rw-r--r--  1 civihosting civihosting    563 May 11 08:42 server.php
drwxr-xr-x  5 civihosting civihosting   4096 May 11 08:42 storage
drwxr-xr-x  4 civihosting civihosting   4096 May 11 08:42 tests
drwxr-xr-x 31 civihosting civihosting   4096 Jul 18 11:52 vendor
-rw-r--r--  1 civihosting civihosting    555 May 11 08:42 webpack.mix.js

which is great, but if this is your document root (meaning the directory that is the “home” directory of your site) then you’ve got a problem, because the real document root of Laravel must be the public directory there. We we must change our document root to that directory.

Each host has a different way of allowing you to do that. On CiviHosting’s Control Panel, there is a tab called Document Roots. Click on that. Then find the URL you want to change and click the Change button.

On the next page you will see that you can either type in the directory you want, or you can click the little directory icon to get a popup window with a list of directories you can click on. Just click on the public directory and then click Select and then click Update.

That’s it. Your Laravel site is now ready. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *