Skip to content

Instantly share code, notes, and snippets.

@asaokamei
Created April 8, 2015 08:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save asaokamei/2d82ab52309642ddcf2f to your computer and use it in GitHub Desktop.
Save asaokamei/2d82ab52309642ddcf2f to your computer and use it in GitHub Desktop.
Vagrant + Nginx + Php-fpm/ZTS
#!/usr/bin/env bash
###
echo "Provisioning Start"
apt-get -y update > /dev/null
###
echo "Installing nginx"
apt-get -y install nginx > /dev/null
cp /vagrant/nginx/www.conf /etc/nginx/sites-available > /dev/null
ln -s /etc/nginx/sites-available/www.conf /etc/nginx/sites-enabled/www.conf
rm -rf /etc/nginx/sites-enabled/default
service nginx start
###
echo "Installing PHP"
#apt-get -y install php5-common php5-dev php5-cli php5-fpm > /dev/null
#apt-get -y install php5-curl php5-mcrypt php5-mysql php5-pgsql > /dev/null
###
echo "Installing MySql"
apt-get -y install debconf-utils > /dev/null
debconf-set-selections <<< "mysql-server mysql-server/root_password password root"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password root"
apt-get -y install mysql-server > /dev/null
service mysql start
#apt-get -y install phpmyadmin > /dev/null
if ! [ -L /var/www ]; then
rm -rf /var/www
ln -fs /vagrant/www /var/www
fi
# 参考
# 「Nginx向けにPHPをソースコードからインストール」
# http://qiita.com/HayneRyo/items/7eb4578138677067cd6d
# http://qiita.com/monkick@github/items/610d1435d812beb853e2
# install build tools
wget http://launchpadlibrarian.net/140087283/libbison-dev_2.7.1.dfsg-1_amd64.deb
wget http://launchpadlibrarian.net/140087282/bison_2.7.1.dfsg-1_amd64.deb
dpkg -i libbison-dev_2.7.1.dfsg-1_amd64.deb
dpkg -i bison_2.7.1.dfsg-1_amd64.deb
# install PHP source
cd /usr/src
mkdir php-5.6.7
cd php-5.6.7
wget http://jp1.php.net/get/php-5.6.7.tar.gz/from/this/mirror
mv mirror php-5.6.7.tar.gz
tar zxvf php-5.6.7.tar.gz
# build php5-fpm
cd php-5.6.7/
apt-get -y install libxml2-dev
./configure --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --prefix=/opt/php-zts --with-config-file-path=/opt/php-zts/etc --enable-maintainer-zts --with-mysql --with-mysqli --enable-pthreads --enable-mbstring
make
make install
echo "extension=pthreads.so" > /opt/php-zts/modules.d/pthreads.ini
# configure
cd sapi/fpm/
cp init.d.php-fpm /etc/init.d/php-fpm
cp php-fpm.conf /opt/php-zts/etc/php-fpm.conf
vi /opt/php-zts/etc/php5-fpm.conf
pid = run/php-fpm.pid
error_log = /var/log/php5-fpm.log
listen /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode 0660
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.hostname = "web-dev"
# port-forwarding is easier. access by http://localhost:8080
# config.vm.network "forwarded_port", guest: 80, host: 8080, id: "nginx"
# access by some private network. http://192.168.33.10
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.provision "shell", path: "provision.sh"
end
server {
listen 80;
server_name trusty.localhost
sendfile off;
location / {
root /var/www;
index index.php index.html;
try_files $uri $uri/ =404;
}
location ~ \.php$ {
root /var/www;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment