Skip to content

Instantly share code, notes, and snippets.

@coffebar
Last active March 29, 2018 10:31
Show Gist options
  • Save coffebar/7dee8c4ee0bf76215471d03ffc5ec1e0 to your computer and use it in GitHub Desktop.
Save coffebar/7dee8c4ee0bf76215471d03ffc5ec1e0 to your computer and use it in GitHub Desktop.
Prepare Ubuntu 16.04 server for sending WebPush via php-cron
#!/usr/bin/env bash
PUSHER_USERNAME=webpusher
PUSHER_PASSWORD="1O23%dv5d3}qaa2"
apt update && apt -y upgrade
# install requirements from apt
apt install -y mc htop php-gmp php-mbstring php-curl php-mysql openssl
# add user with ssh
useradd -m -p $PUSHER_PASSWORD $PUSHER_USERNAME
usermod -aG ssh $PUSHER_USERNAME
mkdir /home/$PUSHER_USERNAME/.ssh
touch /home/$PUSHER_USERNAME/.ssh/authorized_keys
chown -R $PUSHER_USERNAME:$PUSHER_USERNAME /home/$PUSHER_USERNAME/
chmod 700 /home/$PUSHER_USERNAME/.ssh
chmod 644 /home/$PUSHER_USERNAME/.ssh/authorized_keys
echo "$PUSHER_USERNAME:$PUSHER_PASSWORD" | chpasswd
# change shell to bash
chsh -s /bin/bash $PUSHER_USERNAME
su $PUSHER_USERNAME -c bash << EOF
cd /home/$PUSHER_USERNAME/
# install composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
rm composer-setup.php
# install requirements from composer
echo -n '{"require":{"minishlink/web-push": "^2.0"}}' > "composer.json"
php composer.phar install
# create new file cron.php
echo -n '<?php ' > "cron.php"
# add cron.php to crontab
(crontab -l 2>/dev/null; echo "* * * * * php cron.php") | crontab -
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment