Skip to content

Instantly share code, notes, and snippets.

@als15
Created May 16, 2016 12:08
Show Gist options
  • Save als15/23bf07ee36f3ab8e486b1a8f51796199 to your computer and use it in GitHub Desktop.
Save als15/23bf07ee36f3ab8e486b1a8f51796199 to your computer and use it in GitHub Desktop.
#!/bin/bash
# provision a new centos 7 machine with a LEMP stach using a custom built nginx
cd /tmp
yum update -y
# epel repo
yum install -y epel-release
# remi repo
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
#--------------
# install nginx
#--------------
yum groupinstall -y "Development Tools"
yum install -y pcre-devel zlib-devel openssl-devel
yum install -y GeoIP-devel
wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar -xzf nginx-1.6.2.tar.gz
#wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
#tar -xzf ngx_cache_purge-2.3.tar.gz
#wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.zip
#unzip 2.3.zip
cd nginx-1.6.2
./configure --user=nginx --group=nginx --sbin-path=/usr/sbin --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --http-log-path=/var/log/nginx/access.log --with-debug --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module --with-http_dav_module --with-http_geoip_module --with-ipv6 --add-module=/tmp/ngx_cache_purge-2.3
make
make install
useradd -s /sbin/nologin nginx
wget -O /etc/init.d/nginx https://gist.github.com/sairam/5892520/raw/b8195a71e944d46271c8a49f2717f70bcd04bf1a/etc-init.d-nginx
chmod +x /etc/init.d/nginx
# setup nginx autostart
chkconfig nginx on
#add to logrotate
wget -O /etc/logrotate.d/nginx https://raw.githubusercontent.com/scottydelicious/Nginx-CentOS-6-init-script/master/etc/logrotate.d/nginx
# open port 80 and 443
systemctl start firewalld
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --permanent --zone=public --add-port=443/tcp
firewall-cmd --reload
# adjust nginx configuration
wget -O /etc/nginx/nginx.conf https://gist.githubusercontent.com/giladaya/079f2dca296d466a5aec/raw/nginx.conf
# TODO: wget nginx.conf from repo
#geoIP
cd /tmp
mkdir -p /usr/share/GeoIP
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip GeoIP.dat.gz
mv GeoIP.dat /usr/share/GeoIP/
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gz
mv GeoLiteCity.dat /usr/share/GeoIP/
service nginx start
#--------------
# install mysql
#--------------
sudo rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
yum install -y mysql mysql-server
service mysqld start
# unattended mysql_secure_installation
mysql -e "UPDATE mysql.user SET Password = PASSWORD('bobolobo123') WHERE User = 'root'"
mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
mysql -e "DELETE FROM mysql.user WHERE User='';"
mysql -e "DROP DATABASE test;"
mysql -e "FLUSH PRIVILEGES;"
# setup mysql autostart
chkconfig --level 235 mysqld on
#------------
# install php
#------------
yum install -y php-fpm php-cli php-mysqlnd php-gd php-pear php-xml php-xmlrpc php-magickwand php-mbstring php-snmp php-tidy php-imap php-ldap php-mcrypt php-curl
# setup php-fpm autostart
chkconfig --level 235 php-fpm on
# some config changes
mkdir -p /var/run/php_sessions
chown nginx /var/run/php_sessions
wget -O /etc/php-fpm.d/www.conf https://gist.githubusercontent.com/giladaya/079f2dca296d466a5aec/raw/www.conf
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php.ini
f
service php-fpm start
#TODO: opcode cache?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment