2019-06-11
一.环境介绍
1.LNMP
L
linux系统
N
nginx服务
M
MySQL数据库
P
PHP服务
2.百度简介
LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。
[Linux]
是一类[Unix]计算机操作系统的统称,
是目前最流行的免费操作系统。
代表版本有:[debian]、[centos]、[ubuntu]、[fedora]、[gentoo]等。
[Nginx]是一个高性能的HTTP和[反向代理]服务器,也是一个IMAP/POP3/SMTP代理服务器。
Mysql
是一个小型[关系型数据库管理系统]。
[PHP]
是一种在服务器端执行的嵌入HTML文档的[脚本语言]。
这四种软件均为免费[开源软件]组合到一起,成为一个免费、高效、扩展性强的网站服务系统.
二.查看环境
1.系统centOS7
[root 15:31 @ web01 ~]# uname -a
Linux web01 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root 15:31 @ web01 ~]#
2.nginx服务
查看是否安装
[root 15:31 @ web01 ~]# rpm -qa nginx
nginx-1.16.0-1.el7.ngx.x86_64
[root 15:32 @ web01 ~]#
安装相关工具和命令
[root 15:32 @ web01 ~]# yum install -y gcc gcc-c++ autoconf pcre pcre-devel make automake wget httpd-tools vim tree
修改nginx的yum源为官方仓库安装
[root 15:35 @ web01 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
安装nginx服务
[root 15:48 @ web01 ~]# yum install -y nginx
启动服务并加入开机自启动
[root 16:14 @ web01 ~]# systemctl start nginx
[root 16:18 @ web01 ~]# systemctl enable nginx
3.MySQL数据库
查看是否安装
[root 16:13 @ web01 ~]# rpm -qa mariadb-server mariadb
mariadb-5.5.60-1.el7_5.x86_64
mariadb-server-5.5.60-1.el7_5.x86_64
[root 16:14 @ web01 ~]#
安装
[root 15:48 @ web01 ~]# yum install -y mariadb-server mariadb
启动服务并加入开机自启动
[root 16:14 @ web01 ~]# systemctl start mariadb
[root 16:18 @ web01 ~]# systemctl enable mariadb
4.PHP服务
查看是否安装
[root 15:56 @ web01 ~]# rpm -qa php*
php71w-common-7.1.29-1.w7.x86_64
php71w-xml-7.1.29-1.w7.x86_64
php71w-pecl-igbinary-2.0.5-1.w7.x86_64
php71w-gd-7.1.29-1.w7.x86_64
php71w-mysqlnd-7.1.29-1.w7.x86_64
php71w-fpm-7.1.29-1.w7.x86_64
php71w-cli-7.1.29-1.w7.x86_64
php71w-pdo-7.1.29-1.w7.x86_64
php71w-pear-1.10.4-1.w7.noarch
php71w-mcrypt-7.1.29-1.w7.x86_64
php71w-pecl-redis-3.1.6-1.w7.x86_64
php71w-pecl-mongodb-1.5.3-1.w7.x86_64
php71w-devel-7.1.29-1.w7.x86_64
php71w-opcache-7.1.29-1.w7.x86_64
php71w-embedded-7.1.29-1.w7.x86_64
php71w-process-7.1.29-1.w7.x86_64
php71w-pecl-memcached-3.0.4-1.w7.x86_64
php71w-mbstring-7.1.29-1.w7.x86_64
[root 15:56 @ web01 ~]#
先删除已安装的PHP包
yum remove 安装包
[root 15:56 @ web01 ~]# yum remove php-mysql-5.4 php php-fpm php-common
再使用第三方扩展源安装php7.1
[root 16:25 @ web01 ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Retrieving https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
warning: /var/tmp/rpm-tmp.1hDpfh: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Preparing... ################################# [100%]
package epel-release-7-11.noarch is already installed
[root 16:28 @ web01 ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Preparing... ################################# [100%]
package webtatic-release-7-3.noarch is already installed
[root 16:28 @ web01 ~]#
安装php
[root 16:28 @ web01 ~]# yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
启动服务并加入开机自启动
[root 16:28 @ web01 ~]# systemctl start php-fpm
[root 16:28 @ web01 ~]# systemctl enable php-fpm
三.修改配置文件
1.在nginx配置.conf文件添加location模块php
[root 16:36 @ web01 /etc/nginx/conf.d]# vim blog.conf
server {
listen 80;
server_name blog.oldboy.com;
access_log /var/log/nginx/access_blog.log main;
root /usr/share/nginx/html/blog;
location / {
index index.php index.html index.htm;
}
location ~* \.(php|php5)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
2.去指定站点目录添加php文件
[root 16:39 @ web01 /usr/share/nginx/html/blog]# ls
blog.html info.php mysqli.php
[root 16:42 @ web01 /usr/share/nginx/html/blog]# cat info.php
<?php
phpinfo();
?>
[root 16:42 @ web01 /usr/share/nginx/html/blog]# cat mysqli.php
<?php
$servername = "localhost";
$username = "wordpress";
$password = "123456";
// 创建连接
$conn = mysqli_connect($servername, $username, $password);
// 检测连接
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "php连接MySQL数据库成功";
?>
[root 16:43 @ web01 /usr/share/nginx/html/blog]#
3.修改php配置文件
/etc/php-fpm.d/www.conf
使用户主用户组一致都为nginx
[root 16:43 @ web01 /usr/share/nginx/html/blog]# vim /etc/php-fpm.d/www.conf
1 ; Start a new pool named 'www'.
2 [www]
3
4 ; Unix user/group of processes
5 ; Note: The user is mandatory. If the group is not set, the default user's group
6 ; will be used.
7 ; RPM: apache Choosed to be able to access some dir as httpd
8 user = nginx
9 ; RPM: Keep a group allowed to write in log dir.
10 group = nginx
11
4.根据nginx指定站点目录设定的用户和密码
创建mysql数据库中的用户和密码相关
进入mysql
[root 16:53 @ web01 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
数据库命令后面必须加;(分号)
创建数据库wordpress
create database 数据库名字;
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
查看所有数据库
show databases;
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
+--------------------+
5 rows in set (0.02 sec)
MariaDB [(none)]>
创建数据库wordpress的
用户:wordpress
密码:123456
远程登录
MariaDB [(none)]> grant all on wordpress.* to 'wordpress'@'172.16.1.%' identified by '123456';
本地登录
MariaDB [(none)]> grant all on wordpress.* to 'wordpress'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
查看数据库用户信息
MariaDB [(none)]> select user,host from mysql.user;
+-----------+------------+
| user | host |
+-----------+------------+
| root | 127.0.0.1 |
| wordpress | 172.16.1.% |
| root | ::1 |
| | localhost |
| root | localhost |
| wordpress | localhost |
| | web01 |
| root | web01 |
+-----------+------------+
8 rows in set (0.00 sec)
MariaDB [(none)]>
刷新权限信息
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
ctrl+d
退出数据库
四.修改完配置文件重启服务
1.查看服务当前状态
[root 17:26 @ web01 ~]# systemctl status nginx php-fpm mariadb
2.查看服务是否开机自启动
[root 17:32 @ web01 ~]# systemctl is-enabled nginx php-fpm mariadb
enabled
enabled
enabled
[root 17:36 @ web01 ~]#
3.检测nginx配置语法是否正确
[root 17:41 @ web01 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root 17:41 @ web01 ~]#
4.重启服务
[root 17:38 @ web01 ~]# systemctl restart nginx php-fpm
五.检测连接
1.测试一
通过浏览器访问info.php
2.测试二
通过浏览器访问mysqli.php
六.部署博客产品Wordpress
开源网站
官网:
https://cn.wordpress.org/
wordpress开源博客压缩包链接:
https://pan.baidu.com/s/1KOI3FZV8VY22rxD731pp0g
提取码: 7naq
把压缩包从windowns电脑上传到linux
[root 18:11 @ web01 ~]# rz
查看压缩包
[root 18:11 @ web01 ~]# ls
anaconda-ks.cfg 博客wordpress-5.2.1.tar.gz
解压
[root 19:01 @ web01 ~]# tar xf 博客wordpress-5.2.1.tar.gz
查看
[root 19:01 @ web01 ~]# ls
anaconda-ks.cfg wordpress 博客wordpress-5.2.1.tar.gz
查看目录属主属组
[root 19:01 @ web01 ~]# ll -d wordpress
drwxr-xr-x 5 nobody 65534 4096 May 22 02:24 wordpress
移动wordpress目录下所有到站点目录blog下
[root 19:02 @ web01 ~]# mv wordpress/* /usr/share/nginx/html/blog/
把站点目录授权给nginx
[root 19:03 @ web01 ~]# chown -R nginx.nginx /usr/share/nginx/html/blog
查看
[root 19:04 @ web01 ~]# ll -d /usr/share/nginx/html/blog
drwxr-xr-x 5 nginx nginx 4096 Jun 11 19:03 /usr/share/nginx/html/blog
七.布置博客
浏览器输入网址http://10.0.0.7