Created
September 26, 2022 10:46
-
-
Save dev/6bc1747a8ecd70cbb9d9da02c5f19624 to your computer and use it in GitHub Desktop.
Create Laravel project and MySQL Database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#=============================================================================== | |
# Description: This script will create a new laravel project along with a new MySQL database. | |
# Author: Kenny Hietbrink | |
# Github: @dev | |
#=============================================================================== | |
readonly DOMAIN_EXTENSION="dev" | |
readonly MYSQL_USER="root" | |
readonly MYSQL_PASSWORD="" | |
readonly PROJECT_PATH="$HOME/Sites" | |
cd $PROJECT_PATH | |
read -p "Enter the name of the project: " project | |
read -p "Enter the name of the database: " database | |
echo "Creating project $project.$DOMAIN_EXTENSION" | |
composer create-project laravel/laravel $project | |
cd $project | |
echo "Creating database $database" | |
#create utf8mb4 database | |
# do not use -p if password is empty | |
if [ -z "$MYSQL_PASSWORD" ]; then | |
mysql -u $MYSQL_USER -e "CREATE DATABASE IF NOT EXISTS $database CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" | |
else | |
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -e "CREATE DATABASE IF NOT EXISTS $database CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" | |
fi | |
echo "Updating .env file" | |
sed -i '' "s/DB_DATABASE=laravel/DB_DATABASE=$database/g" .env | |
sed -i '' "s/DB_USERNAME=root/DB_USERNAME=$MYSQL_USER/g" .env | |
sed -i '' "s/DB_PASSWORD=/DB_PASSWORD=$MYSQL_PASSWORD/g" .env | |
sed -i '' "s/APP_URL=http:\/\/localhost/APP_URL=https:\/\/$project.$DOMAIN_EXTENSION/g" .env | |
sed -i '' "s/APP_NAME=Laravel/APP_NAME=$project/g" .env | |
echo "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment