Install Laravel 5.4 on Cloud9 + Bonus Tips

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.

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

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

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

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:

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

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.

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.

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.

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.