服务器上配置YYF生产环境
"一键部署"
- Centos (rpm系列):
curl -#L https://yyf.newfuture.cc/assets/code/server-centos.sh |bash
- Ubuntu (deb系列):
curl -#L https://yyf.newfuture.cc/assets/code/server-ubuntu.sh |bash
对于“裸机”可以直接选择对应的系统运行后面的命令自动安装和配置(包括 apache,php,mysql或mariadb,和yaf扩展)。
注意: 服务器上使用生产环境(product)配置,同时配置文件会一直缓存在内存中(更新配置需重启PHP进程)。
1. Centos 上默认配置
curl -#L https://yyf.newfuture.cc/assets/code/server-centos.sh |bash
使用系统默源进行安装httpd和php和数据库,不同版本系统安装的结果会不一样。
组件 | centos 6.x | centos 7.x | |
---|---|---|---|
httpd(apache) | 2.2 | 2.4 | |
PHP 版本 | <=5.4 | 5.5 或5.6 | |
数据库 | mysql | mariadb |
如果代码有误可以在GITHUB上修改
#!/usr/bin/env bash
PROJECT_PATH="/var/www/YYF"
TEMP_PATH="/tmp/"
CONF_PATH="/etc/httpd/conf/httpd.conf"
# sudo yum -y update
#################################
###[LAMP]
### 安装 apache php mysql
################################
# install httpd
# 安装 apache php gcc和git
sudo yum install -y httpd git \
php php-opcache php-pdo_mysql php-mcrypt php-mbstring php-curl \
php-devel gcc
# 安装mysql或者mariadb 会二者选一
sudo yum install -y mysql-server mariadb-server
#################################
###[YAF_EXTENTSION]
### 安装 yaf
################################
#判断yaf版本和php版本
#check the version of php and yaf
PHP_VERSION=$(php -v|grep --only-matching --perl-regexp "\d\.\d+\.\d+"|head -1);
if [[ ${PHP_VERSION} == "7."* ]]; then
#php 7
YAF_VERSION=yaf-3.0.3
else
#php 5
YAF_VERSION=yaf-2.3.5
fi;
# 下载解压yaf
# download yaf
curl https://pecl.php.net/get/${YAF_VERSION}.tgz | tar zx -C $TEMP_PATH
# 编译安装 YAF
# compile and install YAF
cd ${TEMP_PATH}${YAF_VERSION} && phpize;
./configure && make && sudo make install
# 配置yaf(product 环境)
# configure yaf with product environment
sudo tee /etc/php.d/yaf.ini> /dev/null <<EOF
extension=yaf.so
[yaf]
yaf.environ=product
yaf.cache_config = 1
EOF
# configure the apache(httpd)
# 配置apache开机启动
sudo systemctl start httpd.service
sudo systemctl enable httpd
#防火墙允许httpd 部分系统有效
sudo firewall-cmd --permanent --add-service=http
# httpd webroot
# 配置 apache 根目录
sudo cp $CONF_PATH ${CONF_PATH}.back
sudo sed -i.back -e "s|\"/var/www/html\"|\"${PROJECT_PATH}/public\"|g" $CONF_PATH
# clone YYF and initialize
# clone 代码 初始化
if [ ! -f $PROJECT_PATH ]; then
sudo mkdir -p ${PROJECT_PATH}
fi;
sudo chown $UID ${PROJECT_PATH}
git clone https://github.com/YunYinORG/YYF.git ${PROJECT_PATH}
echo 0 | ${PROJECT_PATH}/init.cmd
#重启apache服务器
#restart apache
sudo service httpd restart
2. Ubuntu 上默认配置
curl -#L https://yyf.newfuture.cc/assets/code/server-ubuntu.sh |bash
使用系统默源进行安装apache,msyql和PHP (ubuntu 16.04及以上会自动安装php7)
如果代码有误可以在GITHUB上修改
#!/usr/bin/env bash
PROJECT_PATH="/var/www/YYF"
TEMP_PATH="/tmp/"
echo " UPDATE..."
sudo apt update
#&>$TEMP_PATH/yyf_install.log
#################################
###[LAMP]
### 安装 apache php
################################
#apache
echo "INSTALL apache"
sudo apt-get -y install apache2 gcc git &>>$TEMP_PATH/yyf_install.log
echo "INSTALL php"
#php7
sudo apt-get -y install php php-curl php-pdo-sqlite php-pdo-mysql php-dev libapache2-mod-php &>>$TEMP_PATH/yyf_install.log
#php5
sudo apt-get -y install php5 php5-mcrypt php5-curl php5-sqlite php5-mysql php5-dev libpcre3-dev &>>$TEMP_PATH/yyf_install.log
# httpd webroot
sudo tee /etc/apache2/sites-available/yyf.conf> /dev/null <<EOF
DocumentRoot "${PROJECT_PATH}/public"
<Directory "${PROJECT_PATH}/public">
Options FollowSymLinks
AllowOverride all
Require all granted
</Directory>
EOF
sudo a2ensite yyf.conf
sudo a2dissite 000-default.conf
sudo a2enmod php*
sudo a2enmod rewrite
#################################
###[YAF_EXTENTSION]
################################
# check PHP version
PHP_VERSION=$(php -v|grep --only-matching --perl-regexp "\d\.\d+\.\d+"|head -1);
if [[ ${PHP_VERSION} == "7."* ]]; then
#php 7
YAF_VERSION=yaf-3.0.3
else
#php 5
YAF_VERSION=yaf-2.3.5
fi;
# download yaf
# 下载解压yaf
curl https://pecl.php.net/get/${YAF_VERSION}.tgz | tar zx -C $TEMP_PATH
# 编译安装 YAF
# compile and install YAF
cd $TEMP_PATH${YAF_VERSION} && phpize
./configure && make && sudo make install
## 创建yaf配置文件(product 环境)
## create temp yaf conifg with product environment
cat <<EOF>${TEMP_PATH}yaf.ini
extension=yaf.so
[yaf]
yaf.environ=product
yaf.cache_config = 1
EOF
# 获取 PHP ini 配置目录
# Scan for additional .ini path
PHP_INI_PATH=$(php --ini|grep --only-matching --perl-regexp "/.*\.d$")
PHP_INI_PATH=$(echo $PHP_INI_PATH | sed -r -e 's/cli/*/')
# 复制配置文件到各个目录
# cp the yaf configure to each file
echo $PHP_INI_PATH | xargs -n 1 sudo cp $TEMP_PATH/yaf.ini
# 删除临时文件
# remove temp ini
rm ${TEMP_PATH}yaf.ini
#################################
###[YYF]
### 下载YYF
################################
# clone YYF and initialize
# clone 代码 初始化
if [ ! -f $PROJECT_PATH ]; then
sudo mkdir -p ${PROJECT_PATH}
fi;
sudo chown $UID ${PROJECT_PATH}
git clone https://github.com/YunYinORG/YYF.git ${PROJECT_PATH}
echo 0 | ${PROJECT_PATH}/init.cmd
#重启apache服务器
#restart apache
sudo service apache2 restart
MYSQL_SERVER=$(dpkg -l | grep -c "mysql-server")
if [ ${MYSQL_SERVER} -gt 1 ] ;then
echo "mysql-server was installed"
else
echo "INSTALL mysql-server"
# 静默安装mysql,不显示密码框
echo mysql-server mysql-server/root_password password | sudo debconf-set-selections
echo mysql-server mysql-server/root_password_again password | sudo debconf-set-selections
sudo apt install -y mysql-server
fi;