基于LNMP搭建wordpress个人主页

N23,

操作系统:Centos7.4

数据库:Mariadb5.5

php版本:php-fpm

搭建Nginx服务

准备工作

1、关闭防火墙及selinux

[root@Nginx ~]# systemctl disable firewall

[root@Nginx ~]# systemctl stop firewall

[root@Nginx ~]#sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

2、安装开发组件(yum源安装)

[root@Mariadb ~]# yum grouplist
        Loaded plugins: fastestmirror
        Available Environment Groups:
           Minimal Install
           Compute Node
           Infrastructure Server
           File and Print Server
           Basic Web Server
           Virtualization Host
           Server with GUI
           GNOME Desktop
           KDE Plasma Workspaces
           Development and Creative Workstation
        Available Groups:
           Compatibility Libraries
           Console Internet Tools
           Development Tools
           Graphical Administration Tools
           Legacy UNIX Compatibility
           Scientific Support
           Security Tools
           Smart Card Support
           System Administration Tools
           System Management
        Done

[root@Nginx ~]#yum groupinstall -y 'Development tools'

3、下载Nginx安装包

这里是Nginx官方下载页面download_links,本次安装Nginx1.8稳定版

[root@Nginx ~]#tar -zxvf nginx-1.8.1.tar.gz

4、编译安装 编译之前需要安装一些依赖包,否则编译过程会报错:

[root@Nginx nginx-1.8.1]# yum install -y gd pcre-devel openssl-devel zlib-devel
[root@Nginx nginx-1.8.1]# ./configure \
    --prefix=/usr/local/nginx1.8 \
    --conf-path=/etc/nginx.conf \
    --error-log-path=/var/log/nginx/nginx.log \
    --pid-path=/var/run/nginx.pid \
    --user=nginx \
    --group=nginx \
    --with-http_ssl_module \
    --with-http_image_filter_module \
    --with-http_gzip_static_module \
    --with-http_auth_request_module

配置环境变量,并加载配置文件启动服务

[root@Nginx nginx-1.8.1]#export PATH=/usr/local/nginx1.8/sbin:$PATH
[root@Nginx ~]# nginx -c /etc/nginx.conf    /*指定加载配置文件,否则会报错
[root@Nginx ~]# nginx -t
nginx: the configuration file /etc/nginx.conf syntax is ok
nginx: configuration file /etc/nginx.conf test is successful
[root@Nginx ~]#nginx -s reopen

5、访问测试页

http://SERVERIP/index.html

安装PHP-FPM服务

因为Nginx本身直接仅支持FastCGI,所以,相应的php调用需要php-fpm

1、安装php-fpm(配置本地yum源安装)

[root@Nginx nginx-1.8.1]#yum install php-fpm
[root@Nginx nginx-1.8.1]#systemctl start php-fpm.service

本次实验将php-fpm与Nginx安装在同一台服务器上,故需要修改配置;

2、下面我们进行测试配置

配置nginx支持FastCGI(参照以下内容),将.php模块的#号去掉

[root@Nginx ~]#vi /etc/nginx.conf
     server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.php index.html index.htm;      /*添加index.php
        }
        location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx1.8/html/$fastcgi_script_name;
        include        fastcgi_params;
        }
        location /favicon.ico {
         root html;
        }
    }

其中fastcgi_param为php文件所在的绝对路径

在html路径下新建一个index.php测试页内容如下:

[root@Nginx ~]#cd /usr/local/nginx1.8/html
[root@localhost html]#vi index.php
        <?php
            phpinfo();
        ?>
[root@Nginx ~]#systemctl restart php-fpm
[root@Nginx ~]#nginx -s reload

3、打开php测试页,便可看到phpinfo()测试页

http://$SERVERIP/index.php

安装Mariadb数据库

[本次安装仅适用yum源安装]Mariadb官方的安装已经给的很全了,已经有针对systemd的编译的完整包,可直接下载使用

[root@Nginx ~]#yum install mariadb-server
[root@Nginx ~]#systemctl start mariadb.service
[root@Nginx ~]#mysql -uroot
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> alter user set password=password('xxxxx') where User='root';  /*设置root密码
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> grant all privileges on mysql.* to 'root'@'%';         /*root用户赋权,可以从任意主机远程访问数据库,当数据库与web服务器不在同一台主机时有效
MariaDB [mysql]> flush privileges;

更改root密码也可以使用命令mysqladmin实现

[root@Nginx ~]#mysqladmin -u root -p password xxxxxxx

测试php是否可以访问数据库

[root@Nginx ~]#vim /usr/local/nginx1.8/html/index.php
    <?php
        $link=mysql_connect('localhost','root','xxxxxx');
        if ($link)
            echo 'mysql is running!';
        else
            echo 'mysql isn't connected!';
    ?>
[root@Nginx ~]#nginx -s reload

浏览器打开 http://$SERVERIP/index.php

部署wordpress

1、Wordpress官方下载最新版本linux安装包WordPress4.8

    [root@Nginx ~]#tar -zxvf wordpress4.8.2.tar.gz
    [root@Nginx ~]#mv wordpress4.8.2/* /usr/local/nginx1.8/html/
    [root@Nginx ~]#cd /usr/local/nginx1.8/html/
    [root@Nginx html]#cp wp-config-sample.php wp-config.php
    [root@Nginx html]#vi wp-config.php
        // ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
        /** WordPress数据库的名称 */
        define('DB_NAME', 'mysql');

        /** MySQL数据库用户名 */
        define('DB_USER', 'root');

        /** MySQL数据库密码 */
        define('DB_PASSWORD', '$MYSQLPASSWORD');

        /** MySQL主机 */
        define('DB_HOST', '$DATABASEIP');

        /** 创建数据表时默认的文字编码 */
        define('DB_CHARSET', 'utf8');

        /** 数据库整理类型。如不确定请勿更改 */
        define('DB_COLLATE', '');
        ……
        ……
        ……
        /* 如果没有ftp服务器的话,需要在配置文件添加如下代码,以保证安装主题时会提示先登陆ftp服务器
        define('WP_TEMP_DIR', ABSPATH.'wp-content/tmp');
        define("FS_METHOD", "direct");
        define("FS_CHMOD_DIR", 0777);
        define("FS_CHMOD_FILE", 0777);
 

2、修改/etc/nginx.conf配置文件,以至于能正确解析wordpress的php文件

[root@Nginx ~]#vi /etc/nginx/
    location ~ \.php$ {
            root           /usr/local/nginx1.8/html/wordpress;          /*wordpress的目录,如果是html根目录,则默认即可
            fastcgi_pass   127.0.0.1:9000;          /*本地php-fpm监听地址
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx1.8/html/wordpress$fastcgi_script_name;
           include        fastcgi_params;
        }
        ……
        ……
    location \favicon.ico {
            root html;          /*防止nginx找不到favicon.ico文件而打开页面失败
    }
[root@Nginx ~]#nginx -t
[root@Nginx ~]#nginx -s reload

现在,找个浏览器就可以浏览wordpress,简单的安装即可开始个性的博客之旅。

TIM图片20171102162719

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/88183

(0)
396064847396064847
上一篇 2017-11-01 16:11
下一篇 2017-11-02 18:08

相关推荐

  • 马哥教育网络班21期+第9周课程练习

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash # declare -i nologuser=0 declare -i loguser=0 while read&…

    Linux干货 2016-09-05
  • 简单路由实验

    今天学习了路由相关的基础知识,为了加深印象,做了如下的一个实验。根据下面的网络拓扑图分别配置两台PC和路由,以实现PC1和PC2能够互相ping通。实验环境为VM虚拟机 在实验开始前,我们需要在路由添加两块网卡,PC机添加一块网卡,此实验网卡的链接方式是桥接,一共需要4台虚拟机,两台做PC机,两台做路由器 1、R2路由器的配置 [root@linuxpao&…

    Linux干货 2016-09-05
  • 第三周n28

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 who | cut -d ” ” -f 1 | sort -u 2、取出最后登录到当前系统的用户的相关信息。 who | tail -1 3、取出当前系统上被用户当作其默认shell的最多的那个shell。 cat /etc/passwd | …

    Linux干货 2017-12-17
  • Linux程序包管理方式

    Linux程序包安装和管理方式共计三种:          一、[yum|dnf],通过官网或者其他开源网站提供的文件服务器,本机镜像源等途径进行安装。         二、rpm,通过官网或者其他开源网站通过…

    Linux干货 2016-08-29
  • 编译安装bind9

    一、下载bind9.9.5源码包     可以通过www.isc.org站点来获得源码包。 二、将源码包解压到任意目录     源码包通常都是.tar.gz文件,因此我们需要先将其解压: 三、编译安装bind     1、安装前的准备工作 …

    Linux干货 2015-05-05