Skip to content

Instantly share code, notes, and snippets.

@hello-forsharing-todu
Last active March 7, 2018 06:47
Show Gist options
  • Select an option

  • Save hello-forsharing-todu/00f8902ceca06be12eae893dc376d35b to your computer and use it in GitHub Desktop.

Select an option

Save hello-forsharing-todu/00f8902ceca06be12eae893dc376d35b to your computer and use it in GitHub Desktop.
Nginx, Php-fpm, Redis, Postgresql
#!/bin/bash
#================#
# For CentOS 7.0 #
#================#
######## CONFIG ##########
user="forsharing"
router="index.php"
serverRoot="/home/forsharing/server/public"
domain="localhost"
timezone="Asia/Ho_Chi_Minh"
##########################
useradd $user
# Repos
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
rpm -Uvh http://nginx.org/packages/mainline/centos/7/x86_64/RPMS/nginx-1.13.9-1.el7_4.ngx.x86_64.rpm
# Installation
yum install rsync nginx redis php70w-fpm php70w-gd php70w-mbstring php70w-pecl-xdebug php70w-pgsql php70w-bcmath php70w-opcache php70w-mcrypt php70w postgresql10-server postgresql10-devel wget -y
#php-fpm configuration
sed -i "s@;date.timezone =@date.timezone = $timezone@g" /etc/php.ini
sed -i "s@display_errors = Off@display_errors = On@g" /etc/php.ini
sed -i "s@html_errors = On@html_errors = Off@g" /etc/php.ini
sed -i "s@;catch_workers_output =@catch_workers_output =@g" /etc/php-fpm.d/www.conf
sed -i "s@;php_flag\[display_errors\] = off@php_flag\[display_errors\] = on@" /etc/php-fpm.d/www.conf
# permissions
sed -i "s@user nginx@user $user@g" /etc/nginx/nginx.conf
sed -i "s@user = apache@user = $user@g" /etc/php-fpm.d/www.conf
sed -i "s@group = apache@group = $user@g" /etc/php-fpm.d/www.conf
sed -i "s@group = apache@group = $user@g" /etc/php-fpm.d/www.conf
sed -i "s@SELINUX=enforcing@SELINUX=disabled@g" /etc/sysconfig/selinux
setenforce 0
mkdir -p $serverRoot
echo "
<?php
echo '<h1>Server configured successfully!</h1>';
" > $serverRoot/$router
chown $user /home/$user -R
chgrp $user /home/$user -R
rm -f /etc/nginx/conf.d/*
echo "
server {
listen 80;
server_name l localhost $domain www.$domain;
root $serverRoot;
index $router;
location / {
try_files \$uri \$uri/ /$router;
}
location ~ \.php$ {
fastcgi_index $router;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
}
}
" > /etc/nginx/conf.d/server.conf
#firewall
firewall-cmd --permanent --add-port=22/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
systemctl restart firewalld
# start at boot
systemctl enable php-fpm
systemctl enable redis
systemctl enable nginx
# run them
systemctl start php-fpm
systemctl start redis
systemctl start nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment