centos7中LNMP架构部署

一.环境规划

IP角色
192.168.19.152PHP脚本程序解析
192.168.19.20Web服务器
192.168.19.153数据库节点

系统采用:

[root@nebulalinux ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

软件版本:
nginx:nginx/1.15.0
php:PHP 7.4.8
mysql: 8.0.16
处理防火墙及时间同步

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum -y install ntpdate
[root@localhost ~]# ntpdate ntp1.aliyun.com
[root@localhost ~]# hwclock --systohc

二.程序安装
PHP程序安装
1.下载解压安装包

[root@localhost ~]# wget http://php.net/distributions/php-7.2.0.tar.gz
[root@localhost ~]# tar -xf php-7.4.8.tar\(1\)\(1\).gz -C  /usr/local/src/

2.安装依赖

[root@localhost src]# yum install -y gcc zlib zlib-devel openssl openssl-deverl perl-devel make
[root@localhost ~]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/crypt-2.5.7.tar.gz
[root@localhost ~]# yum -y install gd-devel libjpeg libjpeg-devel libpng libdevel libiconv-devel freetype freetype-devel libmcrypt libmcrypt-devel libxmibxml2-devel libxslt-devel mhash
[root@localhost ~]# tar -zxf libmcrypt-2.5.7.tar.gz
[root@localhost ~]# cd libmcrypt-2.5.7
[root@localhost libmcrypt-2.5.7]# ./configure
[root@localhost libmcrypt-2.5.7]# make && make install
[root@localhost libmcrypt-2.5.7]# echo $?
0
[root@localhost libmcrypt-2.5.7]# yum -y install gd-devel libjpeg libjpeg-delibpng libpng-devel freetype freetype-d autoconf libiconv-devel
[root@localhost ~]# rpm -e libcurl-7.29.0-42.el7.x86_64 --nodeps
[root@localhost ~]# wget https://curl.haxx.se/download/curl-7.56.0.tar.gz
[root@localhost ~]# tar -zxvf curl-7.56.0.tar.gz
[root@localhost ~]# cd curl-7.56.0
[root@localhost curl-7.56.0]# ./configure --prefix=/usr/local/curl --with-sswith-zlib
[root@localhost curl-7.56.0]# echo $?
0
[root@localhost curl-7.56.0]# make && make install
[root@localhost curl-7.56.0]# cd /usr/local/src/php-7.4.8/
[root@localhost php-7.4.8]# ./configure --prefix=/usr/local/php --with-confile-path=/usr/local/php7/etc --with-curl=/usr/local/curl --disable-ipv6 --wito-mysql --with-openssl --with-openssl-dir --with-pcre-regex --with-kerberos th-libdir=lib --with-libxml-dir --with-mysqli=shared,mysqlnd --with-pdo-mysqared,mysqlnd --with-pdo-sqlite --with-gd --with-iconv --with-zlib --with-xml--with-xsl --with-pear --with-gettext --with-png-dir --with-jpeg-dir --with-type-dir --with-mcrypt --with-mhash --enable-json --enable-mbstring --enable --enable-mysqlnd --enable-zip --enable-inline-optimization --enable-shared able-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --ee-mbregex --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-socketenable-soap --enable-session --enable-opcache --enable-fpm --enable-maintaints --enable-fileinfo --enable-gd-jis-conv --with-zlib-dir
[root@localhost php-7.4.8]# echo $?
1
[root@localhost php-7.4.8]# yum -y install  sqlite-devel
[root@localhost php-7.4.8]# yum install libcurl-devel
[root@localhost php-7.4.8]# yum install oniguruma oniguruma-devel
[root@localhost php-7.4.8]# ./configure --prefix=/usr/local/php --with-confile-path=/usr/local/php7/etc --with-curl=/usr/local/curl --disable-ipv6 --wito-mysql --with-openssl --with-openssl-dir --with-pcre-regex --with-kerberos th-libdir=lib --with-libxml-dir --with-mysqli=shared,mysqlnd --with-pdo-mysqared,mysqlnd --with-pdo-sqlite --with-gd --with-iconv --with-zlib --with-xml--with-xsl --with-pear --with-gettext --with-png-dir --with-jpeg-dir --with-type-dir --with-mcrypt --with-mhash --enable-json --enable-mbstring --enable --enable-mysqlnd --enable-zip --enable-inline-optimization --enable-shared able-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --ee-mbregex --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-socketenable-soap --enable-session --enable-opcache --enable-fpm --enable-maintaints --enable-fileinfo --enable-gd-jis-conv --with-zlib-dir
[root@localhost php-7.4.8]# echo $?
0
[root@localhost php-7.4.8]# make
[root@localhost php-7.4.8]# make install
[root@localhost php-7.4.8]# echo $?
0

3.php配置
配置启动项

[root@localhost php-7.4.8]# cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-7.4.8]# cp php.ini-production /etc/php.ini
[root@localhost php-7.4.8]# cd /usr/local/src/php-7.4.8/sapi/fpm/
[root@localhost fpm]# cp -p init.d.php-fpm /etc/init.d/php-fpm
[root@localhost fpm]# cd /etc/init.d/
[root@localhost init.d]# chmod +x php-fpm
[root@localhost init.d]# chkconfig php-fpm on
[root@localhost profile.d]# pwd
/etc/profile.d
[root@localhost profile.d]# cat php.sh
export PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH
[root@localhost init.d]# source /etc/profile
[root@localhost profile.d]# php -v
PHP 7.4.8 (cli) (built: Aug  1 2020 17:10:42) ( ZTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

4.配置php-fpm模块
编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf)

[root@localhost ~]# cd /usr/local/php/
[root@localhost php]# cd etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# vim /usr/local/php/etc/php-fpm.conf
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
[root@localhost profile.d]# cat /usr/local/php/etc/php-fpm.d/www.conf | grep -iv "^\;"
user = nginx
group = nginx
listen = 0.0.0.0:9000
listen.owner = nginx
listen.group = nginx
pm = dynamic
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
[root@localhost php-fpm.d]# cd /usr/local/php/sbin/
[root@localhost sbin]# ./php-fpm
[01-Aug-2020 18:12:36] ERROR: unable to bind listening socket for address '0.0:9000': Address already in use (98)
[01-Aug-2020 18:12:36] ERROR: FPM initialization failed
[root@localhost sbin]# netstat -lntup | grep 9000
tcp        0      0 0.0.0.0:9000            0.0.0.0:*               LISTEN  36551/php-fpm: mast
[root@localhost sbin]# killall php-fpm
[root@localhost sbin]# ./php-fpm
[root@localhost sbin]# ps -ef | grep nginx
root       1732      1  0 15:04 ?        00:00:00 nginx: master process /opta/nginx/sbin/nginx -c /opt/data/nginx/conf/nginx.conf
nginx      1733   1732  0 15:04 ?        00:00:00 nginx: worker process
nginx     36759  36758  0 18:15 ?        00:00:00 php-fpm: pool www
nginx     36760  36758  0 18:15 ?        00:00:00 php-fpm: pool www
nginx     36761  36758  0 18:15 ?        00:00:00 php-fpm: pool www
nginx     36762  36758  0 18:15 ?        00:00:00 php-fpm: pool www
nginx     36763  36758  0 18:15 ?        00:00:00 php-fpm: pool www
root      36771   1613  0 18:16 pts/0    00:00:00 grep --color=auto nginx

5.nginx配置
在这里插入图片描述

[root@nebulalinux ~]# ps -ef | grep nginx
root      16940      1  0 12:56 ?        00:00:00 nginx: master process /opt/data/nginx/sbin/nginx -c /opt/data/nginx/conf/nginx.conf
nginx     16941  16940  0 12:56 ?        00:00:00 nginx: worker process
root      17002  16858  0 15:25 pts/0    00:00:00 grep --color=auto nginx

nginx重启后在php-server上创建测试目录

[root@localhost ~]# mkdir www
[root@localhost ~]# chown -R nginx:nginx www
[root@localhost profile.d]#
[root@localhost profile.d]# cat /www/index.php
<?php
phpinfo();
?>

浏览器测试:在这里插入图片描述
6.mysql配置

mysql> select  user,host,plugin from mysql.user;
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| test02           | %         | mysql_native_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
| root             | localhost | caching_sha2_password |
| test01           | localhost | mysql_native_password |
+------------------+-----------+-----------------------+
#创建用户时修改认证插件为mysql_native_password,并开放客户端
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| memc               |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

7.安装PHP-mysql链接模块

[root@localhost sbin]# cd /usr/local/src/php-7.4.8/ext/
[root@localhost ext]# cd mysql
mysqli/  mysqlnd/
[root@localhost ext]# cd mysqli/
[root@localhost mysqli]# /usr/local/php/bin/ph
phar        php         php-config  phpize
phar.phar   php-cgi     phpdbg
[root@localhost mysqli]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902
[root@localhost mysqli]# ./configure --with-php-config=/usr/local/php/
bin/     etc/     include/ lib/     php/     sbin/    var/
[root@localhost mysqli]# ./configure --with-php-config=/usr/local/php/bin/
[root@localhost mysqli]# ./configure --with-php-config=/usr/local/php/bin/phnfig --enable-embedded-mysqli=shared --enable-shared
[root@localhost mysqli]# echo $?
0
[root@localhost mysqli]# make
[root@localhost mysqli]# make install
[root@localhost mysqli]# echo $?
0
[root@localhost mysqli]# cd /usr/local/php/lib/php/extensions/no-debug-zts-2902/
[root@localhost no-debug-zts-20190902]# ls
mysqli.a  mysqli.so  opcache.a  opcache.so  pdo_mysql.a  pdo_mysql.so
[root@localhost no-debug-zts-20190902]# cd /usr/local/src/php-7.4.8/ext/pdo
[root@localhost pdo]# cd /usr/local/src/php-7.4.8//ext/pdo
pdo/          pdo_firebird/ pdo_oci/      pdo_pgsql/
pdo_dblib/    pdo_mysql/    pdo_odbc/     pdo_sqlite/
[root@localhost pdo]# cd /usr/local/src/php-7.4.8//ext/pdo_mysql/
[root@localhost pdo_mysql]# /usr/local/php/bin/php
php         php-cgi     php-config  phpdbg      phpize
[root@localhost pdo_mysql]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902
[root@localhost pdo_mysql]# ./configure --with-php-config=/usr/local/php/bin-config --with-pdo-mysql=mysqlnd
[root@localhost pdo_mysql]# echo $?
0
[root@localhost pdo_mysql]# make
[root@localhost pdo_mysql]# echo $?
0
[root@localhost pdo_mysql]# make install
[root@localhost php-7.4.8]# cp php.ini-production /usr/local/php/etc/php.ini
cp:是否覆盖"/usr/local/php/etc/php.ini"yes
[root@localhost php-7.4.8]# cd /usr/local/php/etc/
[root@localhost etc]# vim php.ini
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20190902"
extension = mysql.so
extension = pdo_mysql.so
[root@localhost etc]# service php-fpm restart
Gracefully shutting down php-fpm warning, no pid file found - php-fpm is notning ?
Starting php-fpm  done
[root@localhost etc]# ps -ef | grep php
root      70378      1  0 12:23 ?        00:00:00 php-fpm: master process (/local/php/etc/php-fpm.conf)
nginx     70379  70378  0 12:23 ?        00:00:00 php-fpm: pool www
nginx     70380  70378  0 12:23 ?        00:00:00 php-fpm: pool www
nginx     70381  70378  0 12:23 ?        00:00:00 php-fpm: pool www
nginx     70382  70378  0 12:23 ?        00:00:00 php-fpm: pool www
nginx     70383  70378  0 12:23 ?        00:00:00 php-fpm: pool www
root      70408   1613  0 12:24 pts/0    00:00:00 grep --color=auto php

8.编辑mysql测试网页

[root@localhost etc]# cat /www/index1.php
<?php
$con = new mysqli('192.168.19.153','test02','ABC123.com','memc');
if(!$con)
    echo "faling...";
else
    echo "success connect mysql\n";
?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值