minte9
LearnRemember / PHP





Create Project

Use composer to create sample project.
 
composer create-project laravel/laravel myproject
Activate php extension in php.ini
 
;extension=fileinfo
Install dependencies.
 
composer install
Create Apache alias in httpd-vhost.conf
 
Alias /ci4    "D:/myportal-ci4"
Alias /lrv    "D:/myportal-lrv/public"
Check the page url.
 
https://myportal-uat.apps.brd.ro/lrv/public/

Encryption key

Create encryption key (see links).
 
php artisan key:generate

.env
    APP_KEY=base64:xxxxxxxx
    APP_PREVIOUS_KEYS=base64:yyyyyyy

php artisan config:clear
php artisan cache:clear

php artisan encrypt:password mypassword

.env
    DB_PASSWORD_ENCRYPTED=zzzzzzzzzzzzzzzzz

Database

Update the .env File. Comment default connection (it will be set in config/database.php)
 
#DB_CONNECTION=oracle
#DB_HOST=MY01t-ora.db.brd.ro
#DB_PORT=2482
#DB_DATABASE=MYDB.exa.cloud.brd.ro
#DB_USERNAME=gw
#DB_PASSWORD=
Update the config/database.php file:
 
'default' => env('DB_CONNECTION', 'ktp_test'),

'connections' => [

    'ktp_test' => [
        'driver'         => 'oracle',
        'tns'            => env('DB_TNS', ''),
        'host'           => env('DB_HOST', 'MY-ora.db.MYDOMAIN.ro'),
        'port'           => env('DB_PORT', '2482'),
        'database'       => env('DB_DATABASE', 'MY.exa.cloud.brd.ro'),            *- TO DO - encryption
        'username'       => env('DB_USERNAME', 'gw'),
        'password'       => env('DB_PASSWORD', ''),
        'charset'        => env('DB_CHARSET', 'AL32UTF8'),
        'prefix'         => env('DB_PREFIX', ''),
        'prefix_schema'  => env('DB_SCHEMA_PREFIX', ''),
        'edition'        => env('DB_EDITION', 'ora$base'),
        'server_version' => env('DB_SERVER_VERSION', '11g'),
    ],
Install the Oracle Package:
 
composer require yajra/laravel-oci8
Restart apache and clear the configuration cache.
 
php artisan config:cache

Session

 
#config/session.php
    'driver' => env('SESSION_DRIVER', 'file'),

#AuthSessionMiddleware.php
#MiddlewareServiceProvider.php
#bootstrap/providers.php

IAM

File to use for user access.
 
Helpers/auth_helper.php
Models/AuthModel.php
Config/Permisssions.php
Load balance
 
'mydb_test' => [
    'driver'         => 'oracle',
    'tns' => "(DESCRIPTION =
        (ENABLE=BROKEN)
        (LOAD_BALANCE = ON)
        (ADDRESS_LIST =
            (ADDRESS = (PROTOCOL = TCP)(HOST = my01-ora.db.MYDOMAIN.ro)(PORT = 2482))
            (ADDRESS = (PROTOCOL = TCP)(HOST = my02-ora.db.MYDOMAIN.ro)(PORT = 2482))
        )
        (CONNECT_DATA =
            (SERVICE_NAME = MY.exa.cloud.MYDOMAIN.ro) (SERVER = dedicated)
        )
    )",
    'database'       => env('DB_DATABASE', 'MY.exa.cloud.MYDOMAIN.ro'),
    ...

Encrypt password

Create console command: routes/console.php
 
<?php

    use Illuminate\Foundation\Inspiring;
    use Illuminate\Support\Facades\Artisan;
    use App\Services\DatabaseSecurity;

    Artisan::command('encrypt:password {password}', function ($password) {
        $encryptedPassword = DatabaseSecurity::encryptPassword($password);
        $this->info($encryptedPassword);
    })->purpose('Encrypt a password for database configuration');
Check command lists: php artisan list Check encryption command: php encrypt:password 'my_password' Add encrypted password to .env: DB_PASSWORD_ENCRYPTED=eyJpdiI... Comment in config/datase.php 'password' => "", //DatabaseSecurity::decryptPassword(env('DB_PASSWORD_ENCRYPTED')), DatabaseSecurity encrypt/decrypt class:
 
<?php

    namespace App\Services;

    use Illuminate\Support\Facades\Crypt;
    use Illuminate\Support\Facades\Log;

    class DatabaseSecurity
    {
        public static function encryptPassword(string $password): string
        {
            return Crypt::encryptString($password);
        }

        public static function decryptPassword(string $encryptedPassword): string
        {
            Crypt::decryptString($encryptedPassword);
        }
    }

Provider

 
<?php

    namespace App\Providers;

    use Illuminate\Support\Facades\Config;
    use Illuminate\Support\ServiceProvider;

    use App\Services\DatabaseSecurity;

    class DatabaseSecurityServiceProvider extends ServiceProvider
    {
        public function register(): void
        {
            //
        }

        public function boot(): void
        {
            if (env('DB_PASSWORD_ENCRYPTED')) {
                $decryptedPassword = DatabaseSecurity::decryptPassword(env('DB_PASSWORD_ENCRYPTED'));

                $default = config('database.default');
                config(["database.connections.$default.password" => $decryptedPassword]);
            }
        }
    }
Register provider -> Bootsrap\providers.php
 
<?php

    return [
        App\Providers\AppServiceProvider::class,
        App\Providers\MiddlewareAppServiceProvider::class,

        // added
        App\Providers\DatabaseSecurityServiceProvider::class,
    ];

IAM - API

Create project composer create-project laravel/laravel iam-api Vhost Alias /iam "D:/portalppf.apps.brd.ro-iam/public" Route web.php Route::get('/', function () { return view('index'); }); JWT Auth Package composer require tymon/jwt-auth Publish config and generate secret php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider" php artisan jwt:secret Copying file [D:\portalppf.apps.brd.ro-iam\vendor\tymon\jwt-auth\config\config.php] to [D:\portalppf.apps.brd.ro-iam\config\jwt.php] DONE .env JWT_SECRET=xxxxxx Set Up User Model for JWT App\Models\UserModer Upgrade Auth Guard in config/auth.php 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'jwt', 'provider' => 'users', ], ], Create auth controller php artisan make:controller AuthController Set Up Routes routes/api.php Test with curl cd D:\curl-7.70.0-win32-mingw\bin curl -X POST https://localhost/iam/login -H "Content-Type: application.json" -d "{\"email\":\"test@example.com\", \"password\":\"password\"}" bypass certificate check (-k) curl -k -X POST https://localhost/iam/login -H "Content-Type: application.json" -d "{\"email\":\"test@example.com\", \"password\":\"password\"}" Hardcoded credentials in controller error: curl -k -X POST https://localhost/iam/login -H "Content-Type: application.json" -d "{'email':'test@example.com', 'password':'123'}" not working curl -k -X POST https://localhost/iam/login -H "Content-Type: application.json" -d "{'email':'test@example.com', 'password':'password'}" curl -k -X GET https://myportal-uat.apps.brd.ro/iam/ -H "Content-Type: text/html" requires AD user Test from browser: public/test-login.html RouteServiceProvider (because /iam root is different than the default api). php artisan make:provider RouteServiceProvider Debugbar composer require barryvdh/laravel-debugbar --dev #composer remove barryvdh/laravel-debugbar php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider" Publishing in Laravel refers to the process of copying configuration files, assets, and other resources from a package to your application directories. This allows you to customize and manage these resources independently of the package. Documentation composer require darkaonline/l5-swagger composer require zircote/swagger-php on prod: composer install --no-dev --optimize-autoloader publish the configuration: php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider" Generate: php artisan l5-swagger:generate


  Last update: 17 days ago

References and applications: