LNMP架构部署

1.环境规划

主机名IP
php-server192.168.142.33
nginx-server192.168.142.34
mysql-server192.168.142.35

系统采用Centos7u4

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

软件版本:
nginx :1.15.0
php :7.3.20
mysql :8.0.20
2.## 节点处理
2.1 处理防火墙

systemctl stop firewalld
systemctl disable firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0

2.2时间同步

yum -y install ntp ntpdate
ntpdate ntp1.aliyun.com
hwclock --systohc

3.程序安装
3.1 mysql程序安装
参考另一博客MySQL程序的安装
3.2 nginx程序安装
参考另一博客nginx程序的安装
3.3 PHP程序的安装
(1)下载并解压软件包

[root@php-server ~]# wget http://php.net/distributions/ php-7.3.20.tar.gz
[root@php-server ~]# tar xf  php-7.3.20.tar.gz -C /usr/local/src/

(2)安装依赖

[root@php-server ~]# yum install -y gcc zlib zlib-devel openssl openssl-devel
perl perl-devel make
[root@php-server ~]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
[root@php-server ~]# yum -y install gd-devel libjpeg libjpeg-devel libpng
libpng-devel libiconv-devel freetype freetype-devel libmcrypt libmcrypt-devel
libxml2 libxml2-devel libxslt-devel mhash
[root@php-server ~]# tar zxf libmcrypt-2.5.7.tar.gz
[root@php-server ~]# cd libmcrypt-2.5.7
[root@php-server libmcrypt-2.5.7]# ./configure
[root@php-server libmcrypt-2.5.7]# make && make install
[root@php-server libmcrypt-2.5.7]# echo $?
0
[root@php-server libmcrypt-2.5.7]# yum -y install gd-devel libjpeg libjpeg-devel
libpng libpng-devel libiconv-devel freetype freetype-d autoconf
[root@php-server ~]# rpm -e libcurl-7.29.0-42.el7.x86_64 --nodeps
[root@php-server ~]# wget https://curl.haxx.se/download/curl-7.56.0.tar.gz
[root@php-server ~]# tar -zxvf curl-7.56.0.tar.gz
[root@php-server ~]# cd curl-7.56.0
[root@php-server curl-7.56.0]#./configure --prefix=/usr/local/curl --with-ssl --with-zlib
#可能会提示你为安装libzip,根据提示安装libzip包
[root@php-server curl-7.56.0]# make && make install
#缺啥依赖包补啥依赖包根据系统提示。

(3)编译安装php

[root@php-server libmcrypt-2.5.7]# cd /usr/local/src/php-7.3.20/
[root@php-server php-7.3.20]# ./configure --prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--with-curl=/usr/local/curl \
--disable-ipv6 \
--with-pdo-mysql \
--with-openssl \
--with-openssl-dir \
--with-pcre-regex \
--with-kerberos \
--with-libdir=lib \
--with-libxml-dir \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-pdo-sqlite \
--with-gd \
--with-iconv \
--with-zlib \
--with-xmlrpc \
--with-xsl \
--with-pear \
--with-gettext \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--with-mcrypt \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-pdo \
--enable-mysqlnd \
--enable-zip \
--enable-inline-optimization \
--enable-shared \
--enable-libxml \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--enable-soap \
--enable-session \
--enable-opcache \
--enable-fpm \
--enable-maintainer-zts \
--enable-fileinfo \
--enable-gd-jis-conv \
--with-zlib-dir
[root@php-server php-7.3.20]# echo $?
0
[root@php-server php-7.3.20]# make
0
[root@php-server php-7.3.20]# echo $?
0
[root@php-server php-7.3.20]# make install
[root@php-server php-7.3.20]# echo $?
0

4.LNMP环境配置与测试

  1. PHP配置
    配置启动项
[root@php-server php-7.3.20]# cp php.ini-production /usr/local/php7/etc/php.ini
[root@php-server php-7.3.20]# cp php.ini-production /etc/php.ini
[root@php-server php-7.3.20]# cd /usr/local/src/php-7.3.20/sapi/fpm/
[root@php-server fpm]# cp -p init.d.php-fpm /etc/init.d/php-fpm
[root@php-server fpm]# cd /etc/init.d/
functions  netconsole network   php-fpm   README   
[root@php-server init.d]# chmod +x php-fpm
[root@php-server init.d]# chkconfig php-fpm on
[root@php-server init.d]# vim /etc/profile
export PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH
[root@php-server init.d]# source /etc/profile
[root@php-server ~]# php -v
PHP 7.3.20 (cli) (built: Aug  2 2020 20:37:14) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.20, Copyright (c) 1998-2018 Zend Technologies

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

[root@php-server ~]# cd /usr/local/php7
[root@php-server php7]# cd etc/
[root@php-server etc]# cp php-fpm.conf.default php-fpm.conf
[root@php-server etc]# cd php-fpm.d/
[root@php-server php-fpm.d]# cp www.conf.default www.conf
[root@php-server php-7.3.20]# vim /usr/local/php7/etc/php-fpm.conf
pm.max_children = 50      //最多同时提供50个进程提供50个并发服务
pm.start_servers = 5       //启动时启动5个进程
pm.min_spare_servers = 2  //最小空闲进程数 
pm.max_spare_servers = 8  //最大空闲进程数
[root@php-server ~]# cat /usr/local/php7/etc/php-fpm.d/www.conf |grep -iv "^\;"
[www]
user = nginx
group = nginx
listen = 0.0.0.0:9000
listen.owner = nginx
listen.group = nginx
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

在这里插入图片描述
启动

[root@php-server ~]# cd /usr/local/php7/sbin
[root@php-server ~]# ./php-fpm 

在这里插入图片描述

5.nginx配置

[root@localhost nginx]# cat /etc/nginx/nginx.conf
user nginx nginx;
pid /var/run/nginx.pid;
error_log logs/error.log;  #取消错误日志的注释
#启用这几行
events {
 worker_connections 1024;
}
http {
 include    mime.types;
 default_type application/octet-stream;
 log_format main '$remote_addr - $remote_user [$time_local] "$request"';
server {
 listen    80;  #监听80端口
 server_name 192.168.142.34;
 charset koi8-r;
 access_log logs/host.access.log main;
 location / {
     root  /www;     #存放网页路径
     index index.html index.htm;
     }
 location ~ \.php$ {
     root      /www;                
     fastcgi_pass  192.168.42.33:9000;   #php服务器的ip
     fastcgi_index index.php ;       #和访问文件名相同
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     include    fastcgi_params;
   }
 }
}

修改完配置,重启服务
在这里插入图片描述
编辑测试网页
在php-server 上创建测试目录

[root@php-server /]# mkdir www
[root@php-server /]# chown -R nginx:nginx www
编辑测试网页
[root@php-server /]# vim www/index.php
<?php
phpinfo();
?>

在浏览器上测试:
在这里插入图片描述

6.mysql配置
在mysql-server上创建测试账号和测试数据库
注意在
注意:在MySQL8 上,创建用户是修改认证插件为mysql-native_password,并开放客户端。
在这里插入图片描述
安装php-mysql链接模块

[root@php-server ~]# cd /usr/local/src/php-7.3.20/ext/
[root@php-server ~]# cd mysqli/
[root@localhost mysqli]# /usr/local/php7/bin/phpize
[root@localhost mysqli]# ./configure \
--with-php-config=/usr/local/php7/bin/php-config \
--enable-embedded-mysqli=shared \
--enable-shared
[root@localhost mysqli]# echo $?
0
[root@localhost mysqli]# make
[root@localhost mysqli]# make install
[root@localhost mysqli]# echo $?
[root@localhost mysqli]# cd /usr/local/php7/lib/php/extensions/no-debug-zts-20180731
[root@localhost no-debug-zts-20180731]# ls
mysqli.a mysqli.so opcache.a opcache.so pdo_mysql.a pdo_mysql.so
[root@localhost php]# cd /usr/local/src/php-7.3.20/ext/pdo_mysql/
[root@php-server pdo_mysql]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
[root@localhost pdo_mysql]# ./configure \
--with-php-config=/usr/local/php7/bin/php-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.2.0]# cp php.ini-production /usr/local/php7/etc/php.ini
[root@localhost php-7.2.0]# cd /usr/local/php7/etc/
[root@localhost etc]# vim php.ini
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-zts-20170718"
extension = mysqli.so
extension = pdo_mysql.so
[root@localhost etc]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@php-server ~]# ps -ef |grep php
root       5938      1  0 16:40 ?        00:00:00 php-fpm: master process (/usr/local/php7/etc php-fpm.conf)
nginx      5939   5938  0 16:40 ?        00:00:00 php-fpm: pool www
nginx      5940   5938  0 16:40 ?        00:00:00 php-fpm: pool www
nginx      5941   5938  0 16:40 ?        00:00:00 php-fpm: pool www
nginx      5942   5938  0 16:40 ?        00:00:00 php-fpm: pool www
nginx      5943   5938  0 16:40 ?        00:00:00 php-fpm: pool www
root       6270 111644  0 18:17 pts/0    00:00:00 grep --color=auto php

编辑MySQL测试网页

[root@php-server ~]# cat www/index.php
<?php
$con = new mysqli('192.168.142.35','test','ABC123@com','test01');
if(!$con)
       echo "faling...";
else
       echo "success connect mysql\n";
?>

在浏览器上测试:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值