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平台就是 Linux、 Ngnix、 My SQL、PHP的组合架构,需要 Linux服务器、MysαL数据库、PHP解析环境
Ngnix特长:高并发,低资源,处理静态网络访问请求非常强
Apache:静态处理和动态处理都可以做,更适合做动态处理
Nginx将动态资源请求交给PHP当中的fpm处理动态请求
PHP主配置文件:php.ini
Nginx将动态资源分配给FPM或Apache
配置网页动静分离,解析PHP,有两种方法可以选择
较新版本的PHP已经自带FPM模块,用来对PHP解析实例进行管理、优化解析效率
单服务器的LNMP架构通常使用FPM的方式来解析PHP
PHP编译安装步骤
[root@localhost~]# vim /usr/local/nginx/conf/nginx. conf
Servert{
...
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 ~]# cd /usr/local/
[root@localhost local]# ls
bin etc games include lib lib64 libexec sbin share src
[root@localhost local]# iptables -F
[root@localhost local]# setenforce 0
[root@localhost local]# cd /opt/
[root@localhost opt]# mkdir LNMP
[root@localhost opt]# ls
LNMP rh
[root@localhost opt]# cd LNMP/
[root@localhost LNMP]# rz -E '获取宿主机里的软件包'
rz waiting to receive.
[root@localhost LNMP]# ls
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]# tar zxvf nginx-1.12.2.tar.gz -C /opt
[root@localhost LNMP]# cd /opt/
[root@localhost opt]# ls
LNMP nginx-1.12.2 rh
[root@localhost opt]# cd nginx-1.12.2/
[root@localhost nginx-1.12.2]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
[root@localhost nginx-1.12.2]# yum -y install gcc \
gcc-c++ \
make \
pcre-devel \
expat-devel \
perl \
zlib-devel \
pcre
[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]# useradd -M -s /sbin/nologin nginx
[root@localhost nginx-1.12.2]# id nginx
[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
[root@localhost nginx-1.12.2]# nginx -t
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
[root@localhost conf]# cd ..
[root@localhost nginx]# ls
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
[root@localhost nginx]# cd html/
[root@localhost html]# ls
50x.html index.html
[root@localhost html]# nginx 开启服务
[root@localhost html]# netstat -ntap | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 17646/nginx: master
[root@localhost html]# killall -s HUP nginx 重新加载
[root@localhost html]# killall -s QUIT nginx 停止服务
[root@localhost html]# vim /lib/systemd/system/nginx.service '添加使用systemctl工具进行管理'
[Unit]
Description=nginx '描述'
After=network.target '描述服务类别'
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid 'PID文件位置'
ExecStart=/usr/local/nginx/sbin/nginx '启动服务'
ExecReload=/usr/bin/kill -s HUP $MAINPID '根据PID重载配置'
ExecStop=/usr/bin/kill -s QUIT $MAINPID '根据PID终止进程'
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost html]# pkill nginx
[root@localhost html]# systemctl start nginx
[root@localhost html]# netstat -ntap | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 17924/nginx: master
[root@localhost html]# cd /opt/LNMP/
[root@localhost LNMP]# ls
[root@localhost LNMP]# tar zxvf mysql-boost-5.7.20.tar.gz -C /opt
[root@localhost LNMP]# useradd -s /sbin/nologin mysql
[root@localhost LNMP]# yum -y install \
ncurses \
ncurses-devel \
bison \
cmake
[root@localhost LNMP]# cd /opt/mysql-5.7.20/ 'boost是5.7版本的特性'
[root@localhost mysql-5.7.20]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ 'sock;通讯文件,连接数据库,通讯协议的载体'
-DSYSCONFDIR=/etc \ '配置目录指向etc'
-DSYSTEMD_PID_DIR=/usr/local/mysql \ 'pid文件位置'
-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 \ '指定boost位置'
-DWITH_SYSTEMD=1 '守护进程'
[root@localhost mysql-5.7.20]# make && make install
[root@localhost local]# chown -R mysql.mysql mysql/
[root@localhost local]# cd /etc
[root@localhost etc]# vim 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/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]# vim /etc/profile
最后一行插入
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
[root@localhost etc]# source /etc/profile
[root@localhost etc]# 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 -ntap | grep 3306
[root@localhost mysql]# systemctl start mysqld.service
[root@localhost mysql]# netstat -ntap | grep 3306 '查看3306端口'
[root@localhost mysql]# systemctl enable mysqld.service '开启自启动'
[root@localhost mysql]# mysqladmin -u root -p password "ab123"
Enter password: 这里密码为空
[root@localhost mysql]# mysql -u root -p
Enter password: 这里密码为ab123
mysql> show databases;
mysql> quit
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 mysql]# cd /opt/
[root@localhost opt]# ls
安装php压缩包
php-7.1.10.tar.bz2
[root@localhost opt]# tar jxvf php-7.1.10.tar.bz2 '解压'
[root@localhost opt]# 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
重点:PHP有三个核心配置文件 php.ini 核心配置文件 php-fpm.conf 进程服务配置文件
www.conf 扩展配置文件
[root@localhost php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini
[root@localhost php-7.1.10]# vi /usr/local/php/lib/php.ini
找到以下两行的位置,修改这两行
1170 mysql.default_socket = /usr/local/mysql/mysql.sock
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 /usr/local/php/etc/
[root@localhost etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# ls
www.conf.default
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# ls
www.conf www.conf.default
[root@localhost php-fpm.d]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
[root@localhost php-fpm.d]# netstat -natp |grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 23210/php-fpm: mast
[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"
4
vi /usr/local/nginx/conf/nginx.conf //找到下面字段
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]# cd /usr/local/nginx/
[root@localhost nginx]# ls
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
[root@localhost nginx]# cd html/
[root@localhost html]# mv index.html index.html.bak '更改文件名,让系统识别不了就可以了'
[root@localhost html]# ls
50x.html index.html.bak
[root@localhost html]# vim index.html
<?php
phpinfo();
?>
[root@localhost html]# systemctl restart nginx
在网页测试http://20.0.0.51/index.php
mysq1 -u root -p '输入ab123密码'
CREATE DATABASE bbs;
GRANT all ON bbs.* To 'bbsuser'@'%' IDENTIFIED BY 'admin123';
GRANT all ON bbs.* To 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';
flush privileges;
vi /usr/local/nginx/html/index.php '原来的测试页内容更改如下'
<?php
$link=mysqli_connect('20.0.0.51','bbsuser','admin123');
if($link) echo"Success!!
";
else echo "Fail!!";
?>
systemctl restart nginx
在网页测试http://192.168.197.192/index.php
cd/opt
unzip Discuz_X3.4_SC_UTF8.zip -d /tmp
cd /tmp/dir_SC_UTF8/
cp -r upload /usr/local/nginx/html/bbs
cd /usr/local/nginx/html/bbs/
chown -R root:nginx ./config/
chown -R root:nginx ./data/
chown -R root:nginx ./uc_client/
chown -R root:nginx ./uc_server/
chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/
http://ip/bbs/install/index.php
数据库服务器:localhost #本地架设就用 localhost,如果不是在本机上就要填写IP地址和端口
数据库名字户名:bbsuser
管理员账号:admin
密码:admin123
http://IP/bbs/admin.php//管理后台
账户:admin
密码:admin123
访问论坛 http://20.0.0.51/bbs/index.php