Skip to content

Instantly share code, notes, and snippets.

@ahmadnassri
Last active March 4, 2019 19:04
Show Gist options
  • Save ahmadnassri/4248198 to your computer and use it in GitHub Desktop.
Save ahmadnassri/4248198 to your computer and use it in GitHub Desktop.
Typical PHP/Nginx Setup on a Debian server

do everything as root

sudo su

update system:

apt-get update
apt-get upgrade

reboot:

shutdown -r now

install web components

apt-get -y install git nginx php5-fpm php5-cli php5-dev php5-curl php5-imagick php5-mcrypt php5-mysql php5-geoip php5-tidy php5-xsl php5-xmlrpc php5-xdebug php5-apcu php-pear build-essential libpcre3-dev uuid-dev libcurl4-openssl-dev

PHP Extensions:

pecl install oauth uuid pecl_http jsonc
echo "extension=http.so" >> /etc/php5/mods-available/http.ini
echo "extension=oauth.so" >> /etc/php5/mods-available/oauth.ini
echo "extension=uuid.so" >> /etc/php5/mods-available/uuid.ini
echo "extension=json.so" >> /etc/php5/mods-available/json.ini

php5enmod opcache pdo apcu curl geoip imagick mysqli mysql pdo_mysql readline tidy xdebug xmlrpc xsl http json uuid oauth

setup directories:

mkdir /var/www
sudo chown -R `whoami`:www-data /var/www
chmod -R ug+rw /var/www

setup Nginx config:

nano /etc/nginx/sites-available/default.conf
service php5-fpm restart
service nginx restart

Note: set the APPLICATION_ENV to match the environment (production, staging, development)

server {
    listen 80 default_server;

    server_name _;

    return 444;
}

server {
    listen 80;

    server_name www.domain.com;

    root /var/www/public;

    error_log /var/log/nginx/error.log warn;
    access_log /var/log/nginx/access.log combined;

    # do not log static assets
    location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|eot)$ {
        #expires max;
        access_log off;
    }

    # opt-in to the future
    add_header "X-UA-Compatible" "IE=Edge,chrome=1";

    # security through obscurity
    server_tokens off;

    index index.php;

    try_files $uri @rewrite;

    location @rewrite {
        rewrite ^ /index.php last;
    }

    location ~* \.php$ {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_param APPLICATION_ENV "production";
        include fastcgi_params;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment