这里写目录标题
- 一、LNMP架构解读
- MySQL安装配置
- PHP解析环境的安装
- 配置Nginx支持PHP环境
- 二、LNMP应用部署
- 1、安装nginx
- 2、安装MYSQL
- 3、安装php
- 4、让nginx支持PHP
- 5、创建数据库
- 6、更改测试页内容
- 7、安装论坛
一、LNMP架构解读
LNMP平台就是Linux. Ngnix. MySQL. PHP的组合架构,需要Lnux服务器、MySal 数据库、PHP解析坏境
Ngnix特长:高并发,低资源,处理静态网络访问请求非常强
Apache:静态处理和动态处理都可以做,更适合做动态处理
Nginx将动态资源请求交给PHP当中的fpm处理动态请求
PHP主配置文件:php.ini
Nginx将动态资源分配给FPM或Apache
MySQL安装配置
1、为了与Nginx、PHP环境保持- -致, 此处选择采用源代码编译的方式安装MySQL组件
2、MySQL部署的方法
- 编译安装MySQL
- 优化调整
- 初始化数据库
- 启动MySQL服务并设置root数据库账号的密码
PHP解析环境的安装
1、配置网页动静分离,解析PHP,有两种方法可以选择
- 使用PHP的FPM模块
- 将访问PHP页面的Web请求转交给Apache服务器去处理
2、较新版本的PHP已经自带FPM模块,对PHP解析实例进行管理、优化解析效率 - FastCGI将Http Server和动态脚本语言分离开
- Nginx专门处理静态请求,转发动态请求
- PHP-FPM专[门解析PHP动态请求
- 单服务器的LNMP架构通常使用FPM方式来解析PHP
配置Nginx支持PHP环境
1、调用本机的php-fpm进程配置方法
- 建立FPM配置文件php-fpm.conf,修改配置选项
- PID文件、运行用户、服务进程数等 - 启动php-fpm进程
2、配置Nginx支持PHP解析 - 在Nginx的配置文件的server{ }配置段中设置将PHP的网页请求转给FPM模块处理
3、PHP页面访问测试
二、LNMP应用部署
本案例在单台服务器上部署LNMP环境
案例架构
Linux+Nginx+MySQL+PHP
1、安装nginx
[root@localhost ~]
[root@localhost opt]
[root@localhost opt]
[root@localhost LNMP]
rz waiting to receive.
[root@localhost LNMP]
Discuz_X3.4_SC_UTF8.zip mysql-boost-5.7.20.tar.gz ncurses-5.6.tar.gz nginx-1.12.2.tar.gz php-7.1.10.tar.bz2
1、安装环境依赖包
[root@localhost LNMP]
[root@localhost LNMP]
[root@localhost nginx-1.12.2]
gcc-c++ \
zlib-devel \
pcre pcre-devel //安装编译器和其他工具
2、创建运行用户、组
[root@localhost nginx-1.12.2]
[root@localhost nginx-1.12.2]
uid=1001(nginx) gid=1001(nginx) 组=1001(nginx)
3、编译安装nginx
[root@localhost nginx-1.12.2]
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module //安装路径,用户,组,统计模块功能
[root@localhost nginx-1.12.2]
4、路径优化
[root@localhost nginx-1.12.2]
[root@localhost nginx-1.12.2]
nginx
5、检测语法
[root@localhost nginx-1.12.2]
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
6、启动、停止nginx服务
[root@localhost nginx-1.12.2]
[root@localhost nginx-1.12.2]
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 70833/nginx:
用宿主机win10去访问192.168.200.80,成功访问nginx网站
[root@localhost nginx-1.12.2]
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 70833/nginx: master
[root@localhost nginx-1.12.2]
[root@localhost nginx-1.12.2]
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 70833/nginx: master
[root@localhost nginx-1.12.2]
[root@localhost nginx-1.12.2]
[root@localhost nginx-1.12.2]
[root@localhost nginx-1.12.2]
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 70961/nginx: master
[root@localhost nginx-1.12.2]
[root@localhost nginx-1.12.2]
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 70962/nginx: worker
[root@localhost nginx-1.12.2]
[root@localhost nginx-1.12.2]
7、添加nginx系统服务
[root@localhost nginx-1.12.2]
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking //默认进程模式
PIDFile=/usr/local/nginx/logs/nginx.pid //进程文件
ExecStart=/usr/local/nginx/sbin/nginx //安装目录
ExecReload=/usr/bin/kill -s HUP $MAINPID //重载目录
ExecStop=/usr/bin/kill -s QUIT $MAINPID //停止
PrivateTmp=ture
[Install]
WantedBy=multi-user.target //多用户模式
[root@localhost nginx-1.12.2]
[root@localhost nginx-1.12.2]
Warning: nginx.service changed on disk. Run 'systemctl daemon-reload' to reload units. //出现警告
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
[root@localhost nginx-1.12.2]
[root@localhost nginx-1.12.2]
[root@localhost nginx-1.12.2]
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 71619/nginx: master
2、安装MYSQL
[root@localhost nginx-1.12.2]
[root@localhost LNMP]
Discuz_X3.4_SC_UTF8.zip ncurses-5.6.tar.gz php-7.1.10.tar.bz2 mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz
[root@localhost LNMP]
[root@localhost LNMP]
[root@localhost opt]
[root@localhost opt]
[root@localhost opt]
[root@localhost mysql-5.7.20]
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ //存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \ //数据存储位置
-DWITH_BOOST=boost \ //c++库
-DWITH_SYSTEMD=1 //开启第二进程
[root@localhost mysql-5.7.20]
[root@localhost mysql-5.7.20]
[root@localhost mysql-5.7.20]
[root@localhost local]
drwxr-xr-x. 11 root root 151 8月 11 09:57 nginx
[root@localhost local]
[root@localhost local]
drwxr-xr-x. 11 mysql mysql 197 8月 11 12:18 mysql
[root@localhost local]
[root@localhost etc]
[client]
port=3306
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
[mysql]
port=3306
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
character_set_server=utf8
pid-file=/usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
server-id=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
设置环境变量
[root@localhost etc]
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH //声明为全局变量
[root@localhost etc]
初始化数据库
[root@localhost etc]
[root@localhost mysql]
bin COPYING-test include man README share usr
COPYING docs lib mysql-test README-test support-files
[root@localhost mysql]
mysql_install_db
mysqld
[root@localhost mysql]
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data //初始化数据库
2020-08-11T11:41:37.791663Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-08-11T11:41:38.155226Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-08-11T11:41:38.210661Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-08-11T11:41:38.269282Z 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: 9dec1b5f-dbc7-11ea-ab28-000c29cd9a36.
2020-08-11T11:41:38.269993Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-08-11T11:41:38.271838Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@localhost mysql]
[root@localhost mysql]
[root@localhost mysql]
tcp6 0 0 :::3306 :::* LISTEN 95058/mysqld
[root@localhost mysql]
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@localhost mysql]
Enter password: //空密码所以按空格
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@localhost mysql]
Enter password: //输入刚刚设置的密码abc123
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> quit
Bye
[root@localhost mysql]
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 71619/nginx: master
[root@localhost mysql]
tcp6 0 0 :::3306 :::* LISTEN 95058/mysqld
3、安装php
[root@localhost mysql]
[root@localhost mysql]
[root@localhost LNMP]
[root@localhost LNMP]
[root@localhost php-7.1.10]
[root@localhost php-7.1.10]
[root@localhost php-7.1.10]
[root@localhost php-7.1.10]
1170 mysqli.default_socket = /usr/local/mysql/mysql.sock
date.timezone = Asia/Shanghai
[root@localhost php-7.1.10]
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]
[root@localhost php-7.1.10]
[root@localhost etc]
pear.conf php-fpm.conf.default php-fpm.d //fpm模板
[root@localhost etc]
[root@localhost etc]
pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d
[root@localhost etc]
pid = run/php-fpm.pid
[root@localhost etc]
[root@localhost etc]
pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d
[root@localhost etc]
[root@localhost php-fpm.d]
www.conf.default
[root@localhost php-fpm.d]
[root@localhost php-fpm.d]
www.conf www.conf.default
[root@localhost php-fpm.d]
[root@localhost php-fpm.d]
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 105806/php-fpm: mas
[root@localhost php-fpm.d]
[root@localhost php-fpm.d]
4
4、让nginx支持PHP
[root@localhost php-fpm.d]
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
[root@localhost php-fpm.d]
[root@localhost php-fpm.d]
[root@localhost php-fpm.d]
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 106079/nginx: maste
[root@localhost php-fpm.d]
[root@localhost nginx]
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
[root@localhost nginx]
[root@localhost html]
50x.html index.html
[root@localhost html]
[root@localhost html]
50x.html index.html.bak
[root@localhost html]
<?php
phpinfo()
?>
5、创建数据库
[root@localhost html]
Enter password: abc123
mysql> CREATE DATABASE bbs;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> quit
Bye
6、更改测试页内容
[root@localhost html]
<?php
$link=mysqli_connect('192.168.200.80','bbsuser','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>
[root@localhost html]
用win10浏览器登录192.168.200.80/index.php
7、安装论坛
[root@localhost html]
[root@localhost LNMP]
[root@localhost LNMP]
[root@localhost LNMP]
[root@localhost dir_SC_UTF8]
readme upload utility
[root@localhost dir_SC_UTF8]
[root@localhost nginx]
[root@localhost bbs]
admin.php config favicon.ico index.php misc.php search.php uc_client
api connect.php forum.php install plugin.php source uc_server
api.php crossdomain.xml group.php m portal.php static
archiver data home.php member.php robots.txt template
[root@localhost bbs]
[root@localhost bbs]
[root@localhost bbs]
[root@localhost bbs]
[root@localhost bbs]
[root@localhost bbs]
[root@localhost bbs]
[root@localhost bbs]
打开win10 浏览器输入如下地址安装论坛
http://192.168.200.80/bbs/install/index.php
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)