Last active
April 24, 2025 13:10
-
-
Save moaoa/20ff866591e391a60e6aca54affba308 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # Exit immediately if a command exits with a non-zero status | |
| set -e | |
| # Function to display usage instructions | |
| usage() { | |
| echo "Usage: $0 <db_name> <db_user> <db_password>" | |
| exit 1 | |
| } | |
| # Check if the correct number of arguments is provided | |
| # | |
| #if [ "$#" -ne 3 ]; then | |
| # usage | |
| #fi | |
| # Assign command-line arguments to variables | |
| # DB_NAME=$1 | |
| # DB_USER=$2 | |
| # DB_PASS=$3 | |
| # | |
| read -p "Enter the DB name: " DB_NAME | |
| if [ -z "$DB_NAME" ]; then | |
| echo "You didn't enter anything." | |
| fi | |
| read -p "Enter the DB user name: " DB_USER | |
| if [ -z "$DB_USER" ]; then | |
| echo "You didn't enter anything." | |
| fi | |
| read -sp "Enter the DB password: " DB_PASS | |
| if [ -z "$DB_PASS" ]; then | |
| echo "You didn't enter anything." | |
| fi | |
| # Prompt for MySQL root password securely | |
| #read -s -p "Enter MySQL root password: " MYSQL_ROOT_PASSWORD | |
| #echo | |
| # Create MySQL database and user | |
| echo "Creating MySQL database and user..." | |
| #mysql -u root -p"$MYSQL_ROOT_PASSWORD" <<MYSQL_SCRIPT | |
| mysql -u root -p"$DB_PASS" <<MYSQL_SCRIPT | |
| CREATE DATABASE IF NOT EXISTS \`$DB_NAME\`; | |
| FLUSH PRIVILEGES; | |
| MYSQL_SCRIPT | |
| echo "Database and user created successfully." | |
| # Copy .env.example to .env | |
| echo "Setting up .env file..." | |
| cp .env.example .env | |
| # Update .env file with database credentials | |
| sed -i "s/^DB_DATABASE=.*/DB_DATABASE=$DB_NAME/" .env | |
| sed -i "s/^DB_USERNAME=.*/DB_USERNAME=$DB_USER/" .env | |
| sed -i "s/^DB_PASSWORD=.*/DB_PASSWORD=$DB_PASS/" .env | |
| echo ".env file configured." | |
| # Generate Laravel application key | |
| echo "Generating Laravel application key..." | |
| php artisan key:generate | |
| # Run fresh migrations with seeding | |
| echo "Running migrations and seeding database..." | |
| php artisan migrate:fresh --seed | |
| echo "Laravel project setup completed successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment