一.LNMP的简单介绍
LNMP:Linux系统下的Nginx+MySQL+PHP这种网站服务器架构
(1)Linux:计算机的一类操作系统
(2)Nginx:一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器
(3)Mysql:一个小型关系型数据库管理系统一个小型关系型数据库管理系统
(4)PHP:服务器端执行的嵌入HTML文档的脚本语言
架构示意图:
二.nginx
1.nginx的简单介绍
(1)特点
一个轻量级、高性能、稳定性高、并发性好的HTTP和反向代理服务器。也是由于其的特性,其应用非常广
(2)主要功能
反向代理:
是用来代理服务器的,代理我们要访问的目标服务器。代理服务器接受请求,然后将请求转发给内部网络的服务器(集群化),并将从服务器上得到的结果返回给客户端,此时代理服务器对外就表现为一个服务器
负载均衡:
多在高并发情况下需要使用。其原理就是将数据流量分摊到多个服务器执行,减轻每台服务器的压力,多台服务器(集群)共同完成工作任务,从而提高了数据的吞吐量。可使用的负载均衡策略有:轮询(默认)、权重、ip_hash、url_hash(第三方)、fair(第三方)
动静分离:
指把动态请求和静态请求分离开,合适的服务器处理相应的请求,使整个服务器系统的性能、效率更高;根据配置对不同的请求做不同转发,这是动态分离的基础。静态请求对应的静态资源可以直接放在Nginx上做缓冲,更好的做法是放在相应的缓冲服务器上。动态请求由相应的后端服务器处理
2.nginx的配置
(1)安装
[root@server4 ~]# cd lnmp
[root@server4 lnmp]# ls
apache-tomcat-7.0.37.tar.gz mysql-boost-5.7.17.tar.gz
cmake-2.8.12.2-2.el7.x86_64.rpm nginx-1.10.1.tar.gz
cmake-2.8.12.2-4.el6.x86_64.rpm nginx-1.14.0.tar.gz
Discuz_X3.2_SC_UTF8.zip nginx-1.15.9.tar.gz
jar nginx-1.8.0-1.el6.ngx.x86_64.rpm
jdk-7u79-linux-x64.tar.gz nginx-sticky-module-ng.tar.gz
libmcrypt-2.5.8-9.el6.x86_64.rpm openresty-1.13.6.1.tar.gz
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm php-5.6.35.tar.bz2
lnmp re2c-0.13.5-1.el6.x86_64.rpm
memcache-2.2.5.tgz rhel6 lanmp.pdf
[root@server4 lnmp]# tar zxf nginx-1.15.9.tar.gz
[root@server4 lnmp]# cd nginx-1.15.9
[root@server4 nginx-1.15.9]# vim /root/lnmp/nginx-1.15.9/src/core/nginx.h
[root@server4 nginx-1.15.9]# vim auto/cc/gcc
解决源码包安装的依赖性
[root@server4 nginx-1.15.9]# yum install gcc -y
[root@server4 nginx-1.15.9]# yum install pcre-devel -y
[root@server4 nginx-1.15.9]# yum install openssl-devel -y
源码包进行编译及安装
[root@server4 nginx-1.15.9]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module ##源码包编译成二进制文件
[root@server4 nginx-1.15.9]# make && make install ##安装
(2)nginx配置文件的修改
[root@server4 lnmp]# cd /usr/local
[root@server4 local]# ls
bin etc games include lib lib64 libexec lnmp sbin share src
[root@server4 local]# cd lnmp
[root@server4 lnmp]# ls
nginx
[root@server4 lnmp]# vim nginx/conf/nginx.conf
user nginx nginx; ##更改运行用户为nginx
[root@server4 lnmp]# useradd nginx
[root@server4 lnmp]# id nginx
uid=1001(nginx) gid=1001(nginx) groups=1001(nginx)
[root@server4 lnmp]# nginx ##开启nginx
[root@server4 lnmp]# nginx -t ##检查是否有错误
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
(3)软链接修改
[root@server4 lnmp]# ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/
(4)浏览器端测试:172.25.4.114
出现nginx默认页面
3.nginx虚拟主机的实现
(1)虚拟主机的添加
[root@server4 nginx]# cd /usr/local/lnmp/nginx/
[root@server4 nginx]# ls
client_body_temp fastcgi_temp logs sbin uwsgi_temp
conf html proxy_temp scgi_temp
[root@server4 nginx]# vim conf/nginx.conf
server {
listen 80;
server_name www.westos.org; ##访问的域名
location / {
root html/www; ##访问的目录
index index.html; ##访问的文件格式
}
}
server {
listen 80;
server_name bbs.westos.org;
location / {
root html/bbs;
index index.html;
}
}
server {
listen 80;
server_name blog.westos.org;
location / {
root html/blog;
index index.html;
}
}
(2)共享文件的添加
[root@server4 nginx]# cd html/
[root@server4 html]# ls
50x.html index.html
[root@server4 html]# mkdir www
[root@server4 html]# mkdir bbs
[root@server4 html]# mkdir blog
[root@server4 html]# vim www/index.html
[root@server4 html]# cat www/index.html
www.westos.org
[root@server4 html]# vim bbs/index.html
[root@server4 html]# cat bbs/index.html
bbs.westos.org
[root@server4 html]# vim blog/index.html
[root@server4 html]# cat blog/index.html
blog.westos.com
[root@server4 html]# nginx -t ##检测是否有错误
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server4 bbs]# nginx -s reload ##重新加载nginx
(3)物理机测试
域名更改
[root@foundation4 kiosk]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.4.105 www.shenzhen.com
172.25.4.114 server4 westos.org bbs.westos.org www.westos.org blog.westos.org
测试
[root@foundation4 kiosk]# curl bbs.westos.org
bbs.westos.org
[root@foundation4 kiosk]# curl www.westos.org
www.westos.org
[root@foundation4 kiosk]# curl blog.westos.org
blog.westos.com
4.nginx负载均衡的实现
(1)主配置文件的修改
[root@server4 nginx]# vim conf/nginx.conf
17 http {
18 include mime.types;
19 default_type application/octet-stream;
20 upstream westos { ##两台后端服务器
21 server 172.25.4.112:80;
22 server 172.25.4.113:80;
23 }
24 server {
25 listen 80; ##监听端口为80
26 server_name www.westos.org; ##访问的域名
27 location / {
28 proxy_pass http://westos;
29 }
30 }
[root@server4 nginx]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server4 nginx]# nginx -s reload
(2)物理主机的测试
[root@foundation4 kiosk]# curl www.westos.org
server2
[root@foundation4 kiosk]# curl www.westos.org
server3
[root@foundation4 kiosk]# curl www.westos.org
server2
[root@foundation4 kiosk]# curl www.westos.org
server3
[root@foundation4 kiosk]# curl westos.org
server2
[root@foundation4 kiosk]# curl westos.org
server3
[root@foundation4 kiosk]# curl westos.org
server2
三.mysql
1.mysql的简单介绍
(1)简单介绍
属于关系型数据库管理系统。
(2)特点
支持多种操作系统
支持多线程,充分利用CPU资源
提供⽤于管理、检查、优化数据库操作的管理⼯具
⼤型的数据库。可以处理拥有上千万条记录的⼤型数据库
提供TCP/IP、ODBC和JDBC等多种数据库连接途
多语言支持等
2.mysql的配置
(1)mysql的安装
[root@server4 ~]# cd /lnmp
[root@server4 lnmp]# ls
apache-tomcat-7.0.37.tar.gz mysql-boost-5.7.17.tar.gz
cmake-2.8.12.2-2.el7.x86_64.rpm nginx-1.10.1.tar.gz
cmake-2.8.12.2-4.el6.x86_64.rpm nginx-1.14.0.tar.gz
Discuz_X3.2_SC_UTF8.zip nginx-1.15.9
jar nginx-1.15.9.tar.gz
jdk-7u79-linux-x64.tar.gz nginx-1.8.0-1.el6.ngx.x86_64.rpm
libmcrypt-2.5.8-9.el6.x86_64.rpm nginx-sticky-module-ng.tar.gz
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm openresty-1.13.6.1.tar.gz
lnmp php-5.6.35.tar.bz2
memcache-2.2.5.tgz re2c-0.13.5-1.el6.x86_64.rpm
rhel6 lanmp.pdf
[root@server4 lnmp]# tar zxf mysql-boost-5.7.17.tar.gz ##解压源码包
[root@server4 lnmp]# yum install -y cmake-2.8.12.2-2.el7.x86_64.rpm ##安装cmake 用来编译mysql
解决依赖性
[root@server4 lnmp]# cd mysql-5.7.17/
[root@server4 mysql-5.7.17]# ls ##每次解决依赖性,重新编译时,需要清除原来的对象文件和缓存信息''make clean;rm -fr CmakeCache.txt'
boost CTestTestfile.cmake make_dist.cmake sql-common
BUILD dbug Makefile storage
client Docs man strings
cmake Doxyfile-perfschema mysql-test support-files
CMakeCache.txt extra mysys testclients
CMakeFiles include mysys_ssl unittest
cmake_install.cmake info_macros.cmake packaging VERSION
CMakeLists.txt INSTALL plugin VERSION.dep
cmd-line-utils libbinlogevents rapid vio
config.h.cmake libbinlogstandalone README win
configure.cmake libevent regex zlib
COPYING libmysql scripts
CPackConfig.cmake libmysqld source_downloads
CPackSourceConfig.cmake libservices sql
[root@server4 mysql-5.7.17]# yum install gcc gcc-c++ ncurses-devel -y ##curses-devel为字符终端处理库
[root@server4 mysql-5.7.17]# yum install bison -y ##c c++语法分析器
数据库的编译
[root@server4 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH-BOOST=boost/boost_1_59_0/
编译环境的简单介绍
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql \ ##安装目录
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \ ##数据库存放目录
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \ ##Unix socket 文件路径
-DWITH_MYISAM_STORAGE_ENGINE=1 \ ##安装 myisam 存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ ##安装 innodb 存储引擎
-DDEFAULT_CHARSET=utf8 \ ##使用 utf8 字符
-DDEFAULT_COLLATION=utf8_general_ci \ ##校验字符
-DEXTRA_CHARSETS=all ##安装所有扩展字符集
数据库的安装
[root@server4 mysql-5.7.17]# make && make install ##安装时间较长
2.数据库文件的更改
1启动文件
[root@server4 mysql-5.7.17]# cd /usr/local
[root@server4 local]# ls
bin etc games include lib lib64 libexec lnmp sbin share src
[root@server4 local]# cd lnmp/mysql/ ##mysql的安装位置
[root@server4 mysql]# ls
bin COPYING docs include lib man mysql-test README share support-files
[root@server4 mysql]# cd support-files/ ##配置文件所在位置
[root@server4 support-files]# ls
magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server
[root@server4 support-files]# cp mysql.server /etc/init.d/mysqld ##将启动脚本复制到/etc/init.d/mysqld(默认配置文件的存在目录)
2.配置文件
(1)复制配置文件
[root@server4 support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? yes
(2)更改配置文件
18 basedir = /usr/local/lnmp/mysql ##mysql的安装目录
19 datadir = /usr/local/lnmp/mysql/data ##mysql的数据存放位置
20 # port = ..... ##mysql服务对外端口
21 # server_id = .....
22 socket = /usr/local/lnmp/mysql/data/mysql.sock ##mysql与外界联系的套接字文件位置
3.更改环境变量
[root@server4 etc]# vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
[root@server4 etc]# source ~/.bash_profile
4.添加用户及对目录权限做更改
[root@server4 etc]# groupadd -g 27 mysql
[root@server4 etc]# useradd -u 27 -g 27 mysql
[root@server4 etc]# chown mysql.mysql /usr/local/lnmp/mysql -R ##更改其目录所有者及所属组
[root@server4 etc]# chmod +x /etc/init.d/mysqld ##给与其可执行权限
5.初始化数据库
[root@server4 etc]# mysqld --user=mysql --initialize ##数据库临时密码的生成;以mysql用户身份运行
2019-06-27T15:54:45.663643Z 1 [Note] A temporary password is generated for root@localhost: !=<.HE+k6?i& ##初始化密码
[root@server4 etc]# chown root /usr/local/lnmp/mysql/ -R ##安全期间,更改用户为root
[root@server4 etc]# chown root /usr/local/lnmp/mysql/data/ -R ##数据目录所有者必须是mysql,不然mysql用户不能写
测试
[root@server4 etc]# /etc/init.d/mysqld start
Starting MySQL SUCCESS!
[root@server4 etc]# mysql -uroot -p
Enter password: !=<.HE+k6?i&
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17
Copyright (c) 2000, 2016, 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;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. ##报错需要设置安全初始化密码
[root@server4 etc]# mysql_secure_installation ##设置密码为redhat
[root@server4 etc]# mysql -uroot -predhat ##可正常使用数据库
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.17 Source distribution
Copyright (c) 2000, 2016, 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)
四.PHP
1.PHP简单介绍
一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,利于学习,使用广泛,主要适用于Web开发领域。PHP 独特的语法混合了C、Java、Perl以及PHP自创的语法。它可以比CGI或者Perl更快速地执行动态网页。用PHP做出的动态页面与其他的编程语言相比,PHP是将程序嵌入到HTML(标准通用标记语言下的一个应用)文档中去执行,执行效率比完全生成HTML标记的CGI要高许多;PHP还可以执行编译后代码,编译可以达到加密和优化代码运行,使代码运行更快
2.PHP的配置
(1)PHP的安装
源码包解压
[root@server4 etc]# cd /lnmp
[root@server4 lnmp]# ls
[root@server4 lnmp]#tar jxf php-5.6.35.tar.bz2
[root@server4 lnmp]# yum install bzip2 -y
[root@server4 lnmp]# tar jxf php-5.6.35.tar.bz2
[root@server4 lnmp]# cd php-5.6.35
[root@server4 php-5.6.35]# ./configure --help|grep mysql ##过滤php与mysql相关的模块
--with-mysql=DIR Include MySQL support. DIR is the MySQL base
mysqlnd the MySQL native driver will be used
--with-mysql-sock=SOCKPATH
--with-mysqli=FILE Include MySQLi support. FILE is the path
to mysql_config. If no value or mysqlnd is passed
--enable-embedded-mysqli
--with-pdo-mysql=DIR PDO: MySQL support. DIR is the MySQL base directory
If no value or mysqlnd is passed as DIR, the
--enable-mysqlnd Enable mysqlnd explicitly, will be done implicitly
--disable-mysqlnd-compression-support
Disable support for the MySQL compressed protocol in mysqlnd
--with-zlib-dir=DIR mysqlnd: Set the path to libz install prefix
解决依赖性
[root@server4 php-5.6.35]# yum install -y libxml2-devel libcurl-devel
[root@server4 php-5.6.35]# yum install -y libjpeg-turbo-devel-1.2.90-5.el7.x86_64
[root@server4 php-5.6.35]# yum install -y libpng-devel-1.5.13-7.el7_2.x86_64
[root@server4 php-5.6.35]# yum install -y freetype-devel-2.4.11-12.el7.x86_64
[root@server4 php-5.6.35]# yum install -y gmp-devel-6.0.0-12.el7_1.x86_64
[root@server4 php-5.6.35]# cd /lnmp
[root@server4 lnmp]# yum install libmcrypt-2.5.8-9.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
[root@server4 lnmp]# cd php-5.6.35
[root@server4 php-5.6.35]# yum install net-snmp net-snmp-devel -y
源码包编译
[root@server4 php-5.6.35]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-gmp --with-gettext --with-pear --enable-mysqlnd --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
PHP安装
[root@server4 php-5.6.35]# make && make install
3.PHP配置文件的修改
(1)复制更改配置文件
[root@server4 ~]# cd /usr/local/lnmp/php/etc/
[root@server4 etc]# ls
pear.conf php-fpm.conf.default
[root@server4 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server4 etc]# vim php-fpm.conf
25 pid = run/php-fpm.pid
149 user = nginx
150 group = nginx
(2)PHP主配置文件的复制更改
[root@server4 etc]# cd /lnmp/php-5.6.35
[root@server4 php-5.6.35]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server4 php-5.6.35]# cd -
/usr/local/lnmp/php/etc
[root@server4 etc]# vim php.ini
date.timezone = Asia/Shanghai ##修改时区,与PHP服务端时区一致
[root@server4 etc]# timedatectl status ##查看时区[root@server4 etc]# cd -
/lnmp/php-5.6.35
[root@server4 php-5.6.35]# cd sapi/fpm/
[root@server4 fpm]# ls
config.m4 LICENSE php-fpm.conf status.html.in
CREDITS Makefile.frag php-fpm.conf.in tests
fpm php-fpm php-fpm.service www.conf.in
init.d.php-fpm php-fpm.8 php-fpm.service.in
init.d.php-fpm.in php-fpm.8.in status.html
[root@server4 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@server4 fpm]# /etc/init.d/php-fpm start
-bash: /etc/init.d/php-fpm: Permission denied
[root@server4 fpm]# chmod +x /etc/init.d/php-fpm
[root@server4 fpm]# /etc/init.d/php-fpm start
Starting php-fpm done
[root@server4 fpm]# netstat -antlp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 652/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 825/master
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2124/php-fpm: maste
tcp 0 0 172.25.4.114:22 172.25.4.250:42278 ESTABLISHED 2067/sshd: root@pts
tcp6 0 0 :::22 :::* LISTEN 652/sshd
tcp6 0 0 ::1:25 :::* LISTEN 825/master
Local time: Fri 2019-06-28 03:39:03 CST
Universal time: Thu 2019-06-27 19:39:03 UTC
RTC time: Thu 2019-06-27 19:39:02
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: n/a
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
(3)启动文件的复制
[root@server4 etc]# cd -
/lnmp/php-5.6.35
[root@server4 php-5.6.35]# cd sapi/fpm/
[root@server4 fpm]# ls
config.m4 LICENSE php-fpm.conf status.html.in
CREDITS Makefile.frag php-fpm.conf.in tests
fpm php-fpm php-fpm.service www.conf.in
init.d.php-fpm php-fpm.8 php-fpm.service.in
init.d.php-fpm.in php-fpm.8.in status.html
[root@server4 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm ##复制启动脚本到/etc下
(4)php开启
[root@server4 fpm]# /etc/init.d/php-fpm start ##启动php
-bash: /etc/init.d/php-fpm: Permission denied ##权限被拒绝
[root@server4 fpm]# chmod +x /etc/init.d/php-fpm ##给与启动脚本可执行权限
[root@server4 fpm]# /etc/init.d/php-fpm start ##启动成功
Starting php-fpm done
[root@server4 fpm]# netstat -antlp ##查看php端口为9000
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 652/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 825/master
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2124/php-fpm: maste
tcp 0 0 172.25.4.114:22 172.25.4.250:42278 ESTABLISHED 2067/sshd: root@pts
tcp6 0 0 :::22 :::* LISTEN 652/sshd
tcp6 0 0 ::1:25 :::* LISTEN 825/master
4.PHP+nginx
[root@server4 etc]# nginx ##开启nginx
[root@server4 etc]# nginx -t ##检测是否有错
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server4 etc]# netstat -antlp ##查看nginx的端口为80
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2132/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 652/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 825/master
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2124/php-fpm: maste
tcp 0 0 172.25.4.114:22 172.25.4.250:42278 ESTABLISHED 2067/sshd: root@pts
tcp6 0 0 :::22 :::* LISTEN 652/sshd
tcp6 0 0 ::1:25 :::* LISTEN 825/master
[root@server4 etc]# vim /usr/local/lnmp/nginx/conf/nginx.conf ##修改配置文件
81 location / {
82 root html;
83 index index.php index.html index.htm; ##添加php页面
84 }
103 location ~ \.php$ {
104 root html;
105 fastcgi_pass 127.0.0.1:9000; ##php端口
106 fastcgi_index index.php;
107 #ifastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_na me;
108 include fastcgi.conf;
109 }
[root@server4 etc]# cd /usr/local/lnmp/nginx
[root@server4 nginx]# cd html/
[root@server4 html]# ls
50x.html bbs blog index.html www
[root@server4 html]# vim index.php
[root@server4 html]# cat index.php
<?php
phpinfo()
?>
[root@server4 html]# nginx -s reload
[root@server4 html]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
浏览器测试:http://172.25.4.114 出现php界面
五.Discuz论坛搭建
开启mysql和nginx
[root@server4 ~]# /etc/init.d/mysqld start
Starting MySQL... SUCCESS!
[root@server4 bbs]# nginx
解压论坛安装包
[root@server4 lnmp]# unzip Discuz_X3.2_SC_UTF8.zip -d /usr/local/lnmp/nginx/html/
root@server4 lnmp]# cd /usr/local/lnmp/nginx/html/
[root@server4 html]# ls
50x.html index.html index.php readme upload utility
[root@server4 html]# mv upload/ bbs ##改名为bbs
[root@server4 html]# ls
50x.html bbs index.html index.php readme utility
[root@server4 html]# cd bbs/
浏览器访问:172.25.4.114/bbs
出现目录不存在及不可写报错
解决此问题
[root@server4 bbs]# ls
admin.php connect.php forum.php member.php search.php uc_server
api cp.php group.php misc.php source userapp.php
api.php crossdomain.xml home.php plugin.php static
archiver data index.php portal.php template
config favicon.ico install robots.txt uc_client
[root@server4 bbs]# chmod 777 config/ -R
[root@server4 bbs]# chmod 777 data/ -R
[root@server4 bbs]# chmod 777 uc_server/ uc_client/ -R
刷新下一步
解决此问题
[root@server4 bbs]# vim /usr/local/lnmp/php/etc/php.ini ##修改php配置文件 解决数据库与php连接错误问题
1013 pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock
1221 mysqli.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
1162 mysql.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
[root@server4 bbs]# /etc/init.d/php-fpm reload
刷新下一步
解决此问题
[root@server4 ~]# cd /usr/local/lnmp/mysql/
[root@server4 mysql]# ls
bin data include man readme support-files
copying docs lib mysql-test share
[root@server4 mysql]# chmod 755 data/ ##给与数据权限
刷新下一步
进入管理中心
解决报错
[root@server4 bbs]# cd install/
[root@server4 install]# ls
data images include index.php
[root@server4 install]# rm -fr index.php
[root@server4 install]# ls
data images include