环境说明:
系统平台 | IP | 需要安装的服务 |
---|---|---|
redhat | 192.168.102.128 | httpd-2.4 mysql-5.7 php php-mysql |
lamp平台软件安装次序:http–>mysql–>php
注意:PHP要求httpd使用prefork MPM
1. 安装httpd
注意:先将网络源配好。
1.1 安装开发工具包
[root@server ~]# yum -y install epel-release
[root@server ~]# yum groups mark install 'Development Tools'
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
base | 3.6 kB 00:00
centosplus | 3.4 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
(1/5): centosplus/x86_64/primary_db | 2.9 MB 00:04
(2/5): base/x86_64/primary_db | 5.9 MB 00:05
(3/5): base/x86_64/group_gz | 166 kB 00:05
(4/5): extras/x86_64/primary_db | 187 kB 00:05
(5/5): updates/x86_64/primary_db | 5.2 MB 00:07
Marked install: Development Tools
1.2 创建apache服务的用户和组
[root@server ~]# groupadd -r apache
[root@server ~]# useradd -r -M -s /sbin/nologin -g apache apache
1.3安装依赖包
[root@server ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
#安装过程略···
1.4下载和安装apr以及apr-util
[root@server ~]# cd /usr/src/
[root@server src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.5.tar.bz2
#过程略···
[root@server src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
#过程略···
[root@server src]# ls
apr-1.6.5.tar.bz2 apr-util-1.6.1.tar.bz2 debug kernels
[root@server src]# yum -y install bzip2 //安装bzip2
#解压两个包
[root@server src]# tar xf apr-1.6.5.tar.bz2
[root@server src]# tar xf apr-util-1.6.1.tar.bz2
[root@server src]# ls
apr-1.6.5 apr-util-1.6.1 debug
apr-1.6.5.tar.bz2 apr-util-1.6.1.tar.bz2 kernels
[root@server src]# cd apr-1.6.5/
[root@server apr-1.6.5]# vim configure
cfgfile=${ofile}T
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
# $RM "$cfgfile" //加上注释或者删掉
[root@server apr-1.6.5]# ./configure --prefix=/usr/local/apr
#配置过程略···
[root@server apr-1.6.5]# make && make install
#编译安装过程略···
[root@server apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#配置过程略···
[root@server apr-util-1.6.1]# make && make install
编译安装过程略···
1.5编译安装httpd
[root@server ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.34.tar.bz2 //下载软件包(如果包没有了,请根据包前面的网址自行获取包)
[root@server ~]# ls
anaconda-ks.cfg httpd-2.4.34.tar.bz2
[root@server ~]# tar xf httpd-2.4.34.tar.bz2
[root@server ~]# ls
anaconda-ks.cfg httpd-2.4.34 httpd-2.4.34.tar.bz2
[root@server ~]# cd httpd-2.4.34/
[root@server httpd-2.4.34]# ./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@server httpd-2.4.34]# make && make install
#编译安装过程略···
//安装后配置
[root@server httpd-2.4.34]# vim /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
[root@server httpd-2.4.34]# source /etc/profile.d/httpd.sh
[root@server httpd-2.4.34]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@server httpd-2.4.34]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
[root@server httpd-2.4.34]# vim /etc/httpd24/httpd.conf
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName www.example.com:80 //去掉注释
#
# Deny access to the entirety of your server's filesystem. You must
//启动apache
[root@server httpd-2.4.34]# apachectl start
[root@server httpd-2.4.34]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
2.安装MySQL
2.1 安装依赖包
[root@server httpd-2.4.34]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
2.2创建用户和组
[root@server ~]# groupadd -r -g 306 mysql
[root@server ~]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql
2.3下载二级制格式的mysql软件包并解压
[root@server ~]# cd /usr/src/
[root@server src]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz //下载二进制包
[root@server src]# ls
apr-1.6.5 debug
apr-1.6.5.tar.bz2 kernels
apr-util-1.6.1 mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
apr-util-1.6.1.tar.bz2
//解压软件到/usr/local/
[root@server src]# tar xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@server src]# ls /usr/local/
apache bin include libexec share
apr etc lib mysql-5.7.23-linux-glibc2.12-x86_64 src
apr-util games lib64 sbin
2.4修改目录/usr/local/mysql的属主属组
[root@localhost local]# ln -sv mysql-5.7.23-linux-glibc2.12-x86_64/ mysql
[root@server local]# chown -R mysql.mysql /usr/local/mysql
[root@server local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 9月 17 12:31 /usr/local/mysql -> mysql-5.7.23-linux-glibc2.12-x86_64/
2.5添加环境变量
[root@server ~]# ls /usr/local/mysql
bin COPYING docs include lib man README share support-files
[root@server ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@server ~]# . /etc/pro
profile profile.d/ protocols
[root@server ~]# . /etc/profile.d/mysql.sh
[root@server ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
2.6建立数据存放目录
[root@server ~]# mkdir /opt/data
[root@server ~]# chown -R mysql.mysql /opt/data/
[root@server ~]# ll /opt/
总用量 0
drwxr-xr-x. 2 mysql mysql 6 9月 17 13:50 data
2.7初始化数据库
[root@server ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2018-09-17T05:52:56.050088Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-09-17T05:52:58.186950Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-09-17T05:52:58.375927Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-09-17T05:52:58.948910Z 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: ee5aa321-ba3d-11e8-92d4-000c2938489e.
2018-09-17T05:52:58.956148Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-09-17T05:52:58.958181Z 1 [Note] A temporary password is generated for root@localhost: 2r7pygJH+sOp
[root@server ~]# echo '2r7pygJH+sOp' > pass
2.8配置MySQL
[root@server ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
"/usr/local/include/mysql" -> "/usr/local/mysql/include/"
[root@server ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@server ~]# ldconfig -v
略···
2.9生成配置文件
[root@server ~]# cat > /etc/my.cnf <<EOF
> [mysqld]
> basedir = /usr/local/mysql
> datadir = /opt/data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /opt/data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
2.10配置服务
[root@server ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@server ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@server ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld
2.11启动MySQL
[root@server local]# service mysqld start
Starting MySQL.Logging to '/opt/data/server.err'.
SUCCESS!
[root@server local]# ps -ef|grep mysql
root 44994 1 0 14:39 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
mysql 45172 44994 0 14:39 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=server.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root 45203 44547 0 14:41 pts/0 00:00:00 grep --color=auto mysql
[root@server local]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
2.12修改密码
[root@server ~]# cat pass
2r7pygJH+sOp
[root@server ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23
Copyright (c) 2000, 2018, 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('12345678');
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> quit
Bye
3安装PHP
要有网络源,前面已经提过。
3.1安装依赖包
[root@server ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel
#安装过程略···
3.2下载安装PHP
[root@server ~]# cd /usr/src/
[root@server src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
下载过程略···
//编译安装PHP
[root@server src]# tar xf php-7.2.8.tar.xz
[root@server src]# cd php-7.2.8/
[root@server php-7.2.8]# ./configure --prefix=/usr/local/php7 \
> --with-curl \
> --with-freetype-dir \
> --with-gd \
> --with-gettext \
> --with-iconv-dir \
> --with-kerberos \
> --with-libdir=lib64 \
> --with-libxml-dir=/usr \
> --with-mysqli=/usr/local/mysql/bin/mysql_config \
> --with-openssl \
> --with-pcre-regex \
> --with-pdo-mysql \
> --with-pdo-sqlite \
> --with-pear \
> --with-jpeg-dir \
> --with-png-dir \
> --with-xmlrpc \
> --with-xsl \
> --with-zlib \
> --with-config-file-path=/etc \
> --with-config-file-scan-dir=/etc/php.d \
> --with-bz2 \
> --enable-fpm \
> --enable-bcmath \
> --enable-libxml \
> --enable-inline-optimization \
> --enable-mbregex \
> --enable-mbstring \
> --enable-opcache \
> --enable-pcntl \
> --enable-shmop \
> --enable-soap \
> --enable-sockets \
> --enable-sysvsem \
> --enable-xml \
> --enable-zip
[root@server php-7.2.8]# make -j $(cat /proc/cpuinfo |grep processor|wc -l)
编译过程略···
[root@server php-7.2.8]# make install
安装过程略···
3.3安装后配置
[root@server php-7.2.8]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@server php-7.2.8]# source /etc/profile.d/php7.sh
[root@server php-7.2.8]# which php
/usr/local/php7/bin/php
[root@server php-7.2.8]# php -v
PHP 7.2.8 (cli) (built: Sep 17 2018 15:02:30) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
3.4配置php-fpm
[root@server php-7.2.8]# cp php.ini-production /etc/php.ini
[root@server php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@server php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
[root@server php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@server php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
//编辑php-fpm的配置文件、添加如下内容
[root@server php-7.2.8]# vim /usr/local/php7/etc/php-fpm.conf
·······
·······
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
3.5php-fpm
[root@server php-7.2.8]# service php-fpm start
Starting php-fpm done
[root@server php-7.2.8]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
[root@server php-7.2.8]# ps -ef | grep php
root 66511 1 0 15:23 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody 66512 66511 0 15:23 ? 00:00:00 php-fpm: pool www
nobody 66513 66511 0 15:23 ? 00:00:00 php-fpm: pool www
nobody 66514 66511 0 15:23 ? 00:00:00 php-fpm: pool www
nobody 66515 66511 0 15:23 ? 00:00:00 php-fpm: pool www
nobody 66516 66511 0 15:23 ? 00:00:00 php-fpm: pool www
root 66519 44547 0 15:24 pts/0 00:00:00 grep --color=auto php
4配置apache
4.1启动代理模块
[root@server php-7.2.8]# sed -i '/proxy_module/s/#//g' /etc/httpd24/httpd.conf
[root@server php-7.2.8]# sed -i '/proxy_fcgi_module/s/#//g' /etc/httpd24/httpd.conf
4.2配置虚拟机
[root@server php-7.2.8]# mkdir /usr/local/apache/htdocs/lslsls.com
[root@server php-7.2.8]# cat > /usr/local/apache/htdocs/lslsls.com/index.php <<EOF
> <?php
> phpinfo();
> ?>
> EOF
[root@server php-7.2.8]# chown -R apache.apache /usr/local/apache/htdocs/
[root@server php-7.2.8]# ll /usr/local/apache/htdocs/ -d
drwxr-xr-x. 3 apache apache 42 9月 17 18:55 /usr/local/apache/htdocs/
root@server php-7.2.8]# vim /etc/httpd24/httpd.conf
//在最后添加以下内容
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/lslsls.com"
ServerName www.lslsls.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/lslsls.com/$1
<Directory "/usr/local/apache/htdocs/lslsls.com">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
//搜索AddType,添加以下内容
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php //添加此行
AddType application/x-httpd-php-source .phps //添加此行
[root@server php-7.2.8]# sed -i '/ DirectoryIndex/s/index.html/index.php index.html/g' /etc/httpd24/httpd.con
4.3重启Apache服务
[root@server ~]# apachectl stop
[root@server ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
[root@server ~]# apachectl start
[root@server ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*