Note to self, after fiddling with the same errors again and again while setting this up, I'm writing down what I repeat every time I setup a new droplet @ digitalocean.
Create a new droplet @ cloud.digitalocean.com and, when created, copy the IP address to setup a domain name pointing to it right away.
I go at https://www.hover.com/domains and add an A record, I'll assume dev.domain.com
in this guide.
# Login by ssh with the root user and the password sent by email.
ssh [email protected]
# Add a new user called fred (setup a string password)
adduser fred
# Add it to the "sudo" unix group
adduser fred sudo
Now we have an other user than root
we can login with that one, let's do this now and setup a few utilities.
ssh [email protected]
# Shell setup
sudo apt-get install git curl
git clone https://github.com/kiasaki/dotfiles.git
cd dotfiles && ./setup.sh
# Upload our public key so we can login easily
mkdir .ssh
sudo vim ~/.ssh/authorized_keys
# Generate an identity file for those private repos we will need to access
# And don't put any password so we can use it whitout interaction
ssh-keygen -t rsa
sudo apt-get install apache2-utils
sudo apt-get install nginx
sudo apt-get install postgres postgres-contrib
sudo apt-get install php5-cli php5-fpm php5-mcrypt php5-gd php5-pgsql php5-curl
mkdir -p ~/repo/<app>.git
cd ~/repo/<app>.git
git init --bare
curl -o hooks/post-receive https://gist.githubusercontent.com/kiasaki/00a3044d12956a828e76/raw/1b26f63f309e9afaad89fcb127e8e9c147ee402c/post-receive
vim hooks/post-receive
chmod +x hooks/post-receive
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/bin/composer
# Enter postgres
sudo -u postgres psql
Now let's create a user and a database
CREATE USER <dbuser> WITH PASSWORD '<dbpass>';
CREATE DATABASE <dbname>;
GRANT ALL PRIVILEGES ON DATABASE <dbname> TO <dbuser>;
\q
sudo mkdir -p /var/www/<app>/current
sudo chmod -R 755 /var/www/<app>/
sudo chown -R www-data:www-data /var/www/<app>/
# Maybee
# setfacl -Rm d:u:userA:rwX,u:userA:rwX /var/www
Now might be the right time to review that post-receive hook to see if it matches the folders newly created.
Next step is to test the deploy hook to bring the app files on the server
# On your local machine
git remote add live [email protected]:repo/<app>.git
git push live master
# or
git push live <current branch>:master
Here is a simple nginx config for a php website, if it is in the website root we can link it using:
sudo ln -s /var/www/<app>/current/nginx.conf /etc/nginx/sites-enabled/<app>
sudo service nginx restart
sudo mkdir /etc/nginx/ssl
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/server.key -out /etc/nginx/ssl/server.crt
https://github.com/epicserve/s3-backups
sudo apt-get install python-pip
sudo pip install s3-backups
sudo curl -o /usr/local/bin/postgres_to_s3.py https://raw.githubusercontent.com/epicserve/s3-backups/master/s3_backups/postgres_to_s3.py
sudo vim /etc/cron.d/postgres_to_s3
# Add this:
0 */1 * * * postgres /usr/local/bin/postgres_to_s3.py --AWS_ACCESS_KEY_ID='xxxxxxxxxxxxxxxxxxxx' --AWS_SECRET_ACCESS_KEY='xxxxxxxxxxxxxxxxxxxx' --S3_BUCKET_NAME='my-backup-bucket' --S3_KEY_NAME='postgres/my-awesome-server' --backup --archive
wget https://raw.github.com/logentries/le/master/install/linux/logentries_install.sh && sudo bash logentries_install.sh
Then make sure log files are readable and:
le register
le monitor
le follow /var/log/nginx/error.log
sudo service logentries restart
$ sudo mysql -p
CREATE USER 'user'@'localhost' IDENTIFIED BY '';
CREATE DATABASE transax;
GRANT ALL ON transax.* TO 'transax'@'localhost';