Python入门到实战 开源商城系统 js快速排序 mysql安装 string cordova lua safari angular ui router sms GMU 建筑资质 vue版本 河南普通话 photoshop cs3 教程 大数据项目开发案例 最新更新国内最快的dns oracle删除字段sql kafka消费不到数据 plsql连接mysql数据库 mysql函数返回结果集 反函数的二阶导数 重置hosts python随机数 python或运算 python类与对象 java教材 java中的正则表达式 java中的继承 java中的注释 java单继承 java泛型方法 java学习流程 linux系统命令大全 linux系统安装教程图解 python开发实例 sp5 phpqrcode pr滤镜插件 深入浅出通信原理
当前位置: 首页 > 学习教程  > 编程语言

LNMP编译安装

2020/8/11 18:43:27 文章标签:

文章目录

  • 简介
  • LNMP架构的部署
    • LNMP架构概述
    • 安装MySQL服务
    • 安装配置PHP解析环境
    • 配置实例

简介

LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指Perl或Python

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。

Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。

Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。

Mysql是一个小型关系型数据库管理系统。

PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。

这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统

LNMP架构的部署

LNMP架构概述

LNMP平台就是 Linux、 Ngnix、 My SQL、PHP的组合架构,需要 Linux服务器、MysαL数据库、PHP解析环境

Ngnix特长:高并发,低资源,处理静态网络访问请求非常强

Apache:静态处理和动态处理都可以做,更适合做动态处理

Nginx将动态资源请求交给PHP当中的fpm处理动态请求

PHP主配置文件:php.ini

Nginx将动态资源分配给FPM或Apache

安装MySQL服务

为了与 Nginx、PHP环境保持一致,此处选择采用源代码编译的方式安装 My SQL组件
MySQL部署的方法
    编译安装 MySQL
    优化调整
    初始化数据库
    启动mysq服务并设置root数据库账号的密码

安装配置PHP解析环境

配置网页动静分离,解析PHP,有两种方法可以选择
    使用PHP的FPM模块
    将访问PHP页面的Web请求转交给 Apache服务器去处理

较新版本的PHP已经自带FPM模块,用来对PHP解析实例进行管理、优化解析效率
    FastCG将 Http Server和动态脚本语言分离开
    Nginx专门处理静态请求,转发动态请求
    PHP FPM专门解析PHP动态请求

单服务器的LNMP架构通常使用FPM的方式来解析PHP

PHP编译安装步骤
    编译安装PHP
    编译选项时添加"- enable-fpm”以启用此模块
    安装后的调整,主要是配置文件的建立与相应命令工具的路径优化
    安装 Zend Guardloader(提高PHP解析效率),并进行加载配置
    CGI还有跨平台的功能

配置实例

[root@localhost ~]# cd /opt 
[root@localhost opt]# systemctl stop firewalld
[root@localhost opt]# setenforce 0
[root@localhost opt]# iptables -F

[root@localhost opt]# mkdir nginx mysql php
[root@localhost opt]# cd nginx/
nginx-1.12.2.tar.gz
[root@localhost nginx]# tar xzvf nginx-1.12.2.tar.gz
[root@localhost nginx-1.12.2]# yum -y install gcc gcc-c++ zlib-devel pcre pcre-devel
[root@localhost nginx-1.12.2]# useradd -M -s /sbin/nologin nginx
[root@localhost nginx-1.12.2]# id nginx
uid=1001(nginx) gid=1001(nginx)=1001(nginx)
[root@localhost nginx-1.12.2]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module
[root@localhost nginx-1.12.2]# make && make install
[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
[root@localhost nginx-1.12.2]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 99 20
# description: Nginx Server Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
 start)
  $PROG
  ;;
 stop)
  kill -s QUIT $(cat $PIDF)
  ;;
 restart)
  $0 stop
  $0 start
  ;;
 reload)
  kill -s HUP $(cat $PIDF)
  ;;
 *)
   echo "Usage: $0 {start|stop|restart|reload}"
   exit 1
esac
exit 0
[root@localhost nginx-1.12.2]# chmod +x /etc/init.d/nginx 
[root@localhost nginx-1.12.2]# chkconfig --add nginx
[root@localhost nginx-1.12.2]# service nginx start
[root@localhost nginx-1.12.2]# service nginx stop
[root@localhost nginx-1.12.2]# netstat -ntap | grep nginx
[root@localhost nginx-1.12.2]# service nginx start
[root@localhost nginx-1.12.2]# netstat -ntap | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      79280/nginx: master 
[root@localhost nginx-1.12.2]# vim /lib/systemd/system/nginx.server
[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]# systemctl stop nginx
[root@localhost nginx-1.12.2]# netstat -ntap | grep nginx
[root@localhost nginx-1.12.2]# systemctl start nginx
[root@localhost nginx-1.12.2]# netstat -ntap | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      77316/nginx: master 

[root@localhost nginx-1.12.2]# yum -y install lynx
[root@localhost nginx-1.12.2]# lynx 127.0.0.1
[root@localhost nginx-1.12.2]# yum install httpd -y

在这里插入图片描述在这里插入图片描述

[root@localhost nginx-1.12.2]# yum -y install \
> ncurses \
> ncurses-devel \
> bison \
> cmake
[root@localhost nginx-1.12.2]# cd /opt/mysql/
mysql-boost-5.7.20.tar.gz
[root@localhost mysql]# tar xzvf mysql-boost-5.7.20.tar.gz 
[root@localhost mysql]# cd mysql-5.7.20/
[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 \
> -DWITH_SYSTEMD=1
[root@localhost mysql-5.7.20]# make && make install
[root@localhost mysql-5.7.20]# useradd -s /sbin/nologin mysql
[root@localhost mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql/
[root@localhost mysql-5.7.20]# vim /etc/my.cnf
[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/mysql.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
[root@localhost mysql-5.7.20]# chown mysql:mysql /etc/my.cnf 
[root@localhost mysql-5.7.20]# vim /etc/profile
 77 PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
 78 export PATH
[root@localhost mysql-5.7.20]# source /etc/profile
[root@localhost mysql-5.7.20]# echo $PATH
/usr/local/mysql/bin:/usr/local/mysql/lib:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost mysql-5.7.20]# cd /usr/local/mysql/
[root@localhost mysql]# bin/mysqld \
> --initialize-insecure \
> --user=mysql \
> --basedir=/usr/local/mysql \
> --datadir=/usr/local/mysql/data
[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
[root@localhost mysql]# netstat -natp | grep 3306
[root@localhost mysql]# systemctl start mysqld.service 
[root@localhost mysql]# netstat -natp | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      97987/mysqld   

[root@localhost mysql]# systemctl start mysqld.service 
[root@localhost mysql]# systemctl enable mysqld.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@localhost mysql]# systemctl stop mysqld.service 
[root@localhost mysql]# systemctl status mysqld.service 

[root@localhost mysql]# mysqladmin -u root -p password "abc123"
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]# mysql -u root -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20 Source distribution

Copyright (c) 2000, 2017, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> quit
Bye

[root@localhost mysql]# cd /opt
[root@localhost opt]# yum -y install \
> libjpeg \
> libjpeg-devel \
> libpng libpng-devel \
> freetype freetype-devel \
> libxml2 \
> libxml2-devel \
> zlib zlib-devel \
> curl curl-devel \
> openssl openssl-devel
[root@localhost opt]# cd php
php-7.1.10.tar.bz2
[root@localhost php]# tar xjvf php-7.1.10.tar.bz2 
[root@localhost php]# cd php-7.1.10/
[root@localhost php-7.1.10]# ./configure \
> --prefix=/usr/local/php \
> --with-mysql-sock=/usr/local/mysql/mysql.sock \
> --with-mysqli \
> --with-zlib \
> --with-curl \
> --with-gd \
> --with-jpeg-dir \
> --with-png-dir \
> --with-freetype-dir \
> --with-openssl \
> --enable-fpm \
> --enable-mbstring \
> --enable-xml \
> --enable-session \
> --enable-ftp \
> --enable-pdo \
> --enable-tokenizer \
> --enable-zip
[root@localhost php-7.1.10]# make && make install
[root@localhost php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini
[root@localhost php-7.1.10]# vim /usr/local/php/lib/php.ini 
1170 mysqli.default_socket = /usr/local/mysql/mysql.sock
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200811183701573.png)

 939 date.timezone = Asia/Shanghai

在这里插入图片描述

[root@localhost php-7.1.10]# /usr/local/php/bin/php -m
[root@localhost php-7.1.10]# cd /usr/local/php/etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# vim php-fpm.conf
 17 pid = run/php-fpm.pid

在这里插入图片描述

[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini 
[root@localhost php-fpm.d]# netstat -ntap | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      107770/php-fpm: mas 
[root@localhost php-fpm.d]# ln -s /usr/local/php/bin/* /usr/local/bin/
[root@localhost php-fpm.d]# ps aux | grep -c "php-fpm"
[root@localhost php-fpm.d]# vim /usr/local/nginx/conf/nginx.conf
 47         location ~ \.php$ {
 48             root           html;
 49             fastcgi_pass   127.0.0.1:9000;
 50             fastcgi_index  index.php;
 51             fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
 52             include        fastcgi_params;
 53         }

在这里插入图片描述

[root@localhost php-fpm.d]# service nginx stop
[root@localhost php-fpm.d]# netstat -ntap | grep nginx
[root@localhost php-fpm.d]# service nginx start
[root@localhost php-fpm.d]# netstat -ntap | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      108002/nginx: maste 
[root@localhost php-fpm.d]# cd /usr/local/nginx/html/
[root@localhost html]# mv index.html index.html.bak
[root@localhost html]# vim index.php
<?php
phpinfo();
?>

在这里插入图片描述

[root@localhost html]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.20 Source distribution

Copyright (c) 2000, 2017, 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> 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.00 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.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bbs                |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> quit
Bye
[root@localhost html]# vim /usr/local/nginx/html/index.php 
<?php
$link=mysqli_connect('192.168.20.20','bbsuser','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail";
?>

在这里插入图片描述

[root@localhost html]# cd /opt
Discuz_X3.4_SC_UTF8.zip  
[root@localhost opt]# cd dir_SC_UTF8/
[root@localhost dir_SC_UTF8]# cp -r upload/ /usr//local/nginx/html/bbs
[root@localhost dir_SC_UTF8]# cd /usr/local/nginx/html/bbs/
[root@localhost bbs]# chown -R root:nginx ./config/
[root@localhost bbs]# chown -R root:nginx ./data/
[root@localhost bbs]# chown -R root:nginx ./uc_client/
[root@localhost bbs]# chown -R root:nginx ./uc_server/
[root@localhost bbs]# chmod -R 777 ./config/
[root@localhost bbs]# chmod -R 777 ./data/
[root@localhost bbs]# chmod -R 777 ./uc_client/
[root@localhost bbs]# chmod -R 777 ./uc_server/

在这里插入图片描述
在这里插入图片描述在这里插入图片描述


本文链接: http://www.dtmao.cc/news_show_100004.shtml

附件下载

相关教程

    暂无相关的数据...

共有条评论 网友评论

验证码: 看不清楚?