2019-06-11
一.環(huán)境介紹
1.LNMP
L
linux系統(tǒng)
N
nginx服務(wù)
M
MySQL數(shù)據(jù)庫(kù)
P
PHP服務(wù)
2.百度簡(jiǎn)介
LNMP代表的就是:Linux系統(tǒng)下Nginx+MySQL+PHP這種網(wǎng)站服務(wù)器架構(gòu)。
[Linux]
是一類[Unix]計(jì)算機(jī)操作系統(tǒng)的統(tǒng)稱,
是目前最流行的免費(fèi)操作系統(tǒng)。
代表版本有:[debian]、[centos]、[ubuntu]、[fedora]、[gentoo]等。
[Nginx]是一個(gè)高性能的HTTP和[反向代理]服務(wù)器,也是一個(gè)IMAP/POP3/SMTP代理服務(wù)器。
Mysql
是一個(gè)小型[關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng)]。
[PHP]
是一種在服務(wù)器端執(zhí)行的嵌入HTML文檔的[腳本語(yǔ)言]。
這四種軟件均為免費(fèi)[開源軟件]組合到一起,成為一個(gè)免費(fèi)、高效、擴(kuò)展性強(qiáng)的網(wǎng)站服務(wù)系統(tǒng).
二.查看環(huán)境
1.系統(tǒng)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服務(wù)
查看是否安裝
[root 15:31 @ web01 ~]# rpm -qa nginx
nginx-1.16.0-1.el7.ngx.x86_64
[root 15:32 @ web01 ~]#
安裝相關(guān)工具和命令
[root 15:32 @ web01 ~]# yum install -y gcc gcc-c++ autoconf pcre pcre-devel make automake wget httpd-tools vim tree
修改nginx的yum源為官方倉(cāng)庫(kù)安裝
[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服務(wù)
[root 15:48 @ web01 ~]# yum install -y nginx
啟動(dòng)服務(wù)并加入開機(jī)自啟動(dòng)
[root 16:14 @ web01 ~]# systemctl start nginx
[root 16:18 @ web01 ~]# systemctl enable nginx
3.MySQL數(shù)據(jù)庫(kù)
查看是否安裝
[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
啟動(dòng)服務(wù)并加入開機(jī)自啟動(dòng)
[root 16:14 @ web01 ~]# systemctl start mariadb
[root 16:18 @ web01 ~]# systemctl enable mariadb
4.PHP服務(wù)
查看是否安裝
[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
再使用第三方擴(kuò)展源安裝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
啟動(dòng)服務(wù)并加入開機(jī)自啟動(dòng)
[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.去指定站點(diǎn)目錄添加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";
// 創(chuàng)建連接
$conn = mysqli_connect($servername, $username, $password);
// 檢測(cè)連接
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "php連接MySQL數(shù)據(jù)庫(kù)成功";
?>
[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.根據(jù)nginx指定站點(diǎn)目錄設(shè)定的用戶和密碼
創(chuàng)建mysql數(shù)據(jù)庫(kù)中的用戶和密碼相關(guān)
進(jìn)入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)]>
數(shù)據(jù)庫(kù)命令后面必須加;(分號(hào))
創(chuàng)建數(shù)據(jù)庫(kù)wordpress
create database 數(shù)據(jù)庫(kù)名字;
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
查看所有數(shù)據(jù)庫(kù)
show databases;
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
+--------------------+
5 rows in set (0.02 sec)
MariaDB [(none)]>
創(chuàng)建數(shù)據(jù)庫(kù)wordpress的
用戶:wordpress
密碼:123456
遠(yuǎn)程登錄
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)
查看數(shù)據(jù)庫(kù)用戶信息
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)]>
刷新權(quán)限信息
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
ctrl+d
退出數(shù)據(jù)庫(kù)
四.修改完配置文件重啟服務(wù)
1.查看服務(wù)當(dāng)前狀態(tài)
[root 17:26 @ web01 ~]# systemctl status nginx php-fpm mariadb
2.查看服務(wù)是否開機(jī)自啟動(dòng)
[root 17:32 @ web01 ~]# systemctl is-enabled nginx php-fpm mariadb
enabled
enabled
enabled
[root 17:36 @ web01 ~]#
3.檢測(cè)nginx配置語(yǔ)法是否正確
[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.重啟服務(wù)
[root 17:38 @ web01 ~]# systemctl restart nginx php-fpm
五.檢測(cè)連接
1.測(cè)試一
通過(guò)瀏覽器訪問(wèn)info.php

2.測(cè)試二
通過(guò)瀏覽器訪問(wèn)mysqli.php

六.部署博客產(chǎn)品Wordpress
開源網(wǎng)站
官網(wǎng):
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
移動(dòng)wordpress目錄下所有到站點(diǎn)目錄blog下
[root 19:02 @ web01 ~]# mv wordpress/* /usr/share/nginx/html/blog/
把站點(diǎn)目錄授權(quán)給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
七.布置博客
瀏覽器輸入網(wǎng)址http://10.0.0.7













