Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mamedinfo/d2abea899339a42b7d7f53f8ad493a42 to your computer and use it in GitHub Desktop.
Save mamedinfo/d2abea899339a42b7d7f53f8ad493a42 to your computer and use it in GitHub Desktop.

Revisions

  1. @marcuslilja marcuslilja revised this gist Jun 23, 2016. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions ubuntu-server-setup-16.04.md
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,6 @@
    * Nginx
    * MySQL
    * PHP
    * Memcache
    * PHPMyAdmin
    * Node
    * Composer

  2. @marcuslilja marcuslilja revised this gist Jun 23, 2016. 1 changed file with 1 addition and 30 deletions.
    31 changes: 1 addition & 30 deletions ubuntu-server-setup-16.04.md
    Original file line number Diff line number Diff line change
    @@ -310,33 +310,4 @@ phpenmod mcrypt
    aptitude install -y \
    mysql-server \
    mysql-client
    ```

    ## Install PHPMyAdmin
    ```
    apt-get install -y phpmyadmin
    ```

    Add PHPMyAdmin configuration to default host.
    ```
    location /phpmyadmin {
    root /usr/share/;
    index index.php index.html index.htm;
    location ~ ^/phpmyadmin/(.+\.php)$ {
    include snippets/fastcgi-php.conf;
    root /usr/share/;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_intercept_errors on;
    }
    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
    root /usr/share/;
    }
    }
    location /phpMyAdmin {
    rewrite ^/* /phpmyadmin last;
    }
    ```
    ```
  3. @marcuslilja marcuslilja renamed this gist Jun 23, 2016. 1 changed file with 47 additions and 40 deletions.
    87 changes: 47 additions & 40 deletions ubuntu-server-setup-15.04.md → ubuntu-server-setup-16.04.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Server setup for Ubuntu 15.04 on Digital Ocean
    # Server setup for Ubuntu 16.04 on Digital Ocean

    **The setup installs the following software:**

    @@ -67,9 +67,31 @@ ntpdate
    dpkg-reconfigure tzdata
    ```

    ## Install firewall
    ```
    sudo apt-get install ufw
    ```

    Allow SSH, HTTP and HTTPS.
    ```
    sudo ufw allow ssh
    sudo ufw allow http
    sudo ufw allow https
    ```

    Enable firewall.
    ```
    sudo ufw enable
    ```

    Check the status of the firewall.
    ```
    sudo ufw status verbose
    ```

    ## Install NodeJS
    ```
    curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
    curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
    apt-get install -y nodejs
    ```

    @@ -196,7 +218,7 @@ server {
    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_intercept_errors on;
    }
    }
    @@ -230,28 +252,31 @@ service nginx restart

    ## Install PHP
    ```
    apt-get install -y \
    php5-common \
    php5-mysqlnd \
    php5-xmlrpc \
    php5-curl \
    php5-gd \
    php5-cli \
    php5-fpm \
    php5-dev \
    php5-imap \
    php5-mcrypt \
    php5-memcache \
    php5-sqlite \
    apt-get -y install \
    php7.0-fpm \
    php7.0-mysql \
    php7.0-curl \
    php7.0-gd \
    php7.0-intl \
    php-pear \
    memcached \
    imagemagick
    php-imagick \
    php7.0-imap \
    php7.0-mcrypt \
    php-memcache \
    php7.0-pspell \
    php7.0-recode \
    php7.0-sqlite3 \
    php7.0-tidy \
    php7.0-xmlrpc \
    php7.0-xsl \
    php7.0-mbstring \
    php-gettext
    ```

    ## Configure PHP
    Adjustments for php-fpm is based on the 2GB Digital Ocean setup.
    ```
    pico /etc/php5/fpm/pool.d/www.conf
    pico /etc/php/7.0/fpm/pool.d/www.conf
    ```

    ```
    @@ -265,37 +290,19 @@ pm.max_spare_servers = 6
    ```

    ```
    pico /etc/php5/fpm/php.ini
    pico /etc/php/7.0/fpm/php.ini
    ```

    ```
    post_max_size = 64M
    upload_max_filesize = 64M
    date.timezone = Europe/Stockholm
    session.save_handler = memcache
    session.save_path = unix:/tmp/memcached.sock
    mysql.default_socket = /var/run/mysqld/mysqld.sock
    ```

    Enable mcrypt.
    ```
    php5enmod mcrypt
    ```

    ## Configure Memcached
    Configure Memcached to use socket instead of TCP service.
    ```
    pico /etc/memcached.conf
    ```

    ```
    # Remove the following.
    -p 11211
    -l 127.0.0.1
    # Add the following instead.
    -s /tmp/memcached.sock
    -a 666
    phpenmod mcrypt
    ```

    ## Install MySQL
    @@ -320,7 +327,7 @@ location /phpmyadmin {
    include snippets/fastcgi-php.conf;
    root /usr/share/;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_intercept_errors on;
    }
  4. @marcuslilja marcuslilja revised this gist Apr 6, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -55,6 +55,7 @@ make \
    fail2ban \
    apache2-utils \
    curl \
    bc \
    git \
    htop \
    ntp \
  5. @marcuslilja marcuslilja revised this gist Apr 5, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -124,7 +124,7 @@ gzip_comp_level 2;
    gzip_buffers 16 8k;
    gzip_min_length 1100;
    gzip_http_version 1.1;
    gzip_types text/plain text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/rss+xml text/javascript image/svg+xml application/x-font-ttf font/opentype application/vnd.ms-fontobject;
    gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/rss+xml text/javascript image/svg+xml application/x-font-ttf font/opentype application/vnd.ms-fontobject;
    access_log off;
  6. @marcuslilja marcuslilja revised this gist Apr 5, 2016. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -77,11 +77,6 @@ Update npm.
    npm update -g
    ```

    Install bower.
    ```
    npm -g install bower
    ```

    ## Install Composer
    ```
    curl -sS https://getcomposer.org/installer | php -- \
  7. @marcuslilja marcuslilja revised this gist Apr 5, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ chown -R <username>:<username> /home/<username>/.ssh

    Run `visudo` and add the following line at the end of the file.
    ```
    <username> ALL=(ALL) NOPASSWD:ALL
    <username> ALL=(ALL) NOPASSWD: ALL
    ```

    Create and expose a SSH Key for the new user
    @@ -68,7 +68,7 @@ dpkg-reconfigure tzdata

    ## Install NodeJS
    ```
    curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
    curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
    apt-get install -y nodejs
    ```

  8. @marcuslilja marcuslilja revised this gist Apr 5, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ chown -R <username>:<username> /home/<username>/.ssh

    Run `visudo` and add the following line at the end of the file.
    ```
    <username> ALL=(ALL) NOPASSWD: ALL
    <username> ALL=(ALL) NOPASSWD:ALL
    ```

    Create and expose a SSH Key for the new user
  9. @marcuslilja marcuslilja revised this gist Oct 1, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -68,7 +68,7 @@ dpkg-reconfigure tzdata

    ## Install NodeJS
    ```
    curl -sL https://deb.nodesource.com/setup_dev | sudo bash -
    curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
    apt-get install -y nodejs
    ```

  10. @marcuslilja marcuslilja revised this gist Oct 1, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -262,7 +262,7 @@ pico /etc/php5/fpm/pool.d/www.conf
    listen.owner = www-data
    listen.group = www-data
    pm.max_children = 12
    pm.max_children = 16
    pm.start_servers = 4
    pm.min_spare_servers = 2
    pm.max_spare_servers = 6
  11. @marcuslilja marcuslilja revised this gist Oct 1, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -56,6 +56,7 @@ fail2ban \
    apache2-utils \
    curl \
    git \
    htop \
    ntp \
    ntpdate
    ```
  12. @marcuslilja marcuslilja revised this gist Sep 21, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -128,7 +128,7 @@ gzip_comp_level 2;
    gzip_buffers 16 8k;
    gzip_min_length 1100;
    gzip_http_version 1.1;
    gzip_types text/plain text/plain text/css application/json application/x-javascript text/xml application/xml application/rss+xml text/javascript image/svg+xml application/x-font-ttf font/opentype application/vnd.ms-fontobject;
    gzip_types text/plain text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/rss+xml text/javascript image/svg+xml application/x-font-ttf font/opentype application/vnd.ms-fontobject;
    access_log off;
  13. @marcuslilja marcuslilja revised this gist Sep 19, 2015. 1 changed file with 25 additions and 0 deletions.
    25 changes: 25 additions & 0 deletions ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -163,6 +163,31 @@ server {
    index index.php index.html;
    server_name <domain-name>;
    charset utf-8;
    location ~* \.(?:manifest|appcache|html?|xml|json)$ {
    expires -1;
    }
    location ~* \.(?:rss|atom)$ {
    expires 1h;
    add_header Cache-Control "public";
    }
    location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
    expires 1M;
    add_header Cache-Control "public";
    }
    location ~* \.(?:css|js)$ {
    expires 1y;
    add_header Cache-Control "public";
    }
    location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ {
    expires 1M;
    add_header Cache-Control "public";
    }
    location / {
    try_files $uri $uri/ /index.php?$query_string;
  14. @marcuslilja marcuslilja revised this gist Aug 20, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -134,7 +134,7 @@ access_log off;
    client_body_buffer_size 10K;
    client_header_buffer_size 1k;
    client_max_body_size 8m;
    client_max_body_size 64m;
    client_header_timeout 12;
    client_body_timeout 12;
  15. @marcuslilja marcuslilja revised this gist May 6, 2015. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -60,6 +60,11 @@ ntp \
    ntpdate
    ```

    ## Set correct timezone
    ```
    dpkg-reconfigure tzdata
    ```

    ## Install NodeJS
    ```
    curl -sL https://deb.nodesource.com/setup_dev | sudo bash -
  16. @marcuslilja marcuslilja revised this gist May 6, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -151,8 +151,8 @@ pico /etc/nginx/sites-available/<domain-name>.conf

    ```
    server {
    listen 80 default_server;
    listen [::]:80 default_server;
    listen 80;
    listen [::]:80;
    root /var/www/<domain-name>/public/;
    index index.php index.html;
  17. @marcuslilja marcuslilja revised this gist May 6, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -155,7 +155,7 @@ server {
    listen [::]:80 default_server;
    root /var/www/<domain-name>/public/;
    index.php index.html;
    index index.php index.html;
    server_name <domain-name>;
  18. @marcuslilja marcuslilja revised this gist May 6, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,8 @@
    * Nginx
    * MySQL
    * PHP
    * Memcache
    * PHPMyAdmin
    * Node
    * Composer

  19. @marcuslilja marcuslilja revised this gist May 6, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -175,7 +175,7 @@ server {
    # Redirect www to non-www
    server {
    server_name www.<domain-name>;
    return 301 http://<domain-name>;
    return 301 http://<domain-name>$request_uri;
    }
    ```

  20. @marcuslilja marcuslilja revised this gist May 6, 2015. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -149,12 +149,13 @@ pico /etc/nginx/sites-available/<domain-name>.conf

    ```
    server {
    listen 80;
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/<domain-name>/public/;
    index index.php index.html index.htm;
    index.php index.html;
    server_name _ <domain-name>;
    server_name <domain-name>;
    location / {
    try_files $uri $uri/ /index.php?$query_string;
  21. @marcuslilja marcuslilja revised this gist May 6, 2015. 1 changed file with 16 additions and 46 deletions.
    62 changes: 16 additions & 46 deletions ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,28 @@
    # Manual server configuration (Digital Ocean)
    # Server setup for Ubuntu 15.04 on Digital Ocean

    Parameters
    * <username>
    * <ssh-key>
    **The setup installs the following software:**

    * Nginx
    * MySQL
    * PHP
    * Node
    * Composer

    ## Update system
    ```
    apt-get update && apt-get dist-upgrade -y
    apt-get autoremove -y
    ```


    ## Add new user
    Instead of using root as the user, we add a new one.

    ```
    useradd -d /home/<username> -m -s /bin/bash <username>
    usermod -a -G adm,cdrom,sudo,dip,plugdev <username>
    ```

    Copy root authorized_keys to no <username>.
    If you provided your SSH key when creating the droplet, you can copy the authorized_keys to the new `username` to skip needing a password when connecting.

    ```
    mkdir /home/<username>/.ssh
    @@ -27,22 +31,17 @@ chmod 600 /home/<username>/.ssh/authorized_keys
    chown -R <username>:<username> /home/<username>/.ssh
    ```

    Run visudo and add the following line at the end of the file.
    Run `visudo` and add the following line at the end of the file.
    ```
    visudo
    <username> ALL=(ALL) NOPASSWD: ALL
    ```

    Logout and log back in as <username>. Password-less sudo ftw.

    Create ssh-key

    Create and expose a SSH Key for the new user
    ```
    ssh-keygen -t rsa -C "hosting@ardentic.com"
    ssh-keygen -t rsa -C "name@email.com"
    cat ~/.ssh/id_rsa.pub
    ```


    ## Install packages
    ```
    apt-get install -y \
    @@ -59,32 +58,29 @@ ntp \
    ntpdate
    ```


    ## Install NodeJS
    ```
    curl -sL https://deb.nodesource.com/setup_dev | sudo bash -
    apt-get install -y nodejs
    ```

    Update npm.

    ```
    npm update -g
    ```

    Install bower.

    ```
    npm -g install bower
    ```


    ## Install Composer
    ```
    curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
    curl -sS https://getcomposer.org/installer | php -- \
    --install-dir=/usr/bin \
    --filename=composer
    ```


    ## Create default htpasswd file
    ```
    htpasswd -c /etc/default/htpasswd <htpasswd-username>
    @@ -96,22 +92,18 @@ add-apt-repository ppa:nginx/development
    apt-get update && apt-get install nginx-full -y
    ```


    ## Configure Nginx
    Check number of cores to set worker_processes.

    ```
    grep processor /proc/cpuinfo | wc -l
    ```

    Check core limit for number of connections.

    ```
    ulimit -n
    ```

    Configure Nginx accordingly.

    ```
    worker_processes <number-of-cores>;
    worker_connections <core-limit>;
    @@ -144,22 +136,13 @@ send_timeout 10;
    large_client_header_buffers 2 1k;
    ```

    Disable default host.

    ```
    rm /etc/nginx/sites-enabled/default
    ```

    Restart Nginx.

    ```
    service nginx restart
    ```


    ## Configure Nginx vhost
    Create config file for virtual host.

    ```
    pico /etc/nginx/sites-available/<domain-name>.conf
    ```
    @@ -196,30 +179,25 @@ server {
    ```

    Create public directory in site folder.

    ```
    mkdir -p /var/www/<domain-name>/public
    ```

    Fix correct owner.

    ```
    chown -R <username>:<username> /var/www/<domain-name>
    ```

    Enable vhost.

    ```
    ln -s /etc/nginx/sites-available/<domain-name>.conf /etc/nginx/sites-enabled/<domain-name>.conf
    ```

    Restart Nginx.

    ```
    service nginx restart
    ```


    ## Install PHP
    ```
    apt-get install -y \
    @@ -240,10 +218,8 @@ memcached \
    imagemagick
    ```


    ## Configure PHP
    Adjustments for php-fpm is based on the 2GB Digital Ocean setup.

    ```
    pico /etc/php5/fpm/pool.d/www.conf
    ```
    @@ -272,15 +248,12 @@ mysql.default_socket = /var/run/mysqld/mysqld.sock
    ```

    Enable mcrypt.

    ```
    php5enmod mcrypt
    ```


    ## Configure Memcached
    Configure Memcached to use socket instead of TCP service.

    ```
    pico /etc/memcached.conf
    ```
    @@ -295,22 +268,19 @@ pico /etc/memcached.conf
    -a 666
    ```


    ## Install MySQL
    ```
    aptitude install -y \
    mysql-server \
    mysql-client
    ```


    ## Install PHPMyAdmin
    ```
    apt-get install -y phpmyadmin
    ```

    Add PHPMyAdmin configuration to default host.

    ```
    location /phpmyadmin {
    root /usr/share/;
  22. @marcuslilja marcuslilja created this gist May 6, 2015.
    335 changes: 335 additions & 0 deletions ubuntu-server-setup-15.04.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,335 @@
    # Manual server configuration (Digital Ocean)

    Parameters
    * <username>
    * <ssh-key>


    ## Update system
    ```
    apt-get update && apt-get dist-upgrade -y
    apt-get autoremove -y
    ```


    ## Add new user
    ```
    useradd -d /home/<username> -m -s /bin/bash <username>
    usermod -a -G adm,cdrom,sudo,dip,plugdev <username>
    ```

    Copy root authorized_keys to no <username>.

    ```
    mkdir /home/<username>/.ssh
    cp /root/.ssh/authorized_keys /home/<username>/.ssh/
    chmod 600 /home/<username>/.ssh/authorized_keys
    chown -R <username>:<username> /home/<username>/.ssh
    ```

    Run visudo and add the following line at the end of the file.
    ```
    visudo
    <username> ALL=(ALL) NOPASSWD: ALL
    ```

    Logout and log back in as <username>. Password-less sudo ftw.

    Create ssh-key

    ```
    ssh-keygen -t rsa -C "[email protected]"
    cat ~/.ssh/id_rsa.pub
    ```


    ## Install packages
    ```
    apt-get install -y \
    build-essential \
    python-software-properties \
    python \
    g++ \
    make \
    fail2ban \
    apache2-utils \
    curl \
    git \
    ntp \
    ntpdate
    ```


    ## Install NodeJS
    ```
    curl -sL https://deb.nodesource.com/setup_dev | sudo bash -
    apt-get install -y nodejs
    ```

    Update npm.

    ```
    npm update -g
    ```

    Install bower.

    ```
    npm -g install bower
    ```


    ## Install Composer
    ```
    curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
    ```


    ## Create default htpasswd file
    ```
    htpasswd -c /etc/default/htpasswd <htpasswd-username>
    ```

    ## Install Nginx
    ```
    add-apt-repository ppa:nginx/development
    apt-get update && apt-get install nginx-full -y
    ```


    ## Configure Nginx
    Check number of cores to set worker_processes.

    ```
    grep processor /proc/cpuinfo | wc -l
    ```

    Check core limit for number of connections.

    ```
    ulimit -n
    ```

    Configure Nginx accordingly.

    ```
    worker_processes <number-of-cores>;
    worker_connections <core-limit>;
    multi_accept on;
    server_tokens off;
    server_names_hash_bucket_size 64;
    server_name_in_redirect off;
    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 2;
    gzip_buffers 16 8k;
    gzip_min_length 1100;
    gzip_http_version 1.1;
    gzip_types text/plain text/plain text/css application/json application/x-javascript text/xml application/xml application/rss+xml text/javascript image/svg+xml application/x-font-ttf font/opentype application/vnd.ms-fontobject;
    access_log off;
    client_body_buffer_size 10K;
    client_header_buffer_size 1k;
    client_max_body_size 8m;
    client_header_timeout 12;
    client_body_timeout 12;
    keepalive_timeout 15;
    send_timeout 10;
    large_client_header_buffers 2 1k;
    ```

    Disable default host.

    ```
    rm /etc/nginx/sites-enabled/default
    ```

    Restart Nginx.

    ```
    service nginx restart
    ```


    ## Configure Nginx vhost
    Create config file for virtual host.

    ```
    pico /etc/nginx/sites-available/<domain-name>.conf
    ```

    ```
    server {
    listen 80;
    root /var/www/<domain-name>/public/;
    index index.php index.html index.htm;
    server_name _ <domain-name>;
    location / {
    try_files $uri $uri/ /index.php?$query_string;
    auth_basic "Restricted";
    auth_basic_user_file /etc/default/htpasswd;
    }
    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_intercept_errors on;
    }
    }
    # Redirect www to non-www
    server {
    server_name www.<domain-name>;
    return 301 http://<domain-name>;
    }
    ```

    Create public directory in site folder.

    ```
    mkdir -p /var/www/<domain-name>/public
    ```

    Fix correct owner.

    ```
    chown -R <username>:<username> /var/www/<domain-name>
    ```

    Enable vhost.

    ```
    ln -s /etc/nginx/sites-available/<domain-name>.conf /etc/nginx/sites-enabled/<domain-name>.conf
    ```

    Restart Nginx.

    ```
    service nginx restart
    ```


    ## Install PHP
    ```
    apt-get install -y \
    php5-common \
    php5-mysqlnd \
    php5-xmlrpc \
    php5-curl \
    php5-gd \
    php5-cli \
    php5-fpm \
    php5-dev \
    php5-imap \
    php5-mcrypt \
    php5-memcache \
    php5-sqlite \
    php-pear \
    memcached \
    imagemagick
    ```


    ## Configure PHP
    Adjustments for php-fpm is based on the 2GB Digital Ocean setup.

    ```
    pico /etc/php5/fpm/pool.d/www.conf
    ```

    ```
    listen.owner = www-data
    listen.group = www-data
    pm.max_children = 12
    pm.start_servers = 4
    pm.min_spare_servers = 2
    pm.max_spare_servers = 6
    ```

    ```
    pico /etc/php5/fpm/php.ini
    ```

    ```
    post_max_size = 64M
    upload_max_filesize = 64M
    date.timezone = Europe/Stockholm
    session.save_handler = memcache
    session.save_path = unix:/tmp/memcached.sock
    mysql.default_socket = /var/run/mysqld/mysqld.sock
    ```

    Enable mcrypt.

    ```
    php5enmod mcrypt
    ```


    ## Configure Memcached
    Configure Memcached to use socket instead of TCP service.

    ```
    pico /etc/memcached.conf
    ```

    ```
    # Remove the following.
    -p 11211
    -l 127.0.0.1
    # Add the following instead.
    -s /tmp/memcached.sock
    -a 666
    ```


    ## Install MySQL
    ```
    aptitude install -y \
    mysql-server \
    mysql-client
    ```


    ## Install PHPMyAdmin
    ```
    apt-get install -y phpmyadmin
    ```

    Add PHPMyAdmin configuration to default host.

    ```
    location /phpmyadmin {
    root /usr/share/;
    index index.php index.html index.htm;
    location ~ ^/phpmyadmin/(.+\.php)$ {
    include snippets/fastcgi-php.conf;
    root /usr/share/;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_intercept_errors on;
    }
    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
    root /usr/share/;
    }
    }
    location /phpMyAdmin {
    rewrite ^/* /phpmyadmin last;
    }
    ```