Get started with Laravel
Overview
The Laravel framework is installed in the frameworks/laravel directory in the installation directory. This directory includes an example application. Application configuration files are in the conf/ directory and public files, such as HTML pages, CSS and JavaScript files, images and other media assets are stored in the public/ directory.
Activation and Testing
To enable the example application, edit the Apache configuration file at installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf and uncomment the following line
Include "installdir/frameworks/laravel/conf/httpd-prefix.conf"
Then, restart the Apache server.
$ sudo installdir/ctlscript.sh restart apache
You can now verify that the example application is working by visiting its URL using your browser at http://localhost/laravel.
Here is an example of what you might see (Laravel 4.x):
Here is an example of what you might see (Laravel 5.x):
Configuration
Before using the example application, here are a few important points to consider:
To start a new project, edit the file at installdir/frameworks/laravel/app/routes.php (Laravel 4.x) or installdir/frameworks/laravel/app/Http/routes.php (Laravel 5.x) and add a new route:
Route::get('my-first-route', function() { return 'Hello World!'; });
This will create the application route /my-first-route. To see this route in action, append this route to the application URL and visit it in your browser, such as http://localhost/laravel/index.php/my-first-route. If all is working correctly, you will see the output “Hello World!”.
If your application will use a database, edit the database settings in the app/config/database.php (Laravel 4.x) or config/database.php (Laravel 5.x) file.
return array( 'connections' => array( 'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'database_name', 'username' => 'user', 'password' => 'pass', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ), ) );
MySQL support is already available by default. If you plan to use PostgreSQL, enable the php_pdo_pgsql extension in the installdir/php/etc/php.ini file.
extension=php_pdo_pgsql
To move the Laravel application such that it is available at the root URL of the server (without the /laravel URL suffix), follow these steps:
Edit the installdir/frameworks/laravel/conf/httpd-prefix.conf file so that it looks like this:
DocumentRoot "installdir/frameworks/laravel/public" #Alias /laravel/ "installdir/frameworks/laravel/public/" #Alias /laravel "installdir/frameworks/laravel/public" Include "installdir/frameworks/laravel/conf/httpd-app.conf"
Edit the installdir/frameworks/laravel/conf/httpd-app.conf file and replace the AllowOverride None directive with the AllowOverride All directive:
AllowOverride All
Restart the Apache server:
$ sudo installdir/ctlscript.sh restart apache
You should now be able to access the example application at the root URL of your server.
Key Regeneration
A random key of 32 characters is generated during the installation. You can change it later to another random key.
$ cd installdir/frameworks/laravel
$ sudo php artisan key:generate
These commands will generate a new key and print it in the terminal. Copy the 32-character key and then edit the installdir/frameworks/laravel/config/app.php file. You should see a line like this:
'key' => env('APP_KEY', 'PasteYourKeyHere')
Just paste your generated key and save the file.
Upgrading to Laravel 5.1
Follow the steps below to upgrade to Laravel 5.1:
Remove the composer.lock file in the installdir/frameworks/laravel directory:
$ rm installdir/frameworks/laravel/composer.lock
Update composer.json with the latest version:
... "laravel/framework": "5.1.*"
Create a cache/ directory under installdir/frameworks/laravel/bootstrap/:
$ mkdir -p installdir/frameworks/laravel/bootstrap/cache/
Edit the $compiledPath variable in the installdir/frameworks/laravel/bootstrap/autoload.php file as below:
$compiledPath = __DIR__.'/cache/compiled.php';
Create the file installdir/frameworks/laravel/bootstrap/cache/.gitignore with this content:
!.gitignore
Set bitnami as the owner and give writable permission to installdir/frameworks/laravel/bootstrap/cache:
$ sudo chmod 775 installdir/frameworks/laravel/bootstrap/cache $ sudo chown bitnami:root installdir/frameworks/laravel/bootstrap/cache
Add Illuminate\Broadcasting\BroadcastServiceProvider to the providers array in the installdir/frameworks/laravel/config/app.php file:
... 'Illuminate\Broadcasting\BroadcastServiceProvider', ...
Note the comma (,) at the end of the line.
Modify the installdir/frameworks/laravel/app/Http/Controllers/Auth/AuthController.php header from
use App\Http\Controllers\Controller; use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\Registrar; use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
to
use App\User; use Validator; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
Modify installdir/frameworks/laravel/app/Http/Controllers/Auth/AuthController.php constructor from
/** * Create a new authentication controller instance. * * @param \Illuminate\Contracts\Auth\Guard $auth * @param \Illuminate\Contracts\Auth\Registrar $registrar * @return void */ public function __construct(Guard $auth, Registrar $registrar) { $this->auth = $auth; $this->registrar = $registrar; $this->middleware('guest', ['except' => 'getLogout']); }
to
/** * Create a new authentication controller instance. * * @return void */ public function __construct() { $this->middleware('guest', ['except' => 'getLogout']); }
Add in the same file just after the method above:
/** * Get a validator for an incoming registration request. * * @param array $data * @return \Illuminate\Contracts\Validation\Validator */ protected function validator(array $data) { return Validator::make($data, [ 'name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|confirmed|min:6', ]); } /** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { return User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), ]); }
Remove the installdir/frameworks/laravel/app/Services directory.
$ rm -rf installdir/frameworks/laravel/app/Services
Modify the installdir/frameworks/laravel/app/Http/Controllers/Auth/PasswordController.php file from
/** * Create a new password controller instance. public function __construct(Guard $auth, PasswordBroker $passwords) { $this->auth = $auth; $this->passwords = $passwords; $this->middleware('guest'); }
to
/** * Create a new password controller instance. * * @return void */ public function __construct() { $this->middleware('guest'); }
Modify the installdir/frameworks/laravel/app/Http/routes.php file from
Route::get('/', 'WelcomeController@index'); Route::get('home', 'HomeController@index'); Route::controllers([ 'auth' => 'Auth\AuthController', 'password' => 'Auth\PasswordController', ]);
to
Route::get('/', function () { return view('welcome'); });
Remove the installdir/frameworks/laravel/vendor directory:
$ rm -rf installdir/frameworks/laravel/vendor
Include the baseUrl class variable in the installdir/frameworks/laravel/tests/TestCase.php file:
class TestCase extends Illuminate\Foundation\Testing\TestCase { /** * The base URL to use while testing the application. * * @var string */ protected $baseUrl = 'http://localhost'; ...
Delete the installdir/frameworks/laravel/storage/framework/compiled.php file:
$ sudo rm installdir/frameworks/laravel/storage/framework/compiled.php
Run composer update in the installdir/framework/laravel directory:
$ composer update
Check the version of Laravel:
$ php artisan --version
You can also make these optional changes if you wish.
More Information
Learn more about developing applications with Laravel at http://laravel.com/docs/.