目录
前言:
Apache在LAMP里主要实现的功能:
Mysql在LAMP里实现的作用:
PHP在LAMP里的功能:
php 的工作模式
FastCGI 方式安装 php(192.168.10.6主机)
Mysql的编译安装(192.168.10.4主机)
apache的编译安装:(192.168.10.3主机)
测试 LAMP 环境
测试访问 php 测试页
部署Discuz论坛
CGI 模式下 ,即通用网管接口服务器有多少个连接请求就有多少个cgi子进程,运行 PHP ,性能低下。
FastCGI 方式 PHP 是一处独立的进程,所有 PHP 子进程都由 PHP 的一个叫作 php-fpm 的组件负责管理;而 apache 模块化方 式运行的 PHP ,则是 apache 负责调用 PHP 完成工作。性能比fastcgi差很多
主机规划
编译安装 mysql
脚本如下
#!/bin/bash
#name:auto_install_php
#date 2019年12月21日11:32:59
echo '安装前提软件...'
yum -y install libxml2-devel lzip2-devel libcurl-devel libmcrypt-devel openssl-devel bzip2-devel
echo '解压编译libmcrypt...'
cd /usr/src
tar zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure --prefix=/usr/local/libmcrypt && make && make install
echo '安装php...'
cd /usr/src
tar zxf php-5.6.27.tar.gz
cd php-5.6.27/
./configure --prefix=/usr/local/php5.6 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts && make && make install
#提供 php 配置文件
cp /usr/src/php-5.6.27/php.ini-production /etc/php.ini
#为 php-fpm 提供脚本并设置开机自启
cd /usr/src/php-5.6.27/
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
#提供 php-fpm 配置文件并编辑
cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf
sed -i 's:;pid = run/php-fpm.pid:pid = run/php-fpm.pid:' /usr/local/php5.6/etc/php-fpm.conf
sed -i 's/listen = 127.0.0.1:9000/listen = 192.168.10.6:9000/' /usr/local/php5.6/etc/php-fpm.conf
sed -i 's/pm.max_children = 5/pm.max_children = 100/' /usr/local/php5.6/etc/php-fpm.conf
sed -i 's/pm.start_servers = 2/pm.start_servers = 10/' /usr/local/php5.6/etc/php-fpm.conf
sed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 10/' /usr/local/php5.6/etc/php-fpm.conf
sed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 50/' /usr/local/php5.6/etc/php-fpm.conf
#启动php-fpm服务
service php-fpm start
[root@phpserver ~]# mkdir -p /var/www/benet
脚本如下:
#!/bin/bash
#date 2019年12月22日18:08:51
#named:auto_install_mysql
#由于没有下载mysql源码包,所以提前准备好
echo '正在下载资源包...'
yum -y install ncurses-devel gcc gcc-c++ wget make
read -p '你想要的Cmake版本:' VER
wget https://github.com/Kitware/CMake/releases/download/v$VER/cmake-$VER.tar.gz
tar zxf cmake-$VER.tar.gz -C /usr/src
cd /usr/src/cmake-$VER
echo '正在编译安装...'
./configure &> /dev/null
gmake && gmake install &> /dev/null
#创建mysql的用户和组
groupadd mysql
useradd -M -s /sbin/nologin mysql -g mysql
cd /usr/src
tar zxf /mysql-5.6.36.tar.gz
cd mysql-5.6.36/
echo '预编译中...'
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all &> /dev/null
echo '正在编译安装...'
make -j8 && make install -j8 &> /dev/null
echo '对数据库目录进行授权:'
chown -R mysql:mysql /usr/local/mysql
echo '建立配置文件:'
rm -rf /etc/my.cnf
cp support-files/my-default.cnf /etc/my.cnf
#echo '安装Perl模块...'
#如果提示初始化数据库失败,自己手动去掉注释,删掉已安装的软件包,再运行一边脚本
#yum -y install perl-Data-Dumper &> /dev/null
echo '初始化数据库...'
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
echo '设置环境变量:'
echo "PATH=$PATH://usr/local/mysql/bin" >> /etc/profile
. /etc/profile
#mysql 的启动和关闭:
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start
#/etc/init.d/mysqld是一个shell脚本,在启动过程中会调用mysqld_safe脚本,最后调用mysqld服务启动mysql,如下所示.
#$bindir/mysql_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1
netstat -anpt | grep 3306
cat << EOF
****************************************
* Mysql has been installed successfully. *
****************************************
EOF
#!/bin/bash
yum -y install zlib-* make gcc gcc-c++ m4 ncurses-devel kernel-devel
cd /usr/src
tar zxf apr-1.5.2.tar.gz
cd apr-1.5.2/
./configure --prefix=/usr/local/apr && make && make install
cd ..
tar zxf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install
cd ..
tar zxf pcre-8.39.tar.gz
cd pcre-8.39/
./configure --prefix=/usr/local/pcre && make && make install
cd ..
tar zxf openssl-1.0.1u.tar.gz
cd openssl-1.0.1u/
./config -fPIC --prefix=/usr/local/openssl enable-shared && make && make install
mv /usr/bin/openssl /usr/bin/openssl.1.0.1e
ln -s /usr/local/openssl//bin/openssl /usr/bin/openssl
cd /usr/src
tar zxf httpd-2.4.25.tar.gz
cd httpd-2.4.25
./configure --prefix=/usr/local/httpd --enable-so --enable-cgi --enable-cgid --enable-ssl --with-ssl=/usr/local/openssl --enable-rewrite --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=event --enable-proxy --enable-proxy-fcgi --enable-expires --enable-deflate && make && make install
#优化httpd路径
ln -s /usr/local/httpd/bin/* /usr/local/bin
#添加系统服务
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
sed -i '2a\# chkconfig: 35 85 15\n#' /etc/init.d/httpd
chkconfig --add httpd
systemctl start httpd
systemctl enable httpd
netstat -anpt | grep httpd
cat << EOF
******************************************************
* Httpd has been installed and started successfully. *
******************************************************
EOF
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
[root@www ~]# mkdir -p /var/www/benet
启用 Include conf/extra/httpd-vhosts.conf //这一步千万不能忘
同时定位 AddType;添加下面两行:让 apache 能识别 php 格式的页面
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html #添加 index.php(最好添加在最前面)
开启虚拟主机支持使用fcgi,编辑httpd-vhosts.conf
[root@www ~]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
ServerAdmin [email protected]
DocumentRoot "/var/www/benet"
ServerName www.benet.com
ServerAlias benet.com
ErrorLog "logs/benet.com-error_log"
CustomLog "logs/benet.com-access_log" common
ProxyRequests Off //关闭正向代理
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://192.168.10.6:9000/var/www/benet/$1 //把以.php 结尾的文件请求发送到 php-fpm 进程
#
# ProxyPass fcgi://192.168.10.6:9000/var/www/benet //通过 mod_proxy_fcgi 来转发的代理,使用 fastCGI 协议,转到PHP-FPM 监听的端口。
#
//添加用户访问权限
Options FollowSymLinks
AllowOverride None
Require all granted
复制Discuz包到apache和php服务器的/var/www/benet目录,解压并赋权(步骤一样)
unzip Discuz_7.0.0_FULL_SC_UTF8.zip
mv upload/ /var/www/benet/bbs
chmod -R 777 /var/www/benet/bbs
short_open_tag = On
保存退出
service php-fpm restart
在mysql服务器上创建bbs数据库及用户
mysql> create database bbsdb;
mysql> grant all on bbsdb.* to runbbs@'%' identified by 'pwd@123';
mysql> exit
访问Apache,安装discuz论坛