Guide to Laravel 5.4 Workspace Installation

phpmyadmin
mysql
php
laravel
workspace

#1

Install Laravel 5.4 on Cloud9 + Bonus Tips

This is my process for setting up Laravel 5.4 in a Cloud9 workspace.

I also wrote a tutorial for 5.3 if you’re interested: Laravel 5.3 Installation on Cloud9

I had a few errors when installing 5.4 so thought it would be useful to start another topic to help others avoid similar issues, and also have a fresh comment stream related to 5.4 only.

Remove unnecessary files from you workspace

Delete hello-world.php, php.ini and README.md from your workspace - you don’t need them. You can do this in the command line if you prefer:

rm hello-world.php php.ini README.md

Upgrading to PHP 5.6

Firstly, I would like to point out that I have not written instructions for PHP 7 (if you want you can see the 5.3 topic for instructions) because I don’t have the full knowledge to make sure all of the correct packages are installed that are needed to guarantee it will work. Please seek help elsewhere or leave a comment that somebody else may be able to answer in relation to getting PHP 7 set up correctly.

  1. To upgrade to PHP 5.6 you can copy and paste the following code block into the command line (including extra returns for where asked for confirmation):
sudo add-apt-repository ppa:ondrej/php

sudo apt-get update
sudo apt-get install libapache2-mod-php5.6

sudo a2dismod php5
sudo a2enmod php5.6
sudo add-apt-repository ppa:ondrej/php5-compat

sudo apt-get update
sudo apt-get dist-upgrade
Y

Install Laravel

  1. Install composer, add folder containing laravel command to the PATH variable and install a Laravel Project using the following commands:
sudo composer global require 'laravel/installer'
export PATH=~/.composer/vendor/bin:$PATH
laravel new project

  • Move the files and folders from the ‘project’ folder to you workspace folder.
  • Remove the empty ‘project’ folder.

Set the public folder as the root for running your project

  1. Enter the following command to open the cloud9 config file:
sudo nano /etc/apache2/sites-enabled/001-cloud9.conf

and add /public to the end of line 2 e.g.

DocumentRoot /home/ubuntu/workspace/public

Press F2 to exit, then y and return to save.

Set up your database

  1. Run the following commands to make sure your workspace is using the default MySQL database:
mysql-ctl install
mysql-ctl cli
use c9;
exit;
  1. Update your .env file so that Laravel uses the correct database.

Change the database settings in your .env file to look like this:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=c9
DB_USERNAME=your_cloud9_username
DB_PASSWORD=

Note: the username should be your Cloud9 username.

You may also change your .env file to use sqlite as Jeffrey Way often does in lessons on Laracasts. Remember to add a sqlite.database file to your database folder.

I recommend you use MySQL because it is so easy on Cloud9 and is most likely what you will use in production.

You can also install PHPMyAdmin which will be hosted on your c9 domain for access to your database, by entering the following command like so:

phpmyadmin-ctl install

You will see that your username for loggin in is the same as your c9 username and the password is empty (similar to the database). You will also be provided with a link to acces it e.g. c9username-workspacename-c9user.io/phpmyadmin.

Upgrade npm and node

Upgrading to the latest versions of npm and node is necessary for using Laravel Mix (to avoid errors).

  1. Enter the following in the command line to upgrade npm and node:
sudo npm install -g npm
npm install
nvm install 7.5.0
npm rebuild node-sass

Note: when you clone your workspace, the clone may have reverted back to older versions (usually just node). Just enter the command/s again.

Compile css and js assets

  1. Run the following command to compile your assets using Laravel Mix
npm run dev

That’s it! Your Application is ready to run. Kind of…

If you run your application, it should work and you will get the Laravel splash screen. You can now do whatever you want to create your (application) website.

Yes, website. I like to think of an application in the simplest sense as something that remembers what your users do / lets your users save what they have done.

At the moment, your users can’t even sign up to your application. If you want to make it so that your application can have users and remember what they have done, then there are a couple of easy ways to set this up with Laravel. The next section will show you a couple of different ways to do this (depending on what features you want).

Bonus Tips

This section includes a couple of different ways to add user accounts and authentication to your application. I have also added a bonus tutorial based on a personal preference for adding real-time functionality to your application.

Bonus Tip A: Laravel Auth

This is the simplest way to add authentication to your application. Just enter the following in the command line:

php artisan make:auth

If you run your project now, you will see that there are now ‘Login’ and ‘Register’ links on the Laravel welcome screen.

You probably already know what’s comes next, but read on for an important tip.

These won’t work just yet, first we need to run the database migrations using the following command:

php artisan migrate

WAIT! :raised_hand:

If you do this, you probably got the following error:

[Illuminate\Database\QueryException]                                                                                                                              
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_emai  
  l_unique`(`email`))

Don’t worry there’s an easy fix. You just need to do the following:

  • Add the following to the app/Providers/AppServiceProvider boot method:
Schema::defaultStringLength(191);
  • Don’t forget to include the following at the top of the file:
use Illuminate\Support\Facades\Schema;
  • Now you’re safe to run ‘php artisan migrate’

Note: if you ran migrate before updating AppServiceProvider, you will need to manually clear out the tables in your database before you try to do the migrations again, even if you rollback the migrations first it proboably won’t work.

If you managed to run your migrations successfully without any errors -

Yippee! You now have an application with user authentication. Make something awesome!

Bonus Tip B: Authentication scaffolding with Roles and Permissions

Do you want to build an application where users have different roles and permissions? I recently came accross a really cool setup to save you from having to work out how to implement this by yourself.

Centaur

Centaur is ‘an opinionated implementation of Cartalyst’s Sentinel package for Laravel 5’.

It’s already been updated to work with 5.4 . I also made my first contribution on GitHub to the repository to make sure the account activation and password reset emails worked properly. :slight_smile:

Basically it adds user management (for admins) and roles (which you can create and customise) for users. I also like that it gives your app the functionality to add users without them having to register themselves.

Please read the github repository for more info and installation instructions https://github.com/SRLabs/Centaur

Bonus Tip C: Using Firebase (Google)

I recommend using firebase to add real-time features to your app using its Real-Time database, or when you need to store unstructured data. It also has other features including client side authentication, file storage, push messaging and more.

You can use firebase in combination with a basic Laravel installation, or either of the previously mentioned auth installations. I’ll tell you the most basic way to use firebase in your Laravel application, and let you decide whether you use it instead of the standard Laravel authentication and database setup, or mix the two for different purposes as I like to.

Note: it’s not currently possible to use firebase hosting with a Laravel application since there is no way to host/run server side code. This may change in the future.

VueFire

I haven’t mentioned Vue, and I’m not going to talk about it specifically. I recommend you check out the lessons on Laracasts if you don’t already know anything about it. What I am going to show you is VueFire - a NPM package that allows you to easily connect the firebase real-time database to your application.

VueFire is purely for using the firebase database, and not any of the other features. I recommend searching youtube and reading the firebase documentation to learn how the others can be used. (You will want to use firebase authentication in order to protect the data in your firebase database. At the time of writing this, I have not yet tried to implement firebase’s custom authentication that would be required to integrate it with the Laravel auth setup. I will add this when I get round to it.

[to be continued]

Personal Recommendations

  • Use Laravel (or Centaur) authentication and database connection for any structured user related data that a SQL database is ideal for.
  • Use Laravel for greater control over API implementation, when you need to perform complex database queries and build API integrations with other applications.
  • Add firebase for features that demand real-time updates to the user interface e.g. live chat, collaborative note taking; or for unstructured data (since firebase uses a noSQL-like JSON database where the data structure does not need to be explicit).

I’m currently building an app where I use both an SQL database with Laravel (Centaur setup) to manage users and their permissions to view different routes, and a firebase database to store unstructured form submissions from a third party application, where different users will have different form fields in the other application and I need to be able to accept and store any data structure they may have.


How to install Laravel 5.3 to a workspace?
Laravel 5.3 Installation on Cloud9
Getting Started with Laravel
#2

Thanks a lot @prenna for the guide, (almost) works perfectly!

I followed the guide above as well as the 5.3 guide but I couldn’t manage to get breakpoints hitting within my index.php. Any ideas on this? Did you manage to get this working?

Many thanks!


#3

Actually I found the answer – I needed to also update my php-xdebug version as follows:

sudo apt-get install php-xdebug


#4

HI prenna,

thanks for this great post…

I have an issue with npm run dev … i have to run these commands every day in order to work :

sudo npm install -g npm
npm install
nvm install 7.5.0
npm rebuild node-sass

i got the following error every day … once i run the above it worked…

@ dev /home/ubuntu/workspace

cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

/home/ubuntu/workspace/node_modules/laravel-mix/setup/webpack.config.js:1
(function (exports, require, module, __filename, __dirname) { let path = require(‘path’);
^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions…js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at requireConfig (/home/ubuntu/workspace/node_modules/webpack/bin/convert-argv.js:96:18)
at /home/ubuntu/workspace/node_modules/webpack/bin/convert-argv.js:109:17
at Array.forEach (native)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ dev script ‘cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js’.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs
npm ERR! Or if that isn’t available, you can get their info via:
npm ERR! npm owner ls
npm ERR! There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/ubuntu/.npm/_logs/2017-05-09T06_04_10_450Z-debug.log

do you know what is the issue ?

thanks alot


#5

Just need to run this:
nvm install 7.5.0


#6

still no working …


#7

can someone show how can i install more than one laravel project in same workspace?


#8

Hello Dear
Thanks for guide. how to install msyql 5.6 or latest version


#9

NOTICE: You are seeing this message because you have apache2 package installed.

  • Restarting PHP 5.6 FastCGI Process Manager php-fpm5.6 [ OK ]
    Errors were encountered while processing:
    udev
    initramfs-tools
    E: Sub-process /usr/bin/dpkg returned an error code (1)

#10

@prenna I followed your instructions and this is what I got with Laravel 5.4 using PHP 7.1:

Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 444

#11

@prenna - Thanks for writting this up Paul!

I’ve gone through the installation process as you laid out and didn’t run into any errors, but when I go to Preview Running Application, it seems to just show me the raw code of index.php in /public. Is that correct? I thought there was a splash screen or a welcome screen.

I’m running Laravel 5.4.35 and PHP 7.1.8 if that’s helpful.


#13

In case you’re running PHP 7, you might run into a syntax error after installation. I was able to fix this by disabling the PHP5 module in apache itself.

sudo a2dismod php5
sudo service apache2 restart

Apparently, Terminal was running the latest version of PHP7, but apache itself was still trying to run on PHP5 - or at least that’s how I understand it.

Hope this helps anyone!


#14

Just what I needed. Thanks Zach.


#15

I get the raw code, too. Did you manage to fix this, Zach? I’ll keep trying.


#16

Thanks for this tutorial, but when I run sudo a2dismod php5 has this error:
Could not parse /etc/apache2/envvars


#17

maybe this link gist help for install

https://gist.github.com/nakamuraagatha/7defc09f547f9bf0157fdb07b1b9c696


#18

Do you have to run the installer first when you have an exsisting Laravel project uploaded? See I uploaded my project by zip. How do I get my project up and running again?


#19

Can Cloud9 be used with PaaS, like Cloudways? I have Laravel website hosted on managed AWS instance using this platform, since it saves me a lot of time and trouble.