Skip to content

Instantly share code, notes, and snippets.

@codeitlikemiley
Forked from g0ld3lux/ReadME.md
Last active November 28, 2023 12:38
Show Gist options
  • Select an option

  • Save codeitlikemiley/6a951698a570c7a49bc4bc96e24e0113 to your computer and use it in GitHub Desktop.

Select an option

Save codeitlikemiley/6a951698a570c7a49bc4bc96e24e0113 to your computer and use it in GitHub Desktop.
ZSH + Vim Production in Digital Ocean - Running With Docker

ZSH + Vim Production in Digital Ocean - Running With Docker

Requirement: Windows 10 Windows WSL WSL Mintty Digital Ocean Account

Note if you are not using windows, you dont need the vim config for windows ....

Spinning Up Server with Digital Ocean

Note If you sign up in my referral link that would be awesome support
  • Digital Ocean Create a New Droplet

  • Click 1 Click Install Tab

  • Find And choose Docker Image

  • Choose Size Preferabbly choose 20$ /mo

NOTE : At Least 2 GB memory to avoid, shutting down of containers unexpectedly due to lack of memory
  • add new ssh key
ssh-keygen -t rsa -C "your_email@example.com"

Just Follow Steps to get Key

Then Copy your SSH key

cat ~/.ssh/id_rsa.pub
  • Paste it on Your DO Droplet SSHKEY

  • Lastly Choose a hostname or let the default be set by DO

SSH to your MinttyWSL Terminal

  • SSH to terminal
ssh root@ipaddress
  • We Create a new Zsh Sudo User
This is to avoid corrupting your root , and for security purposes
adduser username
usermod -aG sudo username
  • Switch User
su - username

Make Our Terminal Pretty

  • Install ZSH
sudo apt-get install zsh
  • make Zsh default for this user , temporary
chsh -s /bin/zsh
  • We edit our .bashrc
vim .bashrc
  • make zsh default , permanent
if [ -t 1 ]; then
exec zsh
fi
  • Use Your Own ZSH Config , you can use mine or edit it
wget https://gist.githubusercontent.com/codeitlikemiley/68d3f1a9a1da5abf2c8152d7612b943a/raw/ff85fabf5d17f86984e5a58ec2fb5a089276ff65/production.zshrc
mv production.zshrc .zshrc
Added Shortcut: me (your home), lara (laradock folder), sites (/var/www), code(/var/www/code) for your App
  • We Add Bash Profile @ $HOME Directory
wget https://gist.githubusercontent.com/codeitlikemiley/68d3f1a9a1da5abf2c8152d7612b943a/raw/bf170527c611609d98fdbcd24540f8cb28e2ad88/production.bashprofile
mv production.bashprofile .bash_profile
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
  • Add Our Custom Theme For Our Terminal To Look Awesome!
exit
su - username
cd $ZSH/themes
wget https://raw.githubusercontent.com/codeitlikemiley/materialshell/1.1.0/zsh/other/materialshell-electro.zsh-theme

Make Our Vim Pretty

  • Add your .vimrc file at $HOME directory
cd ~
wget https://gist.githubusercontent.com/g0ld3lux/db5c2aa472d7815728a6990abc599df2/raw/db22e9029c28224b6bc287698030ff89697c8ad2/user.vimrc
mv user.vimrc .vimrc
  • Create .vim folder at $HOME directory
mkdir .vim
  • Get Vundle to Handle Our Vim Plugins
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
  • Copy Plugins Configuration of Vim
cd .vim
wget https://gist.githubusercontent.com/g0ld3lux/db5c2aa472d7815728a6990abc599df2/raw/53d4a83dc262cdc2d7b7dadeab72a46666538222/plugins.vim

  • Add Windows Short Cut Keys To Work With Vim
wget https://gist.githubusercontent.com/g0ld3lux/db5c2aa472d7815728a6990abc599df2/raw/53d4a83dc262cdc2d7b7dadeab72a46666538222/mswin.vim
source ~/.vim/mswin.vim
Note: if your not Windows You dont Need mswin.vim
  • Install Vim Dependencies ( This is For Search )
cd ~
sudo apt-get install exuberant-ctags
sudo apt-get install ack-grep
  • Install All Vim Plugins
vim
,ep
:PluginInstall
:q
  • Add ackrc config @ $HOME/.ackrc
wget https://gist.githubusercontent.com/g0ld3lux/db5c2aa472d7815728a6990abc599df2/raw/db22e9029c28224b6bc287698030ff89697c8ad2/user.ackrc
mv user.ackrc .ackrc

Getting Docker Running

  • go back to the root user
exit or su - root
  • Install docker compose
docker-compose
  • switch user
su - su username
  • Run Docker on Sudo on Current User
sudo gpasswd -a $USER docker
  • Allow docker-compose to be use on non-root user
sudo chown -R $(whoami) /usr/local/bin
Note , if you didnt install from 1 click install app and havent choose docker , you may need to configure this yourself

Installing Your Web Application and Run With Laradock

  • Clone Laradock
cd /var
sudo mkdir www
cd www
sudo chown -R $USER:$USER .
git clone https://github.com/laradock/laradock
  • Configure your Laradock Config
cd laradock
cp env-example .env
vim .env

  • Configure MYSQL database , user, user pass and root pass
/MYSL 
enter
press N for next and Enter if you Find MYSQL Configuration
MYSQL_VERSION=8.0
MYSQL_DATABASE=db
MYSQL_USER=YOURUSERNAME
MYSQL_PASSWORD=YOURPASSWORD
MYSQL_ROOT_PASSWORD=YOURROOTPASS
  • exit type :wq

  • Configure Your Web server (NGINX)

cd nginx/sites
cp laravel.conf.example code.conf
To use Other Web Server Check laradock
  • Edit Your Nginx Conf and ADD your DOMAIN
vim code.conf
 server_name YOURDOMAINNAME.com;
 root /var/www/code/public;
  • Clone Your APP REPO
sites
git clone YOURLARAVELPROJECT code
Make Sure to name the folder code, Coz the default configuration for the first site uses that name
  • Run docker-compose command to spin up your app server requirement for example redis, nginx , mysql
docker-compose up -d nginx redis mysql phpmyadmin
  • Install All Your App Composer Dependecies
ws
cd code
composer install
php artisan key:generate
  • Configure Your App Env File
cp .env.example .env
vim .env
  • You Need to Change Redis and Mysql HOST and your DB credentials
DB_HOST=mysql
DB_DATABASE=db
DB_USERNAME=YOURUSERNAME
DB_PASSWORD=YOURPASSWORD
REDIS_HOST=redis
Note: mysql and redis is being autoproxy by docker to point to correct address, same with other containers
You may read more about this on laradock
Note: make your you configure MYSQL database/user/pass , but the default should work
  • you can then view your laravel site at your ipaddress and Once your DNS propagate you can visit your domain also
192.168.1.1 

COnfiguring DNS

  • You need to Login in your Digital Ocean Account

  • Go to NETWORKING

  • Then Add your Domain Name

  • Also You Need to Login In Your Domain Name Server Provider For Example Godaddy

  • You Then Need to POint Your Domain to Digital Ocean DNS

ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com

Thats It! Have Fun!

@codeitlikemiley
Copy link
Author

Once Everything is Installed the normal workflow would be
ssh to your server
su - username

then from there
if you want to go to install with composer or use tinker
just type ws , it will easily log you in your workspace container

for logging in mysql type mysql
also for redis type redis

then authenticate as is...

for configuring your laradock config
just type lara it will send you straight to laradock folder

and for editting stuff in your code just type code
its is better to edit vim outside the container , so you can use your vim shortcuts and configuration easily

@codeitlikemiley
Copy link
Author

Added this awesome plugin for auto completion
https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment