| 环境 | IP | 应用 | yum源 | 
| Redhat8 | 192.168.248.131 | apache | 本地 | 
| Redhat8 | 192.168.248.132 | mysql | 本地 | 
| Redhat8 | 192.168.248.133 | php | 阿里云 | 
这里已经下好apache,apr,apr-util软件包就不再下载了
[root@localhost ~]# tar -xf apr-1.7.0.tar.bz2 
[root@localhost ~]# tar -xf apr-util-1.6.1.tar.gz 
[root@localhost ~]# tar -xf  httpd-2.4.46.tar.gz 
[root@localhost ~]# ls
anaconda-ks.cfg  apr-1.7.0.tar.bz2  apr-util-1.6.1.tar.gz  httpd-2.4.46.tar.gz
apr-1.7.0        apr-util-1.6.1     httpd-2.4.46
#安装依赖环境
[root@localhost ~]# yum  -y groups mark install ‘Development Tools‘
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
#安装apr
[root@localhost ~]# cd apr-1.7.0
[root@localhost apr-1.7.0]# vim configure
    cfgfile="${ofile}T"
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    # $RM "$cfgfile"        //将此行加上注释,或者删除此行
[root@localhost apr-1.7.0]# ./configure  --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make && make install
#安装apr-util
[root@localhost apr-1.7.0]# cd /root/apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ./configure  --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# make && make install
#安装httpd
[root@localhost httpd-2.4.46]# cd /root/httpd-2.4.46
[root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/apache > --sysconfdir=/etc/httpd24 > --enable-so > --enable-ssl > --enable-cgi > --enable-rewrite > --with-zlib > --with-pcre > --with-apr=/usr/local/apr > --with-apr-util=/usr/local/apr-util/ > --enable-modules=most > --enable-mpms-shared=all > --with-mpm=prefork
[root@localhost httpd-2.4.46]# make && make install
#安装后配置
[root@localhost ~]#  echo ‘export PATH=/usr/local/apache/bin:$PATH‘ > /etc/profile.d/httpd.sh
[root@localhost ~]#  source /etc/profile.d/httpd.sh
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost ~]# vim /etc/man_db.conf
[root@localhost ~]#  vim /etc/httpd24/httpd.conf
........................
ServerName www.example.com:80   #取消此行注释
..........................
#启动apache
[root@localhost ~]# apachectl  start
[root@localhost ~]# ss -antl
State         Recv-Q        Send-Q                Local Address:Port                 Peer Address:Port        
LISTEN        0             128                         0.0.0.0:22                        0.0.0.0:*           
LISTEN        0             128                               *:80                              *:*           
LISTEN        0             128                            [::]:22                           [::]:*
#安装依赖包 [root@mysql ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs #创建用户和组 [root@mysql ~]# useradd -r -M -s /sbin/nologin mysql #下载二进制mysql [root@mysql ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz #解压缩 [root@mysql ~]# tar -xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@mysql ~]# ln -sv /usr/local/mysql-5.7.31-linux-glibc2.12-x86_64/ /usr/local/mysql ‘/usr/local/mysql‘ -> ‘/usr/local/mysql-5.7.31-linux-glibc2.12-x86_64/‘ [root@mysql ~]# cd /usr/local/ [root@mysql local]# chown -R mysql.mysql mysql* #添加环境变量 [root@mysql local]# echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/myslq.sh [root@mysql local]# source /etc/profile.d/myslq.sh [root@mysql local]# echo $PATH /usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@mysql local]# ln -s /usr/local/mysql/include/ /usr/include/mysql [root@mysql local]# vi /etc/man_db.conf #MANDATORY_MANPATH /usr/src/pvm3/man # MANDATORY_MANPATH /usr/man MANDATORY_MANPATH /usr/share/man MANDATORY_MANPATH /usr/local/share/man MANDATORY_MANPATH /usr/local/mysql/man #添加man路径 [root@mysql local]# vi /etc/ld.so.conf.d/msqly.conf /usr/local/mysql/lib [root@mysql local]# ldconfig
创建存放数据库目录
[root@mysql ~]# mkdir /mydata [root@mysql ~]# chown -R mysql.mysql /mydata
初始化数据库
[root@mysql local]# mysqld --initialize --user=mysql --datadir=/mydata 2021-01-07T12:47:02.142821Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-01-07T12:47:02.630687Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-01-07T12:47:02.694936Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-01-07T12:47:02.761896Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 70a6e6ab-50e6-11eb-939f-000c299aa5a9. 2021-01-07T12:47:02.764453Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened. 2021-01-07T12:47:04.032275Z 0 [Warning] CA certificate ca.pem is self signed. 2021-01-07T12:47:04.727274Z 1 [Note] A temporary password is generated for root@localhost: OC8!IE3XhDia
配置文件
[root@mysql local]# vi /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /mydata
socket = /tmp/mysql.sock
port = 3306
pid-file = /mydata/mysql.pid
user = mysql
skip-name-resolve
#配置服务启动脚本
[root@mysql local]# cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
[root@localhost support-files]# vi /etc/init.d/mysqld
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
 
basedir=/usr/local/mysql
datadir=/mydata
#启动mysql修改密码
[root@mysql local]# service  mysqld start
Starting MySQL.Logging to ‘/mydata/mysql.err‘.
 SUCCESS! 
[root@mysql local]# mysql -uroot -p‘OC8!IE3XhDia‘
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> set password = password(‘123‘)
    -> ;
Query OK, 0 rows affected, 1 warning (0.00 sec)
配置源
#yum源 [root@localhost ~]wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo [root@localhost ~]sed -i -e ‘/mirrors.cloud.aliyuncs.com/d‘ -e ‘/mirrors.aliyuncs.com/d‘ /etc/yum.repos.d/CentOS-Base.repo [root@localhost ~]sed -i ‘s|$releasever|8|‘ /etc/yum.repos.d/CentOS-Base.repo #epel源 [root@localhost ~]yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm [root@localhost ~][root@ansible ~]# sed -i ‘s|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|‘ /etc/yum.repos.d/epel* [root@localhost ~]sed -i ‘s|^metalink|#metalink|‘ /etc/yum.repos.d/epel* [root@localhost ~]sed -i ‘s|$releasever|8|‘ /etc/yum.repos.d/epel*
安装依赖包
[root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php-mysqlnd [root@localhost ~]# yum -y install php-* [root@localhost ~]# php -v PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.24, Copyright (c) 1999-2018, by Zend TechnologiesZZ
[root@localhost ~]# vi /etc/php-fpm.d/www.conf
......................
;listen = /run/php-fpm/www.sock #注释此行
listen = 0.0.0.0:9000  #添加监听端口
...........................
........................... 
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
listen.allowed_clients = 192.168.248.131  #安装apache主机的ip
.................
#生成测试页面
[root@localhost ~]# vi /var/www/html/index.php
<?php
        phpinfo();
?>
[root@localhost ~]# chown -R apache.apache /var/www/html/
[root@localhost ~]# vim /etc/httpd24/httpd.conf
#搜索AddType
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php          #添加此行
    AddType application/x-httpd-php-source .phps      #添加此行
#搜索proxy.so
#LoadModule remoteip_module modules/mod_remoteip.so
LoadModule proxy_module modules/mod_proxy.so                  //取消注释
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so      //取消注释
#搜索index.html
 DirectoryIndex index.php  index.html #添加index.php
#在配置文件的最后加入以下内容
<VirtualHost *:80>
        DocumentRoot "/usr/local/apache/htdocs/"
        ServerName  www.testhhhh.com
        ProxyRequests   Off
        ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.248.133:9000/var/www/html/$1   #php页面路径
        <Directory "/usr/local/apache/htdocs">
                Options none
                AllowOverride none
                Require all granted
        </Directory>
</VirtualHost>
重启服务
[root@localhost ~]# apachectl restart [root@localhost ~]# systemctl restart php-fpm
 
 
原文:https://www.cnblogs.com/diqiyao/p/14248366.html