#!/bin/bash
#######################################################################
#
#                安裝 LAMP in 5 minutes  for CentOS 7
#
#				Original Date: 2015.03.24
#				Last Updated:  2015.10.29
#				Author: Raymond Chou
#
#########################################################################

rm -fr /var/run/yum.pid

###########  step1: 安裝 httpd       #####
echo -e "step1: 安裝 httpd .............\n\n"
yum -y install httpd
systemctl start httpd.service
systemctl enable httpd.service
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
#systemctl restart firewalld
firewall-cmd --reload


###########  step:  關閉Firewall     #####
#echo -e "step:  關閉Firewall.............\n\n"
#systemctl stop firewalld.service
#systemctl disable firewalld.service


###########  step2: 安裝 mariaDB     #####
echo -e "step2: 安裝 mariaDB .............\n\n"
yum -y install mariadb-server mariadb
systemctl start mariadb.service
systemctl enable mariadb.service
#create other user & database
for var in joe angela
do
  sqlcmd="CREATE DATABASE ${var}DB CHARACTER SET utf8 COLLATE utf8_general_ci;";
  mysql -uroot -e "$sqlcmd"
  sqlcmd="CREATE USER '${var}'@'localhost' IDENTIFIED BY '123456';";
  mysql -uroot -e "$sqlcmd"
  sqlcmd="GRANT ALL PRIVILEGES ON ${var}DB.* TO '${var}'@'localhost' WITH GRANT OPTION;"
  mysql -uroot -e "$sqlcmd"
  #echo $sqlcmd;
done
mysqladmin -u root password '123456'
 #mysql -uroot -e "DROP DATABASE test;"


###########  step3: 安裝 php     #####
echo -e "step3: 安裝 php .............\n\n"
yum -y install php php-mysql php-gd php-pear php-mbstring php-pgsql
systemctl restart httpd.service


###########  step4: 安裝 phpmyadmin     #####
echo -e "step4: 安裝 phpmyadmi .............\n\n"
rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
yum -y install phpmyadmin
 #yum -y update
sed -i 's/Require ip 127.0.0.1/#Require ip 127.0.0.1/g' /etc/httpd/conf.d/phpMyAdmin.conf
sed -i ':a;N;$!ba;s/Require ip ::1/#Require ip ::1\n\tRequire all granted/g' /etc/httpd/conf.d/phpMyAdmin.conf
systemctl reload httpd.service


#!/bin/bash
#######################################################################
#
#                架設 FTP Server
#
#				Original Date: 2016.06.22
#				Last Updated:  2016.06.22
#				Author: Raymond Chou
#
#########################################################################
#Step1. 安裝FTP Server
yum -y install vsftpd

#Step2. 修改vsftpd.conf檔的參數, 並啟動FTP server
sed -i 's/anonymous_enable=YES/anonymous_enable=NO/g' /etc/vsftpd/vsftpd.conf
sed -i 's/#chroot_local_user=YES/chroot_local_user=YES/g' /etc/vsftpd/vsftpd.conf
echo allow_writeable_chroot=YES >> /etc/vsftpd/vsftpd.conf
echo pasv_enable=Yes >> /etc/vsftpd/vsftpd.conf
#啟動FTP server
systemctl enable vsftpd
systemctl start vsftpd

#Step3. 開啟防火牆對ftp的封瑣
firewall-cmd --permanent --add-service=ftp
firewall-cmd --reload

#Step4. 更新 FTP的SELinux boolean值
setsebool -P ftp_home_dir on



#!/bin/bash
#######################################################################
#
#                設定個人帳戶的home Page & 指定至 /var/www/html
#
#				Original Date: 2016.06.22
#				Last Updated:  2016.06.22
#				Author: Raymond Chou
#
#########################################################################

#Step1. 解開UserDir參數
sed -i 's/UserDir disabled/#UserDir disabled/g' /etc/httpd/conf.d/userdir.conf
sed -i 's/#UserDir public_html/UserDir public_html/g' /etc/httpd/conf.d/userdir.conf
sed -i 's/AllowOverride FileInfo AuthConfig Limit Indexes/AllowOverride All/g' /etc/httpd/conf.d/userdir.conf
sed -i 's/Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec/Options None/g' /etc/httpd/conf.d/userdir.conf
#重啟動httpd
systemctl restart httpd


#Step2. 製作david的public_html
mkdir /home/david/public_html
chown david.david /home/david/public_html
chmod 755 /home/david

#Step3. 將系統的Web root指向david的public_html
cd /var/www
mv html html.old
ln -s /home/david/public_html html



