LNMP平台就是 Linux、 Ngnix、 MySQL、PHP的组合架构,需要 Linux服务器、MySQL数据库、PHP解析环境
特点:
Ngnix特长:高并发,低资源,处理静态网络访问请求非常强
Apache:静态处理和动态处理都可以做,更适合做动态处理
Nginx:将动态资源请求交给PHP当中的fpm处理动态请求
PHP主配置文件:php.ini
Nginx将动态资源分配给FPM或Apache
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
1、安装依赖包
yum -y install gcc gcc-c++ pcre-devel zlib-devel make
2、创建运行用户
useradd -M -s /sbin/nologin nginx
3、编译安装Nginx
将nginx 安装包上传到 /opt 目录下
[root@localhost opt]#cd /opt/
[root@localhost opt]#ls
nginx-1.12.0.tar.gz rh
[root@localhost opt]#tar zxvf nginx-1.12.0.tar.gz -C /opt/
[root@localhost opt]#cd nginx-1.12.0/
[root@localhost nginx-1.12.0]#./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module
[root@localhost nginx-1.12.0]#make && make install
4、优化路径
ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
5、添加 Nginx 系统服务
vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -1 $MAINPID
ExecStop=/bin/kill -3 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost nginx-1.12.0]#chmod 754 /lib/systemd/system/nginx.service
[root@localhost nginx-1.12.0]#systemctl start nginx.service
[root@localhost nginx-1.12.0]#systemctl enable nginx.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
1、安装MySQL环境依赖包
yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake
2、创建运行用户
useradd -M -s /sbin/nologin mysql
3、编译安装
首先上传mysql-boost-5.7.20.tar.gz软件包到/opt目录下
[root@localhost opt]#cd /opt/
[root@localhost opt]#ls
mysql-boost-5.7.20.tar.gz nginx-1.12.0.tar.gz
nginx-1.12.0 rh
[root@localhost opt]#tar zxvf mysql-boost-5.7.20.tar.gz
[root@localhost opt]#cd /opt/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_EXTRA_CHARSETS=all \
-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 '守护进程'
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_EXTRA_CHARSETS=all \
-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
make -j 2 && make install
4、修改mysql 配置文件
[root@localhost mysql-5.7.20]#vim /etc/my.cnf
#删除原有内容,添加以下内容
[client] #client 用户程序
port = 3306
socket =/usr/local/mysql/mysql.sock
[mysqld] #以后对msql配置时 更多的会针对于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 #PID文件目录
socket = /usr/local/mysql/mysql.sock #通讯文件
bind-address = 0.0.0.0
skip-name-resolve
max_connnection=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1 #服务id,在之后的mysql集群中用于标识mysql服务器
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
[client]
port = 3306
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
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
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
5、更改mysql安装目录和配置文件的属主属组
[root@localhost mysql-5.7.20]#chown -R mysql:mysql /usr/local/mysql/
[root@localhost mysql-5.7.20]#chown mysql:mysql /etc/my.cnf
6、设置路径环境变量
[root@localhost mysql-5.7.20]#echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@localhost mysql-5.7.20]#source /etc/profile
7、初始化数据库
[root@localhost mysql-5.7.20]#cd /usr/local/mysql/bin/
[root@localhost bin]#
./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
8、添加mysql 系统服务
[root@localhost bin]#cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
[root@localhost bin]#systemctl daemon-reload
[root@localhost bin]#systemctl start mysqld.service
[root@localhost bin]#systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@localhost bin]#netstat -anpt | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 29473/mysqld
9、修改mysql 的登录密码
mysqladmin -u root -p password "abc123"
10、授权远程登录
mysql -u root -p
grant all privileges on *.* to 'root'@'%' identified by 'abc123';
#授予root用户可以在所有终端远程登录,使用的密码是abc123,并对所有数据库和所有表有操作权限
show databases; #查看当前已有的数据库
1、安装环境依赖包
yum -y install \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
2、编译安装PHP
首先将 php-7.1.10.tar.bz2压缩包上传到/opt目录下
[root@localhost opt]#cd /opt/
[root@localhost opt]#ls
mysql-5.7.20 nginx-1.12.0.tar.gz
mysql-boost-5.7.20.tar.gz php-7.1.10.tar.bz2
nginx-1.12.0 rh
[root@localhost opt]#tar jxvf php-7.1.10.tar.bz2
cd 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
make && make install
3、路径优化
ln -s /usr/local/php/bin/* /usr/local/bin/
4、修改PHP配置文件
PHP有三个配置文件
php.ini 主配置文件
php-fpm.conf 进程服务配置文件
www.conf 扩展配置文件
------修改主配置文件---------
[root@localhost php-7.1.10]#cp /opt/php-7.1.10/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
------取消注释并修改939行------
date.timezone = Asia/Shanghai
php -m #验证安装的模块
----------修改进程服务配置文件----------
[root@localhost etc]#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/php-fpm.d/
[root@localhost php-fpm.d]#cp www.conf.default www.conf
5、启动php-fpm
[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 35323/php-fpm: mast
#PHP-FPM(FasttCGI Process Manager: FastCGI 进程管理器)是一个 PHPFastCGI 管理器,由于Nginx服务器不能处理动态页面,需要由nginx 把动态请求交给 php-fpm 进程进行解析。
6、配置 Nginx 支持php解析
[root@localhost php-fpm.d]#vim /usr/local/nginx/conf/nginx.conf
------65行取消注释并修改------
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 mysql]#systemctl restart nginx.service
7、验证PHP测试页
[root@localhost mysql]#vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
浏览器访问:http://
8、验证数据库工作是否正常
mysq1 -u root -p
CREATE DATABASE bbs;
GRANT all ON bbs.* To 'bbsuser'@'%' IDENTIFIED BY 'admin123';
GRANT all ON bbs.* To 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';
flush privileges;
vim /usr/local/nginx/html/index.php ###原来的测试页内容更改如下
<?php
$link=mysqli_connect('192.168.200.50','bbsuser','admin123');
if($link) echo"Success!!
";
else echo "Fail!!";
?>
systemctl restart nginx
在网页测试:http://192.168.121.100/index.php
[root@localhost?mysql]#cd /opt/
[root@localhost?opt]#ls
Discuz_X3.4_SC_UTF8.zip nginx-1.12.0.tar.gz
mysql-5.7.20 php-7.1.10
mysql-boost-5.7.20.tar.gz php-7.1.10.tar.bz2
nginx-1.12.0 rh
[root@localhost?opt]#unzip Discuz_X3.4_SC_UTF8.zip -d /opt/dis
[root@localhost opt]#cd /opt/dis/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://192.168.200.50/bbs/install/index.php
论坛页面访问:http:192.168.200.50/bbs/install/index.php
数据库服务器:localhost
数据库名字:bbs
数据库用户名:bbsuser
数据库密码:admin123
管理员账号:admin
管理员密码:admin123