LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。
#关闭防火墙和SElinux
[root@localhost ~]#systemctl status firewalld.service
[root@localhost ~]#setenforce 0
网盘分享:
链接:https://pan.baidu.com/s/1XDj0p-2f0PQMaJ7xMYQynw
提取码:swl0
#cd到 /opt目录
[root@localhost ~]#cd /opt
#从win10拖软件压缩包到linux上,ls查看
[root@localhost opt]#ls
dir_SC_UTF8 mysql-boost-5.7.20.tar.gz php-7.1.10
Discuz_X3.4_SC_UTF8.zip nginx-1.12.0 php-7.1.10.tar.bz2
mysql-5.7.20 nginx-1.12.0.tar(1).gz 说明.htm
#这里我已经把所有的压缩包都解压了
解压软件包
[root@localhost opt]#tar -zxf nginx-1.12.0.tar(1).gz
安装依赖包:
[root@localhost opt]#yum -y install pcre-devel zlib-devel gcc gcc-c++ make
新建用户 组便于管理(nginx 服务程序默认 以 nobody 身份运行,建议为其创建专门的用户账户,以便更准确的控制访问权限)
[root@localhost opt]#useradd -M -s /sbin/nologin nginx
编译安装Nginx
[root@localhost opt]#cd nginx-1.12.0/
[root@localhost opt]#./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
[root@localhost nginx-1.12.0]#make && make install -j4
#创建软连接
[root@localhost nginx-1.12.0]#ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@localhost system]#cd /lib/systemd/system
[root@localhost system]#vim 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=/usr/bin/kill -s HUP $MAINPID
ExecStop=/usr/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
加入好系统服务后,测试一下:
#测试
[root@localhost system]#systemctl start nginx.service
#查看80端口
[root@localhost system]#ss -natp | grep 80
LISTEN 0 128 *:80 *:* users:(("nginx",pid=56453,fd=6),("nginx",pid=56452,fd=6))
#关闭服务
[root@localhost system]#systemctl stop nginx.service
#先解压mysql软件包
[root@localhost system]#cd /opt
[root@localhost opt]#tar -zxf mysql-boost-5.7.20.tar.gz
[root@localhost opt]#cd mysql-5.7.20/
[root@localhost mysql-5.7.20]# yum -y install \
ncurses \
ncurses-devel \
bison \
cmake
#创建mysql用户
[root@localhost mysql-5.7.20]#useradd -s /sbin/nologin mysql
[root@localhost mysql-5.7.20]#id mysql
uid=1002(mysql) gid=1002(mysql) 组=1002(mysql)
#编译安装
[root@localhost opt]#cd 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
#make编译安装
[root@localhost mysql-5.7.20]#make && make install -j4
#修改文件的所有者和属组
[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/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 mysql-5.7.20]#chown mysql:mysql /etc/my.cnf
#设置环境变量
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile
#初始化数据库
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]#systemctl enable mysqld
[root@localhost mysql]#netstat -anpt | grep 3306
[root@localhost mysql]#systemctl start mysqld
[root@localhost mysql]#netstat -anpt | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 75436/mysqld
[root@localhost mysql]#systemctl stop mysqld
[root@localhost mysql]#systemctl status mysqld
#要开启mysql才能改密码
[root@localhost mysql]#mysqladmin -u root -p password
#登录数据库
[root@localhost mysql]#mysql -u root -p
#解压软件包
cd /opt
tar xjvf php-7.1.10.tar.bz2
cd php-7.1.10
#安装环境依赖包
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
#编译安装
./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 &&make install -j4
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]#cd /usr/local/php/lib/
#在文件中修改1170行和939行
[root@localhost php-7.1.10]#vim php.ini
1170 mysqli.default_socket = /usr/local/mysql/mysql.sock
939 date.timezone = Asia/Shanghai
[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
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
[root@localhost php-fpm.d]#/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
[root@localhost php-fpm.d]#netstat -anpt | grep 9000
#创建软连接,进行全局使用
ln -s /usr/local/php/bin/* /usr/local/bin/
[root@localhost php-fpm.d]#vim /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;
}
#编写php文件
[root@localhost php-fpm.d]#vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
#编写好后,重启一下服务
[root@localhost php-fpm.d]#systemctl restart nginx
在网页测试: http://192.168.111.128/index.php
#进入数据库
mysql -u root -p
#创建数据库,表及用户授权
CREATE DATABASE bbs;
GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY '1234';
GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY '1234';
flush privileges;
cd /opt
#解压软件包
unzip Discuz_X3.4_SC_UTF8.zip
#进入目录
cd 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://192.168.91.100/bbs/install/index.php
在网页测试:http://192.168.91.100/bbs/index.php
LNMP环境搭建部署完成。