Laravel Installer Create Web Application install scripts

Today, We want to share with you Laravel Installer Create Web Application install scripts.In this post we will show you Powerful free Laravel installation wizard script, hear for Learn how to create an Installer of your Laravel Project we will give you demo and example for implement.In this post, we will learn about Laravel Installer Create Laravel application install scripts with an example.

Laravel Installer Create Web Application install scripts

There are the Following The simple About Laravel Installer Create Web Application install scripts Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel desktop application with database, so the some major files and Directory structures for this example is following below.

  • #Update the folder permissions
  • #Install Composer Dependency
  • #Copy .env.example to .env
  • #Update permission for .env
  • #Start the installation process
  • #Install node dependency

Laravel installation wizard script

Step 1: Giving Some Folder Permissions

general permission >> 775

Giving some Permissions for different folders Like ( “bootstrap/cache”, “storage”, “vendor” folder)

sudo chmod -R 775 storage/ bootstrap/cache/ vendor/

Step 2: composer dependency update or install

Installing composer install / composer update dependency

composer install

Step 3: Setting up Copying .env files

Copying .env.example to .env

cp .env.example .env

//update file .env using command
sudo chmod 777 .env

Step 4: Database Migration & Seeding Setting

Configuration Up Database Migrations & Seeding

I shall make a Laravel Artisan Console command

namespace App\Console\Commands;
 
use Illuminate\Console\Command;
use DB;
 
class InstallAppliction extends Command
{
    protected $signature = 'application:install';
 
    protected $description = 'It will installation of the Laravel application & Setting Up Database Migrations & Seeding';
 
    public function __construct()
    {
        parent::__construct();
    }
 
    public function handle()
    {
        $this->line("We can use simple Ctrl+C to exit the Laravel installer any time.\n");
        $this->databaseMake();
        $this->migrate();
        $this->seed();
        $this->setUpKey();
    }
 
    private function databaseMake(){
        if($this->testDbConnection()){
            return;
        }
 
        $this->line("We Some more required to choose a any main database type.");
 
        install_database:
 
        $connection = null;
        $host = null;
        $port = null;
        $database = null;
        $username = null;
        $password = null;
 
        $available_connections = array_keys(config('database.connections'));
        $connection = $this->choice('Select a connection type', $available_connections);
 
        if($connection == "sqlite"){
            $path = database_path('database.sqlite');
            touch($path);
            $this->info('Database file created at ' . $path);
        } else{
            $defaultPort = $connection == "mysql" ? 3306 
                               : ($connection == "pgsql" ? 5432 : null);
 
            $host = $this->ask('Database host', 'localhost');
            $port = $this->ask('Database port', $defaultPort);
            $database = $this->ask('Database name');
            $username = $this->ask('Database username');
            $password = $this->secret('Database password');
        }
 
        $configurations = compact('connection', 'host', 'port', 'database', 'username', 'password');
        $this->customFileUpdateEnvironment($configurations);
 
        if(!$this->testDbConnection()){
            $this->error('Could not connect to database.');
            goto install_database;
        }
    }
 
    private function testDbConnection(){
        $this->line('Checking DB connection.');
 
        try{
            DB::connection(DB::getDefaultConnection())->reconnect();
        }catch(\Exception $e){
            return false;
        }
 
        $this->info('Database connection working.');
        return true;
    }
 
    private function customFileUpdateEnvironment($configurations)
    {
        $env_path = base_path('.env');
        DB::purge(DB::getDefaultConnection());
 
        foreach($configurations as $key => $value){
            $key = 'DB_' . strtoupper($key);
            $line = $value ? ($key . '=' . $value) : $key;
            putenv($line);
            file_put_contents($env_path, preg_replace(
                '/^' . $key . '.*/m',
                $line,
                file_get_contents($env_path)
            ));
        }
 
        config()->offsetSet("database", include(config_path('database.php')));
 
    }
 
    private function migrate(){
        $this->line("\nStarting DB Migration...");
        $this->call('migrate');
    }
 
    private function seed(){
        $this->line("\nStarting DB Seeding...");
        $this->call('db:seed');
    }
 
    private function setUpKey(){
        $this->call('key:generate');
        $this->info("\nLaravel Project installation completed, Good Luck!");
    }
}

This Laravel Application Install file required to be called from the command shell(terminal) script. For this Include the following to the simple Code / script.

php artisan application:install

Step 5 : NPM install

Simpel Last step To Running NPM install

npm install

Creating Installer for Laravel Project

Now, We simple Full In short, the shell (terminal) script will look like the following.

###how to make setup file for Laravel project###
#!/bin/sh

#Giving Some Folder Permissions
sudo chmod -R 775 storage/ bootstrap/cache/ vendor/

# composer dependency update or install
composer install

# Setting up Copying .env files
cp .env.example .env

# Update Simple Laravel Files permission for .env
sudo chmod 777 .env

#Laravel Application Install
php artisan application:install

# NPM install
npm install
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel Installer Create Web Application install scripts.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment