Diasumsikan Anda telah menginstall Composer.
Jalankan perintah berikut di command prompt.
composer create-project --prefer-dist yiisoft/yii2-app-basic nama-folder-proyek
Diasumsikan Anda telah menginstall Composer.
Jalankan perintah berikut di command prompt.
composer create-project --prefer-dist yiisoft/yii2-app-basic nama-folder-proyek
Pengaturan Default
<?php
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'xZXoudqmnLK0Y1l9WQPD2Ss6qkUsRMJ4',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => \yii\symfonymailer\Mailer::class,
'viewPath' => '@app/mail',
// send all mails to a file by default.
'useFileTransport' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
/*
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
*/
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
}
return $config;
<?php$params = require __DIR__ . '/params.php';$db = require __DIR__ . '/db.php';$config = ['id' => 'basic','name' => 'e-CBT ','language' => 'id','basePath' => dirname(__DIR__),'bootstrap' => ['log', 'app\components\Aliases'],'aliases' => ['@bower' => '@vendor/bower-asset','@npm' => '@vendor/npm-asset',],'timeZone' => 'Asia/Jakarta','components' => ['request' => [// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation'cookieValidationKey' => 'BXZKejBQ1ZXCo0zAo5I5d9nmYzLdvuov',],'cache' => ['class' => 'yii\caching\FileCache',],'webUser' => ['class' => 'app\components\webUser',],'user' => ['identityClass' => 'app\models\User','enableAutoLogin' => true,],'errorHandler' => ['errorAction' => 'site/error',],'mailer' => ['class' => 'yii\swiftmailer\Mailer',// send all mails to a file by default. You have to set// 'useFileTransport' to false and configure a transport// for the mailer to send real emails.'useFileTransport' => true,],'log' => ['traceLevel' => YII_DEBUG ? 3 : 0,'targets' => [['class' => 'yii\log\FileTarget','levels' => ['error', 'warning'],],],],'db' => $db,'urlManager' => ['enablePrettyUrl' => true,'showScriptName' => false,'rules' => ['<controller:\w+>/<id:\d+>'=>'<controller>/view','<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>','<controller:\w+>/<action:\w+>'=>'<controller>/<action>',],],],'params' => $params,];if (YII_ENV_DEV) {// configuration adjustments for 'dev' environment/* $config['bootstrap'][] = 'debug';$config['modules']['debug'] = ['class' => 'yii\debug\Module',// uncomment the following to add your IP if you are not connecting from localhost.//'allowedIPs' => ['127.0.0.1', '::1'],];*/$config['bootstrap'][] = 'gii';$config['modules']['gii'] = ['class' => 'yii\gii\Module',// uncomment the following to add your IP if you are not connecting from localhost.//'allowedIPs' => ['127.0.0.1', '::1'],];}return $config;
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ web/$1 [L]
</IfModule>
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
Semua aset baik berupa CSS, JavaScript, atau Gambar ditempatkan di folder public<link href="{{ aset('css/min.css') }}" rel="stylesheet"><script src="{{ aset('use.typekit.net/zjb5wvv.js') }}" ></script><img alt="logo" src="{{ aset('gambar/logo.png') }}">
route::get('/salam',function(){return "Assalamu'alaikum...";});
Route::redirect('/from', '/to');
Route::view('/selamat_datang', 'welcome'); Route::view('/selamat_datang', 'welcome',['nama'=>'Jhon Thor']);
1. Buat folder baru, kita namakan mesin2. Masukkan seluruh folder dan file ke dalam folder mesin, kecuali folder public
3. Keluarkan file .htaccess dan index.php dari folder public seperti gambar di bawah ini.
4. Buka file index.php dengan editor text (Notepad++, CodeLobster, Visual Studio, dll)
5. Replace /../ dengan /mesin/ kemudian simpan
6. Selanjutnya buka file helpers.php di direktori ...\mesin\vendor\laravel\framework\src\Illuminate\Foundation
7. Cari return app('url')->asset($path, $secure); pada file helpers.php ganti dengan return app('url')->asset("public/".$path, $secure); lalu simpan
8. Selanjutnya akses alamat http://localhost:6363/belajar_laravel/laravel/
Untuk memasang Laravel di PC/Laptop kita, ada beberapa cara, di antaranya:
1. dengan mengunduh paket Laravel di github
2. dengan menggunakan Composer
Pada kesempatan ini, kita akan menggunakan cara kedua, yaitu menggunakan Composer. Mari kita eksekusi.
Pertama-tama kita unduh dan install Composer.
1. Buat folder tempat installasi Laravel 2. Misalkan kita buat folder belajar_laravel di drive C3. Kita blok direktorinya seperti gambar di bawah ini, lalu ketik cmd dan tekan enter
4. Muncul kotak dialog Command Prompt
5. Selanjutnya, buka tautan https://getcomposer.org/download/ 6. Di laman tersebut cari kode berikut (lihat gambar), salin (copy), lalu tempelkan (paste) di kotak dialog Command Prompt selanjutnya tekan enter
1. Buka laman https://laravel.com/docs/8.x, lalu cari topik Installation Via Composer 2. Di laman tersebut, cari kode berikut composer create-project laravel/laravel:^8.0 example-app tempel di Command Prompt, lalu ganti example-app dengan nama laravel (tempat paket Laravel) composer create-project laravel/laravel:^8.0 laravel tekan enter3. Tunggu hingga proses installasi selesai
5. Selanjut ketik cd laravel di Command Prompt, lalu tekan enter 6. Ketika php artisan serve di Command Prompt, lalu tekan enter7. Buka browser (Chrome, dll), lalu salin http://127.0.0.1:8000 ke address bar, tekan enter
1. composer create-project --prefer-dist laravel/laravel:^7.0 belajar 2. composer require laravel/ui:^2.4 3. php artisan ui vue --auth 4. Untuk node JS menggunakan versi 14, https://nodejs.org/en/blog/release/v14.21.1 5. npm install && npm run dev 6. masukkan nama db di file .env 7. php artisan migrate Untuk library tambahan: 1. composer require realrashid/sweet-alert php artisan sweetalert:publish (Sumber : https://realrashid.github.io/sweet-alert/) 2. composer require maatwebsite/excel php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" 3. composer require intervention/image
4. composer require barryvdh/laravel-dompdf php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider" Catatan: php yang Koe gunakan PHP 7.4.6