Skip to content

Instantly share code, notes, and snippets.

@eriktailor
Created September 30, 2023 06:48
Show Gist options
  • Save eriktailor/4e19996fb6e4a9deb05b2156c05cb159 to your computer and use it in GitHub Desktop.
Save eriktailor/4e19996fb6e4a9deb05b2156c05cb159 to your computer and use it in GitHub Desktop.
Install Laravel bash script
#!/bin/bash
# Asks for the name of the project folder
echo "Mi legyen a projekt neve?"
read project_name
# Asks for the name of the new database
echo "Mi legyen az adatbázis neve?"
read database_name
# Create a new database
mysql -uroot -pfelix -h 127.0.0.1 <<EOF
CREATE DATABASE IF NOT EXISTS $database_name;
EOF
# Go into the github folder
cd /Users/eriktailor/Documents/GitHub
# Install latest Laravel & basics
composer create-project laravel/laravel $project_name
# Go into the project root
cd $project_name
# Install Laravel basics (eg. auth)
composer require laravel/ui --dev
composer install && composer update
php artisan ui bootstrap --auth
npm install
# Define the database details
database_user="root"
database_password="felix"
# Rewrite the database details in the .env file
cat .env
sed -i '' -E "s/^(DB_DATABASE=).*/\1$database_name/; s/^(DB_USERNAME=).*/\1$database_user/; s/^(DB_PASSWORD=).*/\1$database_password/" .env
# Add the MAMP mysql sockets in the .env file
echo "UNIX_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock" >> .env
echo "DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock" >> .env
# Run the Laravel migrations
php artisan migrate
# Create webpack.mix.js file
touch webpack.mix.js
# Add content for the webpack.mix.js file
echo "const mix = require('laravel-mix');
mix
.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');" > webpack.mix.js
# Delete the app.blade.php file
rm resources/views/layouts/app.blade.php
# Create new app.blade.php file
touch resources/views/layouts/app.blade.php
# Add content in the app.blade.php file
echo '<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<!-- Metas -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>@yield('title')</title>
<!-- Stylesheet -->
<link rel="stylesheet" href="/css/app.css">
</head>
<body>
@yield('content')
<!-- Scripts -->
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<script src="/js/app.js"></script>
</body>
</html>' > resources/views/layouts/app.blade.php
# Delete the package.json file
rm package.json
# Create new package.json file
touch package.json
# Add content into the new package.json file
echo "{
\"scripts\": {
\"dev\": \"npm run development\",
\"development\": \"mix\",
\"watch\": \"mix watch\",
\"watch-poll\": \"mix watch -- --watch-options-poll=1000\",
\"hot\": \"mix watch --hot\",
\"prod\": \"npm run production\",
\"production\": \"mix --production\"
},
\"devDependencies\": {
\"@popperjs/core\": \"^2.11.6\",
\"axios\": \"^1.1.2\",
\"bootstrap\": \"^5.2.3\",
\"laravel-mix\": \"^6.0.49\",
\"sass\": \"^1.56.1\",
\"sass-loader\": \"^12.6.0\"
},
\"dependencies\": {
\"autoprefixer\": \"10.4.5\"
}
}" > package.json
# Install & update npm
npm install && npm update
# Create git repository
git init
# Create a Laravel specific .gitignore file
touch .gitignore
echo "/.phpunit.cache
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.env.production
.phpunit.result.cache
Homestead.json
Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
/.fleet
/.idea
/.vscode" > .gitignore
# Add files to the repo and do the first commit
git add .
git commit -m "Initial commit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment