Last active
February 19, 2021 20:25
-
-
Save ruibeard/1eb5040269434672b6a9d8f1f6def53d to your computer and use it in GitHub Desktop.
Shell Script to Install Laravel on Digital Ocean Droplet LEMP Ubuntu 20.4
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 | |
echo "type your domain ex: subdomain.domain.com " | |
echo "if you type 'example.com', a folder '/var/www/example.com' will be created " | |
read PROJECT_NAME | |
echo "type database name " | |
read DB_DATABASE | |
echo "type db user " | |
read DB_USERNAME | |
echo "type db pass " | |
read DB_PASSWORD | |
echo "Installing necessary dependencies (composer, php8, php-extensions...)" | |
sudo apt install software-properties-common composer -y | |
sudo add-apt-repository -y ppa:ondrej/php > /dev/null 2>&1 | |
sudo apt update | |
sudo apt install php8.0-fpm php8.0-{common,mysql,xml,xmlrpc,curl,gd,imagick,cli,dev,imap,mbstring,opcache,soap,zip,intl,bcmath} -y | |
echo "Creating Nginx Virtual Host Configs" | |
cd /etc/nginx/sites-available/ | |
curl https://gist.githubusercontent.com/ruibeard/bff1315cfaeb7d7c2fdd6927f362fd78/raw/b4263bfd5f83bdb77140140f89d5407aac224277/ngnix.stub -o $PROJECT_NAME | |
sed -i -e "s/\${PROJECT_NAME}/$PROJECT_NAME/" $PROJECT_NAME | |
sudo ln -s /etc/nginx/sites-available/qrcode.bfspires.com /etc/nginx/sites-enabled/ | |
sudo nginx -t | |
sudo systemctl restart nginx | |
echo "Creating Database " | |
echo "create database ${DB_DATABASE} charset utf8mb4; CREATE USER '${DB_USERNAME}'@'localhost' IDENTIFIED BY '${DB_PASSWORD}'; grant all on ${DB_DATABASE}.* to ${DB_USERNAME}@'localhost';flush privileges;" | mysql | |
echo "Creating SSH key" | |
cd ~/.ssh/ | |
cat /dev/zero | ssh-keygen -q -N "" > /dev/null | |
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys | |
cat ~/.ssh/id_rsa.pub | |
read -p "Copy above ssh key to https://github.com/settings/keys" | |
read -p "Copy above ssh key to https://github.com/settings/keys" | |
echo "Create project folder" | |
mkdir /var/www/$PROJECT_NAME && cd "$_" | |
echo "Initializing GIT" | |
git init | |
echo "Make sure you have the key in your github page or we can't 'git pull'" | |
echo "^^^^^^^^^" | |
echo "Adding remote github url to this folder" | |
echo "type githuburl " | |
read GITHUB_URL | |
git remote add origin $GITHUB_URL | |
git pull origin master | |
echo "Installing Laravel dependencies (composer etc..)" | |
cd /var/www/$PROJECT_NAME/ | |
composer install -q | |
chmod -R 777 storage bootstrap/cache | |
chown -R www-data: . | |
echo "Generating Laravel key" | |
php -r "file_exists('.env') || copy('.env.example', '.env');" | |
php artisan key:generate | |
echo "Modifying .env with your DB credentials" | |
sed -i -e "s/DB_DATABASE=laravel/DB_DATABASE=$DB_DATABASE/" .env | |
sed -i -e "s/DB_USERNAME=root/DB_USERNAME=$DB_USERNAME/" .env | |
sed -i -e "s/DB_PASSWORD=/DB_PASSWORD=$DB_PASSWORD/" .env | |
echo "Migrate and Seed Database" | |
php artisan migrate --seed | |
echo "Creating Let's encrypt SSL certificate" | |
sudo certbot --nginx -d $PROJECT_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment