The Application Server

Setup an Application Server

We'll start by creating a production server which will run a PHP applicaiton. This will be a server we deploy an application to.

Install

Let's install all the things specific to our PHP application.

# Ensure basics are installed (already done earlier)
sudo apt-get install -y vim curl tmux wget unzip htop

# Add repositories for latest software
sudo apt-get install -y software-properties-common
sudo add-apt-repository -y ppa:nginx/stable
sudo add-apt-repository -y ppa:ondrej/php5-5.6

# Update and install Nginx + PHP
sudo apt-get update

sudo apt-get install -y nginx php5-fpm php5-cli php5-mcrypt php5-curl \
                              php5-mysql php5-pgsql php5-sqlite \
                              php5-gd php5-memcached \
                              mysql-server-5.6

sudo mysql_secure_installation

Configure PHP

Let's configure PHP-FPM to run as our login-user:

Copy file /etc/php5/fpm/pool.d/www.conf to /etc/php5/fpm/pool.d/series.conf.

Adjust the following items:

[series] # Instead of [www]

user = serial
group = serial

listen: /var/run/php5-fpm-serial.sock

We've setup a separate php-fpm pool for user serial to use for it's applications. Let's reload PHP5-FPM to let that take affect:

sudo service php5-fpm restart

Configure Nginx

Copy default:

cd /etc/nginx/sites-available
sudo cp default serial

Remove default site from "enabled":

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

Enable our new one:

sudo ln -s /etc/nginx/sites-available/serial /etc/nginx/sites-enabled/serial

Edit the default to run our new site:

server {
    listen 80 default_server;

    index index.htm index.html index.php;

    root /home/serial/serialapp/current/public;

    server_name serialapp.com www.serialapp.com serialapp.dev;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php5-fpm-serial.sock;
    }
}

We should make the directory that this points to:

sudo mkdir -p /home/serial/serialapp/current/public

Then we can add a default file in that location to serve as we get started.

Create file /home/serial/serialapp/current/public/index.php with the following content:

<?php
phpinfo();

Then test and reload our configuration:

sudo -u serial mkdir ~/serialapp/current/public

sudo service nginx configtest
sudo service nginx reload

You should be able to see the phpinfo() dump when you head to your server in the browser.