Skip to content

Instantly share code, notes, and snippets.

@djbobbydrake
Last active July 19, 2016 22:29
Show Gist options
  • Save djbobbydrake/ee89e344f765dcfb0ae7e18ec475b756 to your computer and use it in GitHub Desktop.
Save djbobbydrake/ee89e344f765dcfb0ae7e18ec475b756 to your computer and use it in GitHub Desktop.
Setting up Ubuntu + Nginx + PM2

Update ubuntu and install nginx

  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo apt-get install htop git python-software-properties curl libm17n-0 rcconf dialog graphicsmagick build-essential openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev
  4. sudo apt-get install libgoogle-perftools-dev google-perftools
  5. wget http://nginx.org/download/nginx-1.10.1.tar.gz
  6. tar zxvf nginx-1.10.1.tar.gz
  7. rm nginx-1.10.1.tar.gz
  8. cd nginx-1.10.1
  9. sudo ./configure --with-google_perftools_module --with-http_stub_status_module --with-http_ssl_module
  10. sudo make
  11. sudo make install
  12. sudo ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
  13. Add /etc/init/nginx.conf with info from https://www.nginx.com/resources/wiki/start/topics/examples/ubuntuupstart/#
  14. In above script, may need to change DAEMON to env DAEMON=/usr/bin/nginx
  15. sudo initctl list | grep nginx
  16. sudo initctl start nginx
  17. Visit http://{ip_address} to verify successful nginx install
  18. Create your web directory: sudo mkdir -p /var/www/{site}/html
  19. Configure permissions: sudo chown -R $USER:$USER /var/www/{site}/html
  20. sudo chmod -R 755 /var/www

Install Git, checkout repo

  1. sudo apt-get install git
  2. git config --global user.name "name"
  3. git config --global user.email "email"
  4. Create ssh keys, upload to git user's account
  5. Clone your repo to /var/www/{site}/html

Install node and npm

  1. Install nvm from https://github.com/creationix/nvm
  2. nvm install 4.4.7
  3. nvm use 4.4.7
  4. nvm alias default 4.4.7
  5. Update npm: cd ~/.nvm/versions/node/v4.4.7/lib and then npm install npm

Install PM2

  1. npm install pm2 -g
  2. pm2 startup ubuntu
  3. pm2 start app.js
  4. pm2 startup ubuntu
  5. Follow instructions from CLI

Nginx configuration

  1. Tweak the config from https://keymetrics.io/2014/06/17/high-performance-server-configuration-with-ubuntunginxpm2/

Rotate logs

  1. Create file in /etc/logrotate.d/nginx.
  2. Paste and modify the following:
/var/log/nginx/*.log {
        daily
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
        create 640 nginx adm
        sharedscripts
        postrotate
                [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
        endscript
}
  1. Run sudo logrotate -f /etc/logrotate.d/nginx to confirm that your log rotate works.

Installing php7

  1. sudo add-apt-repository ppa:ondrej/php
  2. sudo apt-get update
  3. sudo apt-get install php7.0 php7.0-cli php7.0-fpm php7.0-gd php7.0-json php7.0-mysql php7.0-readline php7.0-pdo
  4. sudo apt-get install mcrypt php7.0-mcrypt
  5. sudo apt-get install php-curl
  6. sudo apt-get install php7.0-mbstring
  7. sudo apt-get install php7.0-zip
  8. sudo apt-get install php7.0-xml
  9. sudo apt-get install php7.0-sybase
  10. Don't know why, but apache2 got installed. Uninstall with sudo service apache2 stop, and then sudo apt-get autoremove apache2, and then sudo apt-get purge apache2*.
  11. Install composer: curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment