#!/bin/bash
# configure local yum repo
cat > /etc/yum.repos.d/yum_local.repo << EOF
[yum_local]
name=yum_local
baseurl=http://192.168.1.61
gpgcheck=0
enabled=1
EOF
yum clean all
yum makecache
# add user www for web service
useradd -u 1111 -s /sbin/nologin -M www
# install nginx and configure
yum install nginx -y
systemctl start nginx
systemctl enable nginx
sed -i "s#user nginx;#user www;#g" /etc/nginx/nginx.conf
# install php
yum install php73-php php73-php-cli php73-php-common php73-php-devel php73-php-embedded php73-php-json php73-runtime -y
yum install php73-php-gd php73-php-mbstring php73-php-pdo php73-php-xml -y
yum install php73-php-fpm php73-php-mysqlnd php73-php-opcache -y
yum install php73-php-pecl-memcached php73-php-pecl-redis5 php73-php-pecl-mongodb -y
# backup php configuration
cp /etc/opt/remi/php73/php.ini{,.backup}
cp /etc/opt/remi/php73/php-fpm.conf{,.backup}
cp /etc/opt/remi/php73/php-fpm.d/www.conf{,.backup}
# modify php-fpm user www
sed -i "s#user = apache#user = www#g" /etc/opt/remi/php73/php-fpm.d/www.conf
sed -i "s#group = apache#group = www#g" /etc/opt/remi/php73/php-fpm.d/www.conf
# configure nginx support php
mv /etc/nginx/conf.d/default.conf{,.backup}
cat > /etc/nginx/conf.d/www.conf << EOF
server {
listen 80;
server_name www.will.com;
root /usr/share/nginx/html/www;
error_page 404 /404.html;
location / {
index index.php index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
}
EOF
# create website test code
mkdir -p /usr/share/nginx/html/www
chown -R www.www /usr/share/nginx/html/www
cd /usr/share/nginx/html/www
echo $(hostname -I) > index.php
echo "<br><br>" >> index.php
echo "<?php phpinfo(); ?>" >> index.php
echo "status: 404" > 404.html
echo "<br><br>" >> 404.html
echo $(hostname -I) >> 404.html
# start php-fpm
systemctl start php73-php-fpm
systemctl enable php73-php-fpm
# restart nginx
systemctl restart nginx