Prerequisites:
- your mysql DB setup and your schema installed (or use artisan), the mysql user you are going to put in your .env file must have be granted relevant permissions on the relevant database.
- php >= 5.6 for apache
- This will depend on your hosting. for my hosting, I had to add this line to the root .htaccess file: “AddType x-httpd-php56 .php”
- php >= 5.6 for command line
- When you SSH to your server (e.g. using kitty or putty), see what version you have:
$ bash-3.2$ php -v PHP 5.6.22 (cli) (built: Jun 9 2016 18:53:49)
- If the answer is not 5.6 or higher, contact your server hosting provider and ask them how to change the default. For mine, I edited my root .bashrc and added the following line:
alias php=/usr/bin/php-5.6
- Composer
- This one is a bit o a mystery. There are conflicting instructions. The official website suggest running the following at the command line:
-
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"
- the result is a composer.phar file. However, the instructions to run it universally are like this: “# composer xxx” which will not work. I chose to add the following line to my .bashrc file:
alias composer=/pathtomydir/composer.phar
- However, running “# composer xxx” results in the following warning:
Warning: Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI
- To solve this, I found the cli version, and changed the alias to this:
alias composer="/usr/bin/php-5.6-cli ~/composer.phar"
- When you SSH to your server (e.g. using kitty or putty), see what version you have:
Deployment:
- get the project onto a server. E.g.
- ssh myserver.com
- mkdir versions
- cd versions
- git clone –depth 1 https://someone@app.deveo.com/SomeProject
- Now you should have the following dirs:
- www (or public_html or similar)
- versions
- copy the public dir to your www root (including dot files) = don’t use *):
- cd www
- cp -r ../versions/SomeProject/. .
- Modify www/index.php (not Public/index.php)
Install dependencies.
- cd yourprojectdir
- run “composer install”
- This will download a bunch of files.
- Unfortunately for me, at the end I got this:
Generating autoload files > Illuminate\Foundation\ComposerScripts::postInstall > php artisan optimize Content-type: text/html <br /> <b>Parse error</b>: syntax error, unexpected 'class' (T_CLASS), expecting ident ifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in <b>/var/sites/d/dev.g amificationgiant.com/public_html/versions/platform-new/artisan</b> on line <b>30 </b><br /> Script php artisan optimize handling the post-install-cmd event returned with er ror code 255
The problem seems to be that composer is spawning a new shell which gets the default php which is 5.4, and there is nothing I can do about this. Dead end for our hosting provider.
The solution is the following:
- $ cd
- $ mkdir bin
- $ ln -s /usr/bin/php-5.6 ~/bin/php
- edit .bashrc to have the following two lines:
alias composer="/usr/bin/php-5.6-cli ~/composer.phar" export PATH=/var/sites/g/gamificationgiant.com/bin:$PATH
Now you can install dependencies:
- $ composer install
- $ composer dumpautoload -o
- $ php artisan route:cache
The last item will give the following error:
Unable to prepare route [api/user] for serialization. Uses Closure.
setup environment
- cd to the root of your app
- $ cp .env.example .env
- edit .env with your database details etc.
- $ php artisan key:generate
- Do this only if you dont want to use an existing key in your .env
- $ php artisan config:cache
- This has to be done after adding the key to .env.
Hopefully now your app will be working.
Trouble shooting
Cipher issues
If you see this in your “storage/logs/laravel.log” file:
'The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.' in /var/sites/d/dev.gamificationgiant.com/public_html/versions/platform-new/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:43 Stack trace: #0 /var/sites/d/dev.xxxxx.com/public_html/versions/platform-new/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php(27): Illuminate\Encryption\Encrypter->__construct(NULL, 'AES-256-CBC')
Then check the following:
- a valid cipher is set in .env APP_KEY
- you have run “php artisan config:cache” AFTER setting the key.