LNMP环境搭建wordpress

LNMP

Linux Nginx Mysql PHP

LNMT

Linux Nginx Mysql Tomcat(JAVA)

搭建博客网站blog.wsm.com

1.部署nginx

参见web服务部署过程
],修改nginx配置文件

[root@test01 conf]# vim conf.d/blog.conf 
server {
        listen       80;
        server_name  blog.wsm.com;
        location / {
            root   html/gcy;
            index  index.php index.html index.htm;
        }
        location ~* \.(php|php5)$ {                       #添加location 匹配正则 以.php .php5结尾
            root   html/blog;                                   #站点目录
            fastcgi_pass   127.0.0.1:9000;           
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}

测试nginx是否正常-静态

[root@test01 conf]# curl -H Host:blog.wsm.com 10.0.0.111
blog gcy

2.安装MySQL

Centos7中mysql 替换为 mariadb

安装
yum -y install mariadb-server
启动mariadb
systemctl start mariadb

检查是否有进程

root@test01 ~]# ps -ef |grep mysql
mysql     32529      1  0 05:59 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql     32691  32529  0 05:59 ?        00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root      32728  11511  0 06:00 pts/1    00:00:00 grep --color=auto mysql

默认端口号3306

[root@test01 ~]# ss -lntup|grep mysql
tcp    LISTEN     0      50        *:3306                  *:*                   users:(("mysqld",pid=32691,fd=13))

进入mysql
[root@test01 ~]# mysql -uroot -p

  • 显示所有数据库
    show databases;
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)
  • 创建数据库
    create database wordpress;
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.00 sec)
MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
  • 查看用户
    select user,host from mysql.user;
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  |
|           | test01     |
| root      | test01     |
+-----------+------------+
8 rows in set (0.00 sec)
  • 删除无用用户
    drop user ''@'localhost' ;
MariaDB [(none)]> drop user ''@'localhost' ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> drop user ''@'test01' ;
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        |
| root      | localhost  |
| wordpress | localhost  |
| root      | test01     |
+-----------+------------+
6 rows in set (0.00 sec)
  • 更新一下权限信息
    flush privileges ;
MariaDB [(none)]> flush  privileges ;
Query OK, 0 rows affected (0.00 sec)

3.安装PHP

先配置php yum源安装
yum remove php-mysql-5.4 php php-fpm php-common #移除系统中已存在的数据库及php等
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 -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

  • 修改php-fpm.d配置文件
[root@test01 ~]# vim /etc/php-fpm.d/www.conf 
[root@test01 ~]# grep -n '=.www' /etc/php-fpm.d/www.conf 
8:user = www
10:group = www
  • systemctl restart php-fpm 重启

检查端口与进程,端口为9000

[root@test01 ~]# ss -lntup |grep php-fpm
tcp    LISTEN     0      128    127.0.0.1:9000                  *:*                   users:(("php-fpm",pid=32779,fd=9),("php-fpm",pid=32778,fd=9),("php-fpm",pid=32777,fd=9),("php-fpm",pid=32776,fd=9),("php-fpm",pid=32775,fd=9),("php-fpm",pid=32774,fd=7))
[root@test01 ~]# ps -ef |grep php
root      32774      1  0 06:37 ?        00:00:00 php-fpm: master process (/etc/php-fpm.conf)
www       32775  32774  0 06:37 ?        00:00:00 php-fpm: pool www
www       32776  32774  0 06:37 ?        00:00:00 php-fpm: pool www
www       32777  32774  0 06:37 ?        00:00:00 php-fpm: pool www
www       32778  32774  0 06:37 ?        00:00:00 php-fpm: pool www
www       32779  32774  0 06:37 ?        00:00:00 php-fpm: pool www
root      32785  11511  0 06:39 pts/1    00:00:00 grep --color=auto php

4.联合测试

  • 测试nginx是否正常-静态
[root@test01 conf]# curl -H Host:blog.wsm.com 10.0.0.111
blog gcy
  • 测试php是否正常-显示动态 nginx + php

写入一个测试文件
[root@test01 blog]# cat /application/nginx-1.14.2/html/blog/info.php
<?php
phpinfo();
?>

浏览器访问blog.wsm.com/info.php显示页面

image.png

表示成功

  • 测试php与mariadb
    写入一个测试文件
[root@web01 blog]#cat /application/nginx-1.14.2/html/blog/mysql.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数据库成功";
?>

浏览器访问blog.wsm.com/mysql.php显示页面

image.png

########LNMP部署完成########

  • 下载wordpress 搭建网站 放入程序代码

unzip wordpress-5.0.3-zh_CN.zip
mv wordpress/* /application/nginx-1.14.2/html/blog/
chown www.www /application/nginx-1.14.2/html/blog/

  • 浏览器访问blog.wsm.com
image.png

填写信息成功访问


image.png

显示数据库内容

MariaDB [(none)]> show tables from wordpress;
+-----------------------+
| Tables_in_wordpress   |
+-----------------------+
| wp_commentmeta        |
| wp_comments           |
| wp_links              |
| wp_options            |
| wp_postmeta           |
| wp_posts              |
| wp_term_relationships |
| wp_term_taxonomy      |
| wp_termmeta           |
| wp_terms              |
| wp_usermeta           |
| wp_users              |
+-----------------------+
12 rows in set (0.00 sec)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 买的时候真的以为就是干枯的树枝,因为不贵,就买了 真的就是一把干枝,像路边捡的 一周后就有变化了 又过了两天后 早...
    白若丁阅读 4,514评论 0 0
  • 凭栏江辽阔, 舟随楼影动。 夕阳一点斜, 江心两日圆。
    抱一阅读 1,864评论 2 1
  • 在栅格数据中,像元通常表示主导要素或像元覆盖区域的现象,而矢量数据则可精确描绘或识别各个要素。如何表达空间对象是栅...
    Gerhard_杨光辉阅读 7,132评论 0 1

友情链接更多精彩内容