john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

Nginx php fpm composer dependency slim framework

sudo apt-get install nginx # ubuntu 12.04

vi /etc/nginx/nginx.conf # do nothing as the defaults are fine, # NOTE THERE IS A KNOWN CRAPPY ISSUE: # YOU CANNOT CHANGE THE LOG DIRECTORY (yes the config file is misleading) # IF NEEDED LOL: --prefix when compiling nginx

vi /etc/nginx/sites-available/default # example with the default index.html on port 80 vi /etc/nginx/sites-enabled/default # symlink to the sites-available/default ls /usr/share/nginx/www # index.html and 50x.html

sudo service nginx start

http://localhost/ # Welcome to nginx!


NOTE: nginx, PHP (and memcached) communicate over TCP UNLESS unix sockets are enabled (performance)

php5-fpm default user is www-data

sudo apt-get install php5-cgi php5-fpm # optionally: php-cli (run scripts directly), php5-gd (create images from code), php5-mcrypt (crypto), php5-suhosin (security), php-apc (caching), php5-curl (cURL in php)

vi /etc/nginx/fastcgi_params # no change necessary

vi /etc/php5/fpm/pool.d/www.conf

;listen = 127.0.0.1:9000 # comment out the TCP listen = /var/run/php5-fpm.sock # enable a socket based connection to nginx or other processes

note that /var/run/php5-fpm.pid contains the pid of the php5-fpmmaster


mkdir /var/run/php5-fpm vi /etc/nginx/sites-available/default # this is where most changes occur (i.e. enabling php)

server { server_name localhost;
root /var/www;
index index.php;

    location ~ \.php$ {
    try_files $uri $uri/ /index.php?$args =404;     # if not matching these then  404
            fastcgi_pass unix:/var/run/php5-fpm.socket;
            fastcgi_index index.php;
            include /etc/nginx/fastcgi_params;
    }

}

ps aux | grep nginx service nginx stop # or /etc/init.d/nginx reload then restart then status ps aux | grep nginx ps aux | grep php /etc/init.d/php5-fpm stop # or service php5-fpm stop

/etc/init.d/nginx start # http://localhost/ returns "502 bad gateway" because nginx cannot reach php, also check /etc/init.d/php5-fpm start # http://localhost returns hello world (newlines in the source do not become break in html =)


vi /var/www/index.php

nginx-php-fpm hello <?php echo 'world' ?>



Composer: PHP dependency management

Slim micro REST framework

cd /var/www # To only install locally for a specific project

curl -s https://getcomposer.org/installer | php #!/usr/bin/env php All settings correct for using Composer Downloading...

Composer successfully installed to: /home/ubuntu/Desktop/docs/repos/php/example/composer.phar
 Use it: php composer.phar

vi /var/www/composer.json { "require": { "slim/slim": "2.*" } }

php composer.phar install Loading composer repositories with package information Installing dependencies - Installing slim/slim (2.2.0) Downloading: 100%

Writing lock file
Generating autoload files

vi /var/www/index.php <?php require 'vendor/autoload.php'; $app = new \Slim\Slim(); $app->get( '/', function() { # for a REST GET request return hi world echo 'hi world'; });

$app->run(); ?>

not sure if /etc/init.d/nginx restart and /etc/init.d/php5-fpm restart is required, but cat /var/log/nginx/error.log

http://docs.slimframework.com/ (careful of the nginx configs)



INTERESTING

sudo apt-get install memcached php5-memcache

 ## Deny illegal Host headers. 
 # if ($host !~* ^(mydomain.com|www.mydomain.com)$ ) {
 #  return 405;
 # }
## Only requests to our Host are allowed 
#      if ($host !~ ^($server_name)$ ) {        # using a variable is usually better
#         return 444;
#      }

## Deny certain User-Agents (case insensitive) ## The ~ makes it case insensitive as opposed to just a ~ # if ($http_user_agent ~ (Baiduspider|Jullo) ) { # return 405; # }

## Deny certain Referers (case insensitive) ## The ~ makes it case insensitive as opposed to just a ~ # if ($http_referer ~ (nudit|porn|sex) ) { # etc. # return 405; # }

Only allow these request methods

Do not accept DELETE, SEARCH and other methods

if ($request_method !~ ^(GET|HEAD|POST)$ ) {

return 444;

}

http://arstechnica.com/information-technology/2012/12/web-served-part-3-bolting-on-php-with-php-fpm/


  • « oxygen agent factory
  • Nginx static files slim php require import class »

Published

Jun 3, 2013

Category

linux

~455 words

Tags

  • composer 1
  • dependency 3
  • fpm 1
  • framework 3
  • installs 41
  • nginx 7
  • php 82
  • slim 3