lnmp(linux+nginx+mysql+php)搭建个人博客wordpress--(linux运维19)

1. nginx的安装

使用的是yum的安装所以首先要保证虚拟机有网络,前边博客有写nginx安装,这里就直接写安装过程
第一步:

vim /etc/yum.repos.d/nginx.repo 
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

第二步:

yum -y install nginx

第三步:

useradd www -s /sbin/nologin -M
sed -i '/^user/c user www;' /etc/nginx/nginx.conf
grep "^user" /etc/nginx/nginx.conf

第四步:

systemctl start nginx
systemctl enable nginx

2. MySQL(mariadb)安装

第一步:

yum install mariadb-server mariadb -y	

第二步:启动数据库

systemctl strat mariadb
systemctl enable mariadb

第三步:设置密码
参数说明

/application/mysql/bin/mysqladmin -u root          password 'new-password'   --- 给本地数据库设置密码
/application/mysql/bin/mysqladmin -u root -h web01 password 'new-password'   --- 给远程数据库设置密码
mysqladmin -uroot password 123456

登录:

mysql -uroot -p123456
[root@web02 17:27:44 /var/log/nginx]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.68-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.00 sec)

3. php安装

第一步:更新yum源,卸载自带的php

yum remove php-mysql php php-fpm php-common
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

第二步安装:

yum install -y 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	

第三步:编写配置文件

vim /etc/php-fpm.d/www.conf
user = www   nginx---www
group = www
PS: 保证nginx进程的管理用户和php服务进程的管理用户保持一致

第四步: 启动php服务

systemctl start php-fpm 
[root@web02 17:33:46 /var/log/nginx]# systemctl start php-fpm
[root@web02 17:33:53 /var/log/nginx]# ps -ef |grep php
root     10950     1  0 17:33 ?        00:00:00 php-fpm: master process (/etc/php-fpm.conf)
www      10951 10950  0 17:33 ?        00:00:00 php-fpm: pool www
www      10952 10950  0 17:33 ?        00:00:00 php-fpm: pool www
www      10953 10950  0 17:33 ?        00:00:00 php-fpm: pool www
www      10954 10950  0 17:33 ?        00:00:00 php-fpm: pool www
www      10955 10950  0 17:33 ?        00:00:00 php-fpm: pool www
root     10963  9532  0 17:34 pts/2    00:00:00 grep --color=auto php

4. lnmp之间建立联系(只是测试,可以直接第五步)

4.1 nginx与php

server {
       listen        80;
       server_name   blog.yq.com;
       location  / {
         root  /html/blog;
         index index.php  index.html;
       }
       location ~ \.php$ {
                root /html/blog;
                fastcgi_index index.php;          
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass  127.0.0.1:9000;
                include fastcgi_params;
       }
    }

编写动态资源文件

cat /html/blog/test_php.php 
<?php
   phpinfo();
?>

访问测试:

  blog.yq.com/test_php.php

在这里插入图片描述

4.2 php与mysql之间建立关系

编写文件

 vim test_mysql.php
 <?php
        $servername = "localhost";
        $username = "root";
        $password = "123456";
        $link_id=mysql_connect('主机名','用户','密码');
        $conn = mysqli_connect($servername, $username, $password);
        if ($conn) {
              echo "mysql successful by root !\n";
           }else{
              die("Connection failed: " . mysqli_connect_error());
           }
       ?>

5. 博客的搭建(第四步只是测试,可以直接第五步)

5.1blog网站页面:

https://cn.wordpress.org/
下载上传到站点目录
解压:

 tar xf wordpress-5.8.1-zh_CN.tar.gz 

移动到/html/blog目录下

mv wordpress/* blog/

修改目录属主属组

[root@web02 17:58:16 /html]# chown -R www.www blog/
[root@web02 17:58:19 /html]# ll blog/
total 208
-rw-r--r--  1 www www   405 Feb  6  2020 index.php
-rw-r--r--  1 www www 19915 Jan  1  2021 license.txt
-rw-r--r--  1 www www  7346 Jul  6 20:23 readme.html
-rw-r--r--  1 www www  7165 Jan 21  2021 wp-activate.php
drwxr-xr-x  9 www www  4096 Sep 17 16:00 wp-admin
-rw-r--r--  1 www www   351 Feb  6  2020 wp-blog-header.php
-rw-r--r--  1 www www  2328 Feb 17  2021 wp-comments-post.php
-rw-r--r--  1 www www  3004 May 21 18:40 wp-config-sample.php
drwxr-xr-x  5 www www    69 Sep 17 16:00 wp-content
-rw-r--r--  1 www www  3939 Jul 31  2020 wp-cron.php
drwxr-xr-x 25 www www  8192 Sep 17 16:00 wp-includes
-rw-r--r--  1 www www  2496 Feb  6  2020 wp-links-opml.php
-rw-r--r--  1 www www  3900 May 16 01:38 wp-load.php
-rw-r--r--  1 www www 45463 Apr  7 02:39 wp-login.php
-rw-r--r--  1 www www  8509 Apr 14  2020 wp-mail.php
-rw-r--r--  1 www www 22297 Jun  2 07:09 wp-settings.php
-rw-r--r--  1 www www 31693 May  8 04:16 wp-signup.php
-rw-r--r--  1 www www  4747 Oct  9  2020 wp-trackback.php
-rw-r--r--  1 www www  3236 Jun  9  2020 xmlrpc.php

5.2 配饰文件的设置

nginx的配置文件

vim /etc/nginx/conf.d/blog.conf
server {
       listen        80;
       server_name   blog.yq.com;
       location  / {
         root  /html/blog;
         index index.php  index.html;
       }
       location ~ \.php$ {
                root /html/blog;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass  127.0.0.1:9000;
                include fastcgi_params;  
       }
    }
systemctl restart nginx

5.3 网站的配置

上边的步骤好了,打开浏览器访问:

blog.yq.com 

前提你要配置hosts

访问:

192.168.246.8 blog.yq.com 

选择中文,现在就开始
在这里插入图片描述
下一步:
在这里插入图片描述
这里我们要创建数据库;授权一个用户

mysql -uroot -p123456

create database wordpress;
grant all on wordpress.* to wordpress@'localhost' indentified by '123456';
MariaDB [(none)]> select user,host from mysql.user;
+-----------+-----------+
| user      | host      |
+-----------+-----------+
| root      | 127.0.0.1 |
| root      | ::1       |
|           | localhost |
| root      | localhost |
| wordpress | localhost |
|           | web02     |
| root      | web02     |
+-----------+-----------+
7 rows in set (0.00 sec)

创建好了数据库之后,填写
在这里插入图片描述
下一步:
在这里插入图片描述
下一步:
在这里插入图片描述
安装WordPress:
在这里插入图片描述
根据自己的账号面登录即可:
在这里插入图片描述

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

长安有故里y

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值