第48课 LNMP服务搭建 2019-06-06

第一步;搭建LNMP环境:

1、安装nginx服务:

1.1 先在新创文件nginx.repo下面写入nginx官网最新源信息:
[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 启动nginx服务,加入开机自启:
 [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数据库服务:

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 启动mysql服务,加入开机自启:
[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服务2种方法:

3.1 网络好的情况下:
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 网络不好的情况下,需要用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、创建数据库:

4.1 检查数据库和用户
[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.
'//查看所有数据库'
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.04 sec)
'//查看mysql数据库中的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 创建数据库和创建用户:
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 检查创建的用户是否生效:
[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 查看是否可以登录到数据库:
[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)]> 
可以登陆进去新创建的wordpress数据库。

5、php服务配置:

5.1 修改php文件信息:
[root@web02 ~]# egrep '^user|^group' /etc/php-fpm.d/www.conf 
user = nginx
group = nginx
5.2 修改完文件信息后,需要重启php服务:
[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

第二步:检测环境:

1、检查nginx服务和php服务是否正常:

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 在站点目录/usr/share/nginx/html/blog下面创建info.php文件:
[root@web02 ~]# cat /usr/share/nginx/html/blog/info.php 

1.3 进入浏览器检测:

php网页验证.png

出现以上图示就表明验证成功。

2、检查php服务和mysql服务是否正常:

2.1 站点目录下创建mysqli.php文件:
[root@nginx /usr/share/nginx/html/blog]# cat  mysqli.php

2.2 进入浏览器检测:

mysql检测.png

出现上图证明php服务和mysql服务已经连接成功。
第三步:搭建博客网站:

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地址,进行博客创建即可:

mysql数据库.png

证明博客搭建成功。

你可能感兴趣的:(第48课 LNMP服务搭建 2019-06-06)