Lumenを試したときのちょっとした構築メモ。
Lumen
Laravelの作者 Taylor Otwell(元マイクロソフト)が作ったmicro framework。
「美味い、安い、速い」という牛丼のようなWAF。公式HP
選んだ理由
- PHPだしぃ〜(学習が簡単)
- シンプルだしぃ〜(micro frameworkを自称するだけあって必要最小限の機能)
- 速そうだしぃ〜(PHPのクセに高速な動作を謳っている)
- オサレ!(゚∀゚)
環境
仮想環境:vagrant
OS:Ubuntu 14.04.5
言語:PHP7.1
Webサーバー:nginx/1.12.1
手順メモ
PHP7.1とExtensionをインストール
リポジトリを追加。
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
本体とExtensionをインストール
$ sudo apt-get install php7.1 php7.1-fpm php7.1-mbstring php7.1-xml php7.1-zip
Composerインストール
$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo chmod +x /usr/local/bin/composer
Lumenをインストール
$ cd /srv/www
$ composer create-project --prefer-dist laravel/lumen sample
nginx設定
最小限の設定だけしてみる。
/etc/nginx/nginx.conf
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile off;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
/etc/nginx/conf.d/default.conf
server {
listen 80;
server_name lumensample.local;
root /srv/www/sample/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
fpmの設定
/etc/php/7.1/fpm/pool.d/www.conf
listen.owner = www-data ←nginxのconfで設定したuserにしておく
listen.group = www-data
listen.mode = 0660
サービス再起動
$ sudo service php7.1-fpm restart
$ sudo service nginx restart
ブラウザでアクセス
hostsにlumensample.localを追加。
ブラウザのURLにhttp://lumensample.localを入力してアクセス。
↓みたいなバージョンが表示されればOK.
お手軽!!