第一步;搭建LNMP環(huán)境:
1、安裝nginx服務(wù):
1.1 先在新創(chuàng)文件nginx.repo下面寫(xiě)入nginx官網(wǎng)最新源信息:
[root@web02 ~]# cat /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
1.2 啟動(dòng)nginx服務(wù),加入開(kāi)機(jī)自啟:
[root@web02 ~]# systemctl start nginx
[root@web02 ~]# systemctl enable nginx
[root@web02 ~]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2019-06-11 15:53:23 CST; 12min ago
Docs: http://nginx.org/en/docs/
Main PID: 7232 (nginx)
CGroup: /system.slice/nginx.service
├─7232 nginx: master process /usr/sbin/nginx -c /et...
└─7233 nginx: worker process
Jun 11 15:53:22 web02 systemd[1]: Starting nginx - high perfo....
Jun 11 15:53:23 web02 systemd[1]: PID file /var/run/nginx.pid....
Jun 11 15:53:23 web02 systemd[1]: Started nginx - high perfor....
Hint: Some lines were ellipsized, use -l to show in full.
2、 安裝mysql數(shù)據(jù)庫(kù)服務(wù):
2.1 安裝mysql:
[root@web02 ~]# yum install -y mariadb-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.nwsuaf.edu.cn
* updates: mirrors.163.com
* webtatic: us-east.repo.webtatic.com
Package 1:mariadb-server-5.5.60-1.el7_5.x86_64 already installed and latest version
Nothing to do
2.2 啟動(dòng)mysql服務(wù),加入開(kāi)機(jī)自啟:
[root@web02 ~]# systemctl start mariadb.service
[root@web02 ~]# systemctl enable mariadb.service
[root@web02 ~]# systemctl status mariadb.service
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2019-06-11 15:53:28 CST; 23min ago
Main PID: 7289 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─7289 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─7453 /usr/libexec/mysqld --basedir=/usr --datadir...
Jun 11 15:53:22 web02 systemd[1]: Starting MariaDB database s....
Jun 11 15:53:23 web02 mariadb-prepare-db-dir[7211]: Database M...
Jun 11 15:53:24 web02 mysqld_safe[7289]: 190611 15:53:24 mysql...
Jun 11 15:53:24 web02 mysqld_safe[7289]: 190611 15:53:24 mysql...
Jun 11 15:53:28 web02 systemd[1]: Started MariaDB database se....
Hint: Some lines were ellipsized, use -l to show in full.
3、安裝php服務(wù)2種方法:
3.1 網(wǎng)絡(luò)好的情況下:
1、rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
2、rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
3、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
3.2 網(wǎng)絡(luò)不好的情況下,需要用rpm包安裝:
1、命令:rpm -ivh ‘壓縮包文件’
2、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
4、創(chuàng)建數(shù)據(jù)庫(kù):
4.1 檢查數(shù)據(jù)庫(kù)和用戶
[root@web02 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
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.
'//查看所有數(shù)據(jù)庫(kù)'
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.04 sec)
'//查看mysql數(shù)據(jù)庫(kù)中的user表中的user列和host列(用戶)'
MariaDB [(none)]> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | web02 |
| root | web02 |
+------+-----------+
6 rows in set (0.00 sec)
4.2 創(chuàng)建數(shù)據(jù)庫(kù)和創(chuàng)建用戶:
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on wordpress.* to 'wordpress'@'172.16.1.%' identified by '123456';
Query OK, 0 rows affected (0.03 sec)
MariaDB [(none)]> grant all on wordpress.* to 'wordpress'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
4.4 檢查創(chuàng)建的用戶是否生效:
[root@web02 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
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)]> select user,host from mysql.user;
+-----------+------------+
| user | host |
+-----------+------------+
| root | 127.0.0.1 |
| wordpress | 172.16.1.% |
| root | ::1 |
| | localhost |
| root | localhost |
| wordpress | localhost |
| | web02 |
| root | web02 |
+-----------+------------+
8 rows in set (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
+--------------------+
5 rows in set (0.00 sec)
4.5 查看是否可以登錄到數(shù)據(jù)庫(kù):
[root@web02 ~]# mysql -uwordpress -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
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)]>
可以登陸進(jìn)去新創(chuàng)建的wordpress數(shù)據(jù)庫(kù)。
5、php服務(wù)配置:
5.1 修改php文件信息:
[root@web02 ~]# egrep '^user|^group' /etc/php-fpm.d/www.conf
user = nginx
group = nginx
5.2 修改完文件信息后,需要重啟php服務(wù):
[root@web02 ~]# systemctl restart php-fpm.service
[root@web02 ~]# ss -lntup|grep 9000
tcp LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",pid=8216,fd=9),("php-fpm",pid=8215,fd=9),("php-fpm",pid=8214,fd=9),("php-fpm",pid=8213,fd=9),("php-fpm",pid=8212,fd=9),("php-fpm",pid=8210,fd=7))
[root@web02 ~]# ps -ef |grep php
root 8210 1 0 17:08 ? 00:00:00 php-fpm: master process (/etc/php-fpm.conf)
nginx 8212 8210 0 17:08 ? 00:00:00 php-fpm: pool www
nginx 8213 8210 0 17:08 ? 00:00:00 php-fpm: pool www
nginx 8214 8210 0 17:08 ? 00:00:00 php-fpm: pool www
nginx 8215 8210 0 17:08 ? 00:00:00 php-fpm: pool www
nginx 8216 8210 0 17:08 ? 00:00:00 php-fpm: pool www
root 8239 7777 0 17:09 pts/0 00:00:00 grep --color=auto php
第二步:檢測(cè)環(huán)境:
1、檢查nginx服務(wù)和php服務(wù)是否正常:
1.1 conf.d下面的主配置文件:
[root@web01-13 /etc/nginx/conf.d]# cat 02-blog.conf.bak
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;
}
}
1.2 在站點(diǎn)目錄/usr/share/nginx/html/blog下面創(chuàng)建info.php文件:
[root@web02 ~]# cat /usr/share/nginx/html/blog/info.php
<?php
phpinfo();
?>
1.3 進(jìn)入瀏覽器檢測(cè):

php網(wǎng)頁(yè)驗(yàn)證.png
出現(xiàn)以上圖示就表明驗(yàn)證成功。
2、檢查php服務(wù)和mysql服務(wù)是否正常:
2.1 站點(diǎn)目錄下創(chuàng)建mysqli.php文件:
[root@nginx /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ù)成功";
?>
2.2 進(jìn)入瀏覽器檢測(cè):

mysql檢測(cè).png
出現(xiàn)上圖證明php服務(wù)和mysql服務(wù)已經(jīng)連接成功。
第三步:搭建博客網(wǎng)站:
3.1 代碼上線具體步驟:
[root@web02 ~]# tar xf wordpress-5.2.1.tar.gz
[root@web02 ~]# ll
total 10980
drwxr-xr-x 5 nobody 65534 4096 May 22 02:24 wordpress
-rw-r--r-- 1 root root 11199196 Jun 8 08:48 wordpress-5.2.1.tar.gz
[root@web02 ~] mv wordpress/* /usr/share/nginx/html/blog/
[root@web02 ~] chown -R nginx.nginx /usr/share/nginx/html/blog/
[root@web02 ~]# ll -d nginx.nginx /usr/share/nginx/html/blog/
ls: cannot access nginx.nginx: No such file or directory
drwxr-xr-x 5 nginx nginx 4096 Jun 11 17:37 /usr/share/nginx/html/blog/
3.2 瀏覽器直接輸入IP地址,進(jìn)行博客創(chuàng)建即可:

mysql數(shù)據(jù)庫(kù).png
證明博客搭建成功。