编译安装实现LAMP
1. 实现基于fastcgi模式下的编译安装
实现CentOS 7 编译安装基于 fastcgi 模式的多虚拟主机的wordpress和discuz的LAMP架构
2. 实验环境
两台主机:
- 一台主机:httpd+php(fastcgi模式)
- 一台主机:mariadb 服务器
软件版本:
- mariadb-10.2.29-linux-x86_64.tar.gz 通用二进制格式
- apr-1.7.0.tar.bz2
- apr-util-1.6.1.tar.bz2
- httpd-2.4.41.tar.gz
- php-7.3.10.tar.bz2
- wordpress-5.3-zh_CN.tar.gz
- Discuz_X3.4_SC_UTF8【20190917】.zip
3. 实现步骤
3.1 二进制安装mariadb
[root@centos7 ~]# useradd -r -s /sbin/nologin mysql
[root@centos7 data]# tar xf mariadb-10.2.29-linux-x86_64.tar.gz -C /usr/local/
[root@centos7 data]# cd /usr/local/
[root@centos7 local]# chown -R mysql.mysql mariadb-10.2.29-linux-x86_64/
[root@centos7 local]# ln -s mariadb-10.2.29-linux-x86_64/ mysql
[root@centos7 local]# mkdir /data/mysql
[root@centos7 local]# chown -R mysql.mysql /data/mysql/
[root@centos7 local]# mkdir /etc/mysql
[root@centos7 local]# cp mysql/support-files/my-huge.cnf /etc/mysql/my.cnf
[root@centos7 local]# vim /etc/mysql/my.cnf
[mysqld]
#加三行
datadir =/data/mysql
skip_name_resolve = ON
#修改sock文件路径为/data/mysql/mysql.sock
#准备PATH变量
[root@centos7 local]# vim /etc/profile.d/lamp.sh
PATH=/usr/local/mysql/bin/:$PATH
[root@centos7 local]# . /etc/profile.d/lamp.sh
[root@centos7 local]# yum install -y libaio
[root@centos7 local]# cd mysql
[root@centos7 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
[root@centos7 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@centos7 mysql]# chkconfig --add mysqld
[root@centos7 mysql]# service mysqld start
#为wordprss和discuz应用准备数据库和用户帐号
mysql -uroot
mysql> create database wordpress;
mysql> create database discuz;
mysql> grant all on wordpress.* to wpuser@'192.168.8.%' identified by "wppass";
mysql> grant all on discuz.* to discuz@'192.168.8.%' identified by 'dispass';
3.2 编译安装httpd
#安装相关包
[root@centos7 mysql]# yum install -y gcc pcre-devel openssl-devel expat-devel
#编译安装httpd
[root@centos7 lamp]# tar xf apr-1.7.0.tar.bz2
tar (child): lbzip2: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
[root@centos7 lamp]# yum install bzip2
[root@centos7 lamp]# tar xvf apr-1.7.0.tar.bz2
[root@centos7 lamp]# tar xvf apr-util-1.6.1.tar.bz2
[root@centos7 lamp]# tar xf httpd-2.4.41.tar.gz
[root@centos7 lamp]# mv apr-1.7.0 httpd-2.4.41/srclib/apr
[root@centos7 lamp]# mv apr-util-1.6.1 httpd-2.4.41/srclib/apr-uti
[root@centos7 lamp]# cd httpd-2.4.41/
./configure \
--prefix=/app/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-included-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
[root@centos7 httpd-2.4.41]# make -j 2 && make install
#准备PATH变量
[root@centos7 httpd-2.4.41]# vim /etc/profile.d/lamp.sh
PATH=/app/httpd24/bin:$PATH
[root@centos7 httpd-2.4.41]# . /etc/profile.d/lamp.sh
#创建和配置用户和组
[root@centos7 httpd-2.4.41]# useradd -s /sbin/nolgin -r -u 88 apache
[root@centos7 httpd-2.4.41]# vim /app/httpd24/conf/httpd.conf
user apapche
group apache
#修改为event模式
LoadModule mpm_event_module modules/mod_mpm_event.so
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
[root@centos7 httpd-2.4.41]# httpd -M | grep mpm
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::243a:c30d:a2c2:406e%eth0. Set the 'ServerName' directive globally to suppress this message
mpm_event_module (shared)
[root@centos7 httpd-2.4.41]# apachectl start
3.3 编译安装fastcgi 方式的 php7.3
#安装相关包,依赖EPEL源
#php 7.3 相关包
yum install gcc libxml2-devel bzip2-devel libmcrypt-devel
#php 7.4 相关包
yum install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel
oniguruma-devel
编译:
[root@centos7 lamp]# tar xf php-7.3.10.tar.xz
[root@centos7 lamp]# cd php-7.3.10/
[root@centos7 php-7.3.10]# ./configure --prefix=/app/php73 \
> --enable-mysqlnd \
> --with-mysqli=mysqlnd \
> --with-pdo-mysql=mysqlnd \
> --with-openssl \
> --with-freetype-dir \
> --with-jpeg-dir \
> --with-png-dir \
> --with-zlib \
> --with-libxml-dir=/usr \
> --with-config-file-path=/etc \
> --with-config-file-scan-dir=/etc/php.d \
> --enable-mbstring \
> --enable-xml \
> --enable-sockets \
> --enable-fpm \
> --enable-maintainer-zts \
> --disable-fileinfo
#php7.4 编译
tar xvf php-7.4.0.tar.xz
cd php-7.4.0/
./configure \
--prefix=/app/php74 \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-zlib \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
[root@centos7 php-7.3.10]# make -j 2 && make install
#准备PATH变量
[root@centos7 php-7.3.10]# vim /etc/profile.d/lamp.sh
PATH=/app/php73/bin:/app/httpd24/bin:$PATH
[root@centos7 php-7.3.10]# . /etc/profile.d/lamp.sh
#准备php配置文件和启动文件
[root@centos7 php-7.3.10]# cp php.ini-production /etc/php.ini
[root@centos7 php-7.3.10]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
[root@centos7 php-7.3.10]# cd /app/php73/etc/
[root@centos7 etc]# cp php-fpm.conf.default php-fpm.conf
[root@centos7 php-fpm.d]# cp www.conf.default www.conf
#修改进程所有者
[root@centos7 php-fpm.d]# vim www.conf
user apache
group apache
#支持status和ping页面
pm.status_path = /status
ping.path = /ping
#支持opcache加速
[root@centos7 php-fpm.d]# mkdir /etc/php.d
[root@centos7 php-fpm.d]# vim /etc/php.d/opcache.ini
[opcache]
zend_extension=opcache.so
opcache.enable=1
[root@centos7 php-fpm.d]# systemctl daemon-reload
[root@centos7 php-fpm.d]# systemctl status php-fpm.service
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@centos7 php-fpm.d]# systemctl enable --now php-fpm.service
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
3.4 修改配置httpd 支持php-fpm
[root@centos7 php-fpm.d]# vim /app/httpd24/conf/httpd.conf
#取消下面两行的注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
#修改下面行
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
#加下面三行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
#实现两个虚拟主机
<virtualhost *:80>
servername wordpress.magedu.org
documentroot /data/wordpress
<directory /data/wordpress>
require all granted
</directory>
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/wordpress/$1
#实现status和ping页面
ProxyPassMatch ^/(status|ping)$ fcgi://127.0.0.1:9000/$1
CustomLog "logs/access_wordpress_log" common
</virtualhost>
<virtualhost *:80>
servername discuz.magedu.org
documentroot /data/discuz
<directory /data/discuz/>
require all granted
</directory>
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/discuz/$1
CustomLog "logs/access_discuz_log" common
</virtualhost>
3.5 准备wordpress和discuz! 相关文件
#准备wordpress程序文件
mkdir /data/
tar xvf wordpress-5.3-zh_CN.tar.gz
mv wordpress/ /data
setfacl –R –m u:apache:rwx /data/wordpress/
#或者chown –R apache.apache /data/wordpress
#准备discuz!程序文件
unzip Discuz_X3.4_SC_UTF8【20190917】.zip
mkdir /data/discuz
mv upload/* /data/discuz
setfacl -R -m u:apache:rwx /data/discuz/
3.6 测试访问
vim /etc/hosts
192.168.8.100 wordpress.magedu.org discuz.magedu.org