Skip to content

Instantly share code, notes, and snippets.

@yu81
Last active October 22, 2015 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yu81/4ddafe488f0bece58c28 to your computer and use it in GitHub Desktop.
Save yu81/4ddafe488f0bece58c28 to your computer and use it in GitHub Desktop.
#!/bin/bash -xv
# Initialize Amazon Linux AMI 2015.03 for PHP5 Web Application
# yum
# update default
sudo yum upgrade --enablerepo="*" -y
# install php
for i in $(seq 3)
do
[ ! -s remi-release-6.rpm ] && curl --connect-timeout 3 http://remi.kazukioishi.net/enterprise/remi-release-6.rpm > remi-release-6.rpm
done
sudo yum localinstall -y remi-release-6.rpm
sudo yum install unixODBC -y
sudo yum install scl-utils --enablerepo="*" -y
sudo yum install httpd --enablerepo="*" -y
sudo yum install mysql -y
sudo yum install php php-common --enablerepo="remi,remi-php56" --disablerepo="amzn*" -y
sudo yum install php php-{fpm,bcmath,cli,common,debuginfo,json,ldap,litespeed,mbstring,mysqlnd,odbc,opcache,pdo,pecl-{lzf,lzf-debuginfo,msgpack,uuid,uuid-debuginfo,xmldiff,redis},process,zip} --enablerepo="epel*,remi,remi-test,remi-php56*" --disablerepo="amzn*" -y
sudo yum install php-pecl-redis --enablerepo="remi,remi-test,remi-php56*" --disablerepo="amzn*" -y
# install others
sudo yum install nginx --enablerepo="remi,remi-test,remi-php56*" -y
sudo yum install git --enablerepo="epel*,remi,remi-test,remi-php56*" -y
sudo yum install tig --enablerepo="epel*,remi,remi-test,remi-php56*" -y
sudo yum install redis --enablerepo="epel*,remi,remi-test,remi-php56*" --disablerepo="amzn*" -y
sudo yum install perl gawk bash zsh sed wget s3cmd rsync htop dstat memcached spawn-fcgi --enablerepo="*" -y
# New Relic
[ ! -s newrelic-repo-5-3.noarch.rpm ] && curl 'http://download.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm' > newrelic-repo-5-3.noarch.rpm
sudo yum localinstall newrelic-repo-5-3.noarch.rpm -y
sudo yum install newrelic-sysmond -y
sudo nrsysmond-config --set license_key=LICENSE_KEY # LICENSE_KEY required
sudo /etc/init.d/newrelic-sysmond start
sudo chkconfig newrelic-sysmond on
sudo yum install newrelic-php5 -y
sudo newrelic-install install
# Additional manual configration required for New Relic.
# See below.
# https://docs.newrelic.com/docs/agents/php-agent/installation/php-agent-installation-redhat-centos
# https://docs.newrelic.com/docs/agents/php-agent/advanced-installation/php-agent-installation-non-standard-php-advanced
# edit php.ini
if [ -s /etc/php.ini ]; then
timezone_exists=$(sudo cat /etc/php.ini | egrep "^date.timezone = " | head -1 | awk '{if($1 ~ /date\.timezone/){print "true"}else{print "false";}}')
if [ "${timezone_exists:-_false}" != "true" ]; then
echo 'date.timezone = "Asia/Tokyo"' |
sudo cat /etc/php.ini - > ./php.ini.new
sudo cp -p /etc/php.ini /etc/php.ini.bak.$(date +%Y%m%d%H%M%S)
sudo mv -f ./php.ini.new /etc/php.ini
fi
fi
# Install composer for global.
if [ ! -s ~/.composer/composer.phar ]; then
mkdir ~/.composer
pushd ~/.composer
wget https://getcomposer.org/composer.phar
if [ -s composer.phar ]; then
# Install psysh
php composer.phar global require psy/psysh:dev-master
# Install Laravel
php composer.phar global require "laravel/installer=~1.1"
# Install Lumen
php composer.phar global require "laravel/lumen-installer=~1.0"
php composer.phar update
fi
popd
echo 'export PATH=$HOME/.composer/vendor/bin:$PATH' >> .bash_profile
source .bash_profile
fi
# FuelPHP
curl 'http://get.fuelphp.com/oil' | sh
# TODO : configuration of nginx,php-fpm
# add www user
sudo groupadd www
sudo useradd www -g www
sudo chown -R www:www /var/www
sudo chmod 2775 /var/www
sudo find /var/www -type d -exec sudo chmod 2775 {} +
sudo find /var/www -type f -exec sudo chmod 0664 {} +
# override php-fpm.d/www.conf
sudo cp -p /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.bat.$(date +%Y%m%d%H%M%S)
wget https://gist.githubusercontent.com/YU81/375a0e91b9cfd15d4f2c/raw/php-fpm_d_www.conf
sudo cp -p php-fpm_d_www.conf /etc/php-fpm.d/www.conf
# override nginx.conf
sudo cp -p /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak.$(date +%Y%m%d%H%M%S)
wget https://gist.githubusercontent.com/YU81/b1b7ce53389374ca2711/raw/fuelphp_nginx.conf
sudo cp -p fuelphp_nginx.conf /etc/nginx/nginx.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment