
Initial Setup
Download and Install VirtualBox
- The first thing you need is to download VirtualBox for your platform if you haven’t already. You can download it here.
- Install VirtualBox onto your fastest drive.
Download and Install Ubuntu
- It’s easiest to download and use Ubuntu Server 18.04 right now. But if you like, you can download Ubuntu 20.04 instead.
- Launch VirtualBox, and then create a new VM. On the first screen:
- Choose a memorable name.
- Put the Machine Folder on your fastest drive.
- Type: Choose Linux
- Version: Choose Ubuntu 64 Bit.
- On the second screen:
- Select as much memory as you can spare. 8 gigs would be good.
- On the third screen:
- You’ll want to create a new virtual disk.
- If you only use VirtualBox then you can leave it as VDI and click Create.
- Select Dynamically Sized and hit Next.
- Ensure that you have chosen to put the disk image on your fastest drive. Give the drive a nice size (about 100GB) and hit Create.
- Now that the disk image is created, choose the Machine and then click on Settings.
- Navigate to Storage, click on the empty CD Under Storage Devices.
- Under Attributes on the Right, Click on the disk next to Optical Drive.
- Find the Ubuntu disk image you downloaded and select it.
- Toggle the Live CD/DVD checkbox and then hit Ok.
- Now hit Launch/Start and get let the installation begin.
- You might get a prompt when you initially hit launch asking you to choose a media to boot from. It “should” have the Ubuntu Live CD/DVD already chosen, so just confirm it and keep ongoing.
Installing Ubuntu Part 2
- After some scrolling text, you’ll get to your first prompt: Choosing a language. Hit Enter and you’ll get the default English option.
- It’s almost guaranteed that you’ll get hit with an Installer Update. Just go ahead and update to the new installer.
- That should have went fast and you’ll see Keyboard Configuration. Unless you have something unique, hit Enter.
- Hit Enter on Network Connections without touching anything.
- Hit Enter on Configure Proxy.
- Hit Enter on configure Ubuntu Archive Mirror.
- On Guide Storage Configuration:
- Ensure that Use an entire Disk is checked.
- Ensure
Set up this disk as an LVM group
is UNCHECKED or you will have nothing but problems. - Move on down to Done and hit enter.
- On Storage Configuration you should be able to just hit Enter.
- You’ll be prompted with a
Confirm Destructive Action
warning. If you’ve done everything right, select Continue and hit enter. - On Profile Setup you’ll fill in the information requested. Make a note of it so you don’t lose it, or you’ll be doing all of this again.
- On SSH Setup, check the box for Install OpenSSH Server. Unless you have an SSH Identity to upload/import, leave it set to No.
- On Featured Server Snaps, skip everything and hit Done.
- While you’re making all those choices, it’s been installing in the background, so that’s good news! It’ll then start downloading and installing security updates. Let it do it’s thing before proceeding.
- Once updates are down, hit Reboot. You’ll probably see an error about unmounting the cdrom. Click on Devices in the menu, select Optical Drives, and then choose the unmount option.
- Click on the Machine menu option, then hit Reset, click through the warning and let it reboot.
- After it reboots, you may not see a login prompt, but you’ll notice that it has stopped scrolling text for a minute or two. Try hitting enter. If you get a login prompt, go ahead and log in! 🙂
Prep the Server
- Create a Deploy user
sudo su
adduser deploy
adduser deploy sudo
exit
- You’ll need to know your IP address for this next step. Since you don’t know it, we’ll need to install net tools and then do ifconfig to get the guest computers IP address. This will let us copy your personal SSH key to the guest machine.
sudo apt install net-tools
ifconfig
and get your ip address.- From your host computers command prompt, type:
ssh-copy-id [email protected]<your-guest-ip-address>
- From your host computers command prompt, type:
ssh-copy-id [email protected]<your-guest-ip-address>
- Now type
ssh [email protected]<your-guest-ip-address>
Install Virtualbox Guest Additions
- In Virtualbox, select Devices and then select Insert Guest Additions CD.
- On the command prompt type:
sudo mount /dev/cdrom /mnt
- Type
cd /mnt
- Type
sudo apt-get install -y dkms build-essential linux-headers-generic linux-headers-$(uname -r)
- Type
sudo su
- Type
./VboxLinuxAdditions.run
- Type
shutdown -r now
- In Devices menu be sure to enable the shared clipboard (Host to Guest at a minimum). Drag and Drop isn’t necessary because you don’t have a GUI.
Installing Ruby
- Adding Node.js repository
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
- Adding Yarn repository
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo add-apt-repository ppa:chris-lea/redis-server
- Refresh our packages list with the new repositories
sudo apt-get update
- Install our dependencies for compiiling Ruby along with Node.js and Yarn
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev dirmngr gnupg apt-transport-https ca-certificates redis-server redis-tools nodejs yarn
- Installing RBENV:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
git clone https://github.com/rbenv/rbenv-vars.git ~/.rbenv/plugins/rbenv-vars
exec $SHELL
rbenv install 2.7.1
rbenv global 2.7.1
ruby v
- ruby 2.7.1
- Installing Bundler:
Installing NGINX and Passenger
For production, we’ll be using NGINX as our webserver to receive HTTP requests. Those requests will then be handed over to Passenger which will run our Ruby app.
Installing Passenger is pretty straightforward. We’ll add their repository and then install and configure their packages.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger bionic main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update
sudo apt-get install -y nginx-extras libnginx-mod-http-passenger
if [ ! -f /etc/nginx/modules-enabled/50-mod-http-passenger.conf ]; then sudo ln -s /usr/share/nginx/modules-available/mod-http-passenger.load /etc/nginx/modules-enabled/50-mod-http-passenger.conf ; fi
sudo ls /etc/nginx/conf.d/mod-http-passenger.conf
Now that we have NGINX and Passenger installed, we need to point Passenger to the correct version of Ruby.
We’ll start by opening up the Passenger config file in your favorite editor, nano or vim.
If you want to use the Nano for editing: sudo nano /etc/nginx/conf.d/mod-http-passenger.conf
If you want to use the Vim for editing: sudo vim /etc/nginx/conf.d/mod-http-passenger.conf
We simply want to change the passenger_ruby line to match the following: passenger_ruby /home/deploy/.rbenv/shims/ruby;
Save this file and we’ll start NGINX. sudo service nginx start
You can check and make sure NGINX is running by visiting your server’s public IP address in your browser and you should be greeted with the “Welcome to NGINX” message.
Next we’re going to remove this default NGINX server and add one for our application instead.
sudo rm /etc/nginx/sites-enabled/default
- If you want to use the Nano for editing
sudo nano /etc/nginx/sites-enabled/myapp
- If you want to use the Vim for editing
sudo vim /etc/nginx/sites-enabled/myapp
We want the contents of our NGINX site to look like the following.
Change “myapp` to the name of your app. We’ll use this same folder later on when we define our Capistrano deploy_to folder.
server {
listen 80;
listen [::]:80;
server_name _;
root /home/deploy/myapp/current/public;
passenger_enabled on;
passenger_app_env production;
location /cable {
passenger_app_group_name myapp_websocket;
passenger_force_max_concurrent_requests_per_process 0;
}
# Allow uploads up to 100MB in size
client_max_body_size 100m;
location ~ ^/(assets|packs) {
expires max;
gzip_static on;
}
}
Save the file and then we’ll reload NGINX to load the new server files. sudo service nginx reload
Setting up PostgreSQL
sudo apt-get install postgresql postgresql-contrib libpq-dev
sudo su - postgres
createuser --pwprompt deploy
createdb -O deploy myapp
exit
Creating a MYSQL Database
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
sudo mysql_secure_installation
- Open the MySQL CLI to create the user and database
mysql -u root -p
In the following example, make sure you replace the following names:
- myapp with the name of your database, typically the name of your app
- $omeFancyPassword123 with your own password
- deploy with the name of your database user if you’d like something different
CREATE DATABASE IF NOT EXISTS myapp;
CREATE USER IF NOT EXISTS 'deploy'@'localhost' IDENTIFIED BY '$omeFancyPassword123';
CREATE USER IF NOT EXISTS 'deploy'@'%' IDENTIFIED BY '$omeFancyPassword123';
GRANT ALL PRIVILEGES ON myapp.* TO 'deploy'@'localhost';
GRANT ALL PRIVILEGES ON myapp.* TO 'deploy'@'%';
FLUSH PRIVILEGES;
\q