Skip to content

Instantly share code, notes, and snippets.

@basoro
Last active June 26, 2018 05:04
Show Gist options
  • Save basoro/54fbfea1cbcf6884a360df54774b72e4 to your computer and use it in GitHub Desktop.
Save basoro/54fbfea1cbcf6884a360df54774b72e4 to your computer and use it in GitHub Desktop.
Fast and Dirty Nginx, PHP-FPM 5.6 and MySQL 5.5 for Centos 6.x
#!/bin/bash
###################
# disable selinux #
###################
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g'/etc/selinux/config
##############################
# disable un-needed services #
##############################
service httpd stop
chkconfig httpd off
service xinetd stop
chkconfig xinetd off
service saslauthd stop
chkconfig saslauthd off
service sendmail stop
chkconfig sendmail off
service rsyslog stop
#Work around OpenVZ's memory allocation limits (if on OpenVZ)
if [ -e "/proc/user_beancounters" ]
then
echo "* soft stack 256" >/etc/security/limits.conf
sed -i 's/plugins=1/plugins=0/' /etc/yum.conf
fi
#remove all current PHP, MySQL, mailservers, rsyslog.
yum -y remove httpd php mysql rsyslog sendmail postfix mysql-libs
###################
# Add a few repos #
###################
# nginx repo
rpm -Uvh http://nginx.org/packages/rhel/6/noarch/RPMS/nginx-release-rhel-6-0.el6.ngx.noarch.rpm
# epel-release repo
yum -y install epel-release
# php56 repo
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
################################
# Install PHP, NGINX and MySQL #
################################
yum -y install nginx
yum -y install mysql55w mysql55w-server
yum -y install php56w-fpm php56w-mysql php56w-gd php56w-xml php56w-process
########################################
# Install Postfix, SyLog-Ng and Cronie #
########################################
yum -y install postfix syslog-ng cronie
yum -y install libdbi
yum -y install libdbi-drivers
yum -y install libdbi-dbd-mysql
yum -y install syslog-ng-libdbi
yum -y install zip unzip
########################
# install MySQL config #
########################
cat > /etc/my.cnf <<END
[mysqld]
default-storage-engine = myisam
key_buffer = 1M
query_cache_size = 1M
query_cache_limit = 128k
max_connections=25
thread_cache=1
skip-innodb
query_cache_min_res_unit=0
tmp_table_size = 1M
max_heap_table_size = 1M
table_cache=256
concurrent_insert=2
max_allowed_packet = 1M
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 64K
END
echo Do not worry if you see a error stopping MySQL
/etc/init.d/mysqld stop
###################
# Configure nginx #
###################
cat > /etc/nginx/php <<END
index index.php index.html index.htm;
location ~ \.php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
try_files \$uri =404;
fastcgi_pass 127.0.0.1:9000;
error_page 404 /404page.html; #makes nginx return it's default 404
# page instead of a blank page
}
END
cat > /etc/nginx/nginx.conf <<END
user nginx nginx;
worker_processes 1;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
}
http {
include mime.types;
default_type application/octet-stream;
client_max_body_size 64M;
sendfile on;
tcp_nopush on;
keepalive_timeout 3;
gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
server_tokens off;
include /etc/nginx/conf.d/*;
}
END
rm /etc/nginx/conf.d/*
cat > /etc/nginx/conf.d/default.conf <<END
server {
listen 80 default;
server_name _;
root /var/www/html;
include php;
}
server {
listen 8888;
server_name localhost;
root /var/www/panel;
include php;
}
END
#install php-fpm config
cat > /etc/php-fpm.d/www.conf <<END
[www]
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
user = nginx
group = nginx
pm = ondemand
pm.process_idle_timeout = 3s
pm.max_children = 5
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1
pm.max_requests = 500
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_admin_value[upload_max_filesize] = 32M
END
#Create directories
mkdir /var/www
mkdir /var/www/html/
mkdir /var/www/logs/
mkdir /usr/share/nginx/logs/
chown -R nginx:nginx /var/www/html/
#add users, start services and configure iptables
service php-fpm start
chkconfig php-fpm on
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp --dport 8888 -j ACCEPT
service iptables save
chkconfig syslog-ng on
service syslog-ng start
chkconfig crond on
service crond start
service nginx restart
chkconfig nginx on
chkconfig mysqld on
service mysqld start
echo 'nginx ALL=(ALL) NOPASSWD: ALL' | sudo EDITOR='tee -a' visudo
#Fix Sessions:
mkdir /var/lib/php/session
chmod 777 /var/lib/php/session
# add vhost creator script
cat > "/bin/setup-vhost" <<END
#!/bin/bash
if [ -z "\$1" ]
then
echo "Usage: setup-vhost <hostname> (without the www. prefix)"
exit
fi
# Checking Permissions and making directorys
mkdir "/var/www/html/\$1"
chown nginx:nginx -R "/var/www/html/\$1"
# Setting up Nginx mapping
cat > "/etc/nginx/conf.d/\$1.conf" <<EOF
server {
server_name \$1 www.\$1;
root /var/www/html/\$1;
include php;
access_log /var/www/logs/\$1-access.log;
error_log /var/www/logs/\$1-error.log;
}
EOF
service nginx reload
echo vhost created successfully, upload files to /var/www/html/\$1
END
chmod +x /bin/setup-vhost
cat > /var/www/html/index.php <<END
<?php
phpinfo();
?>
END
curl -o panel.zip https://raw.githubusercontent.com/basoro/basoro.github.io/master/panel.zip
unzip panel.zip -d /var/www/
rm -f panel.zip
sleep 3
# Setup tinydns
# Prepare environment
yum -y install gcc make
mkdir -p /usr/local/src/tinydns
# Compile and install daemontools:
cd /usr/local/src/tinydns
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
tar -xzf daemontools-0.76.tar.gz
cd admin/daemontools-0.76/
echo gcc -O2 -include /usr/include/errno.h > src/conf-cc
package/install
# Compile and install djbdns server
cd /usr/local/src/tinydns
wget http://cr.yp.to/djbdns/djbdns-1.05.tar.gz
tar -xzf djbdns-1.05.tar.gz
cd djbdns-1.05/
echo gcc -O2 -include /usr/include/errno.h > conf-cc
make setup check
# Create user account to run tinydns service and logging
/usr/sbin/useradd -s /bin/false tinydns
/usr/sbin/useradd -s /bin/false dnslog
ipaddr=$(curl -s http://whatismyip.akamai.com/)
sleep 3
tinydns-conf tinydns dnslog /etc/tinydns $ipaddr
ln -s /etc/tinydns /service
cat > /etc/init/svscan.conf <<END
start on runlevel [12345]
respawn
exec /command/svscanboot
END
initctl reload-configuration
initctl start svscan
cd /service/tinydns/root
cat > /service/tinydns/root/data <<END
Zdomain.com:ns1.domain.com:hostmaster.domain.com
&domain.com::ns1.domain.com
&domain.com::ns2.domain.com
#define mx for domain
@domain.com::mail.domain.com.:10
#define A for ns1, ns2, amail and www for our dns
+ns1.domain.com:$ipaddr
+ns2.domain.com:$ipaddr
+domain.com:$ipaddr
+*.domain.com:$ipaddr
+www.domain.com:$ipaddr
END
sleep 3
clear
echo Instalasi server selesai.
echo
echo Silahkan akses Panel LEMP di http://ipaddress:8888
echo Username = admin
echo Password = admin
echo
echo Untuk membuat virtual host, jalankan
echo setup-vhost example.com
echo jangan sertakan www
echo
echo
echo run /usr/bin/mysql_secure_installation to set mysql password
echo
echo
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment