Dependency
- Setup Timezone
- Initialized CentOS Server
- Setup NginX
Option
Script
# Setup Timezone
function isinstalled {
if yum list installed | grep "$@"; then
true
else
false
fi
}
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
if isinstalled "ntp"; then
echo "Install ntp .......... [${GREEN}OK${RESET}]";
else
yum install ntp -y;
mv /etc/localtime /etc/localtime.bak
ln -s /usr/share/zoneinfo/Asia/Bangkok /etc/localtime
ntpd
chkconfig ntpd on
echo "Install ntp .......... [${GREEN}Installed${RESET}]";
fi
# Initialized CentOS Server
yum groupinstall "Development tools" -y
yum install nano wget -y
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel -y
yum install libjpeg-devel freetype-devel libpng-devel -y
yum install libxml2-devel libxslt-devel -y
yum install epel-release -y
setenforce 0
# TODO: disable
# nano /etc/selinux/config
# SELINUX=disabled
# Setup NginX
function isinstalled {
if yum list installed | grep "$@"; then
true
else
false
fi
}
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
if isinstalled "nginx"; then
echo "Install nginx .......... [${GREEN} OK ${RESET}]";
else
yum install nginx -y;
cat <<EOT > /etc/nginx/nginx.conf
user nginx;
worker_processes {{ NGINX_PROCESSES }};
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
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 on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
server_names_hash_bucket_size 64;
}
EOT
mkdir -p /etc/nginx/sites-available
chkconfig nginx on
service nginx start
echo "Install nginx .......... [${GREEN} Installed ${RESET}]";
fi
# Install PHP on NginX (With MySQL extension)
yum install php-fpm php-mysql -y
chkconfig php-frm on
cat <<EOT > /etc/nginx/conf.d/default.conf
server {
listen 80 default_server;
server_name _;
include /etc/nginx/default.d/*.conf;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
EOT
cat <<EOT > /etc/php-fpm.d/www.conf
; Start a new pool named 'www'.
[www]
listen = 127.0.0.1:9000
;listen.backlog = -1
listen.allowed_clients = 127.0.0.1
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0666
user = nginx
group = nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
;pm.max_requests = 500
;pm.status_path = /status
;ping.path = /ping
;ping.response = pong
;request_terminate_timeout = 0
;request_slowlog_timeout = 0
slowlog = /var/log/php-fpm/www-slow.log
;rlimit_files = 1024
;rlimit_core = 0
;chroot =
;chdir = /var/www
;catch_workers_output = yes
;security.limit_extensions = .php .php3 .php4 .php5
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp
;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
;php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 128M
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
EOT
service php-frm start
service nginx restart