Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Server suggestions

Install some dependencies

apt-get update
apt-get upgrade 
apt-get install git wget software-properties-common python-software-properties

Install PHP 7.1 and dependencies

add-apt-repository ppa:ondrej/php
apt-get update
apt-get install php7.1 php7.1-fpm php7.1-cli php7.1-mcrypt php7.1-mbstring php7.1-zip php7.1-curl php7.1-dom

cgi.fix_pathinfo

Use nano or other text editors if you don't know vim.

vim /etc/php/7.1/fpm/php.ini

Find #cgi.fix_pathinfo=1 line and update it to cgi.fix_pathinfo=0 (removing # will uncomment line).

Other tutorials:

Install nodejs

apt-get install nodejs

Other tutorials

Install Nginx

apt-get install nginx

Config nginx

vim /etc/nginx/sites-available/default

Remove all lines and add this (update with your domain name):

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    index index.php index.html index.htm;
    root /home/datmusic/api.example.com/current/public;

    server_name api.example.com;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    location ~ /links/.+\.mp3$ {
     types {
      application/octet-stream;
     }
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Now restart nginx (or reload):

service nginx restart

Other Tutorials

Install composer

Install composer and move it to /usr/local/bin.

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

Other tutorials

Start installing datmusic-api

Add user

Set password and you can skip other sections.

adduser datmusic

Docs: https://linux.die.net/man/8/adduser

Create main folders and files

Login as datmusic (su datmusic).

Run following commands in home folder of datmusic user, one by one (update domain names):

cd /home/datmusic
mkdir api.example.com
git clone https://github.com/alashow/datmusic-api.git
mv datmusic-api/storage api.example.com/
cp datmusic-api/.env.example api.example.com/.env
cd api.example.com
mkdir storage/app/cookies && mkdir -p storage/app/public/mp3
# Update .env for your needs (app_env, app_url, tokens)
vim .env

Run update.sh

cd /home/datmusic/api.example.com/
wget https://gist.githubusercontent.com/alashow/c1a7be2020059e4ae8160328fbaf1a8c/raw/update.sh -O update.sh
chmod +x update.sh

Edit update.sh (vim update.sh)

You need to update ROOT_FOLDER to your domain or to another name (don't customize root folder if you didn't in sections above).

If you want to clone from custom repo, change repo url in update.sh.

Now run update.sh

./update.sh

Update.sh script should work correctly, if it doesn't, please open issue at https://github.com/alashow/datmusic-api/issues or leave comment here.

Fix permissions

Login as root and run:

NOTE: if you aren't using datmusic username, then you will need downlload the script, change the username, and then run.

cd /home/datmusic/api.example.com
wget https://gist.githubusercontent.com/alashow/c1a7be2020059e4ae8160328fbaf1a8c/raw/fix_permissions.sh -O - | sh
# run in "root" folder (e.g /home/datmusic/api.datmusic.xyz/)
chown -R datmusic:www-data storage .env
find storage -type f -exec chmod 664 {} \;
find storage -type d -exec chmod 775 {} \;
chgrp -R www-data storage .env
chmod -R ug+rwx storage .env
# update to your fork or another git repository
REPO="https://github.com/alashow/datmusic-api.git"
REPO_BRANCH="vk-api"
# main folder name, usually domain name
ROOT_FOLDER="api.example.com"
FOLDER_NAME="current"
OLD_RELEASES_FOLDER="releases"
# timestamp as unique name for older releases
CURRENT_RELEASE_NAME=`date +%s`
STORAGE_PATH="/home/datmusic/$ROOT_FOLDER/storage"
ENV_PATH="/home/datmusic/$ROOT_FOLDER/.env"
# if not first deployment (check whether "current" folder exists)
if [ -d "$FOLDER_NAME" ]; then
mkdir -p $OLD_RELEASES_FOLDER
# move current release to releases folder
mv $FOLDER_NAME "$OLD_RELEASES_FOLDER/$CURRENT_RELEASE_NAME"
fi
# clone repo to folder
git clone --depth=1 --branch=$REPO_BRANCH $REPO $FOLDER_NAME
# remove .git, we don't need it
rm -rf $FOLDER_NAME/.git
cd $FOLDER_NAME
# remove default storage folder
rm -rf storage
# create symlink to storage folder and .env file
ln -s $STORAGE_PATH
ln -s $ENV_PATH
# create symlink to mp3 folders
ln -s $STORAGE_PATH/app/public/mp3 public/mp3
ln -s $STORAGE_PATH/app/public/links public/links
composer install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment