GVKun编程网logo

Centos7.4-LNMP快速部署wordpress(centos7搭建wordpress)

15

针对Centos7.4-LNMP快速部署wordpress和centos7搭建wordpress这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展CentOS6.4安装配置LNMP服务器搭建W

针对Centos7.4-LNMP快速部署wordpresscentos7搭建wordpress这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展CentOS 6.4安装配置LNMP服务器搭建Wordpress、CentOS 6.5安装WordPress(基于LNMP)、centos 6.9 快速部署lnmp网站、CentOS 7 yum安装LAMP,LNMP并搭建WordPress个人博客网站等相关知识,希望可以帮助到你。

本文目录一览:

Centos7.4-LNMP快速部署wordpress(centos7搭建wordpress)

Centos7.4-LNMP快速部署wordpress(centos7搭建wordpress)

环境准备

[[email protected] ~]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
[[email protected] ~]# uname -r
3.10.0-693.el7.x86_64

下载LNMP软件包

[[email protected] ~]# yum install -y Nginx mariadb-server PHP-MysqL PHP-fpm
启动LNMP服务
[[email protected] ~]# systemctl start Nginx.service mariadb.service PHP-fpm.service
[[email protected] ~]# systemctl enable Nginx.service mariadb.service PHP-fpm.service
检查LNMP服务是否启动
[[email protected] ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0: LISTEN 1726/Nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:
LISTEN 1173/sshd
tcp 0 0 127.0.0.1:9000 0.0.0.0: LISTEN 1682/PHP-fpm: maste
tcp 0 0 0.0.0.0:3306 0.0.0.0:
LISTEN 1934/MysqLd
tcp6 0 0 :::80 ::: LISTEN 1726/Nginx: master
tcp6 0 0 :::22 :::
LISTEN 1173/sshd
udp 0 0 127.0.0.1:323 0.0.0.0: 713/chronyd
udp6 0 0 ::1:323 :::
713/chronyd

编写Nginx配置文件

[[email protected] ~]# cat /etc/Nginx/Nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index index.PHP index.html index.htm;
        }
        location ~ \.PHP$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.PHP;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

创建wordpress用户,并授权

[[email protected] ~]# MysqL
MariaDB [(none)]> create database wordpress;
Query OK,1 row affected (0.00 sec)
MariaDB [(none)]> grant all on wordpress. to ‘wordpress’@’localhost’ identified by ‘123456’;
Query OK,0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK,0 rows affected (0.00 sec)
MariaDB [(none)]> exit
将wordpress导入到Nginx站点目录下
[[email protected] ~]# mv wordpress/
/usr/share/Nginx/html/

重启Nginx服务

[[email protected] ~]# systemctl restart Nginx.service

登录浏览器访问测试

Centos7.4-LNMP快速部署wordpress


Centos7.4-LNMP快速部署wordpress

手动配置wp-config.php到站点目录下

[[email protected] ~]# cat /usr/share/Nginx/html/wp-config.php

<?PHP
/**
 * wordpress基础配置文件。
 *
 * 这个文件被安装程序用于自动生成wp-config.php配置文件,
 * 您可以不使用网站,您需要手动复制这个文件,
 * 并重命名为“wp-config.php”,然后填入相关信息。
 *
 * 本文件包含以下配置选项:
 *
 * * MysqL设置
 * * 密钥
 * * 数据库表名前缀
 * * ABSPATH
 *
 * @link https://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php
 *
 * @package wordpress
 */

// ** MysqL 设置 - 具体信息来自您正在使用的主机 ** //
/** wordpress数据库的名称 */
define(‘DB_NAME‘,‘wordpress‘);

/** MysqL数据库用户名 */
define(‘DB_USER‘,‘wordpress‘);

/** MysqL数据库密码 */
define(‘DB_PASSWORD‘,‘123456‘);

/** MysqL主机 */
define(‘DB_HOST‘,‘localhost‘);

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

/** 数据库整理类型。如不确定请勿更改 */
define(‘DB_COLLATE‘,‘‘);

/**#@+
 * 身份认证密钥与盐。
 *
 * 修改为任意独一无二的字串!
 * 或者直接访问{@link https://api.wordpress.org/secret-key/1.1/salt/
 * wordpress.org密钥生成服务}
 * 任何修改都会导致所有cookies失效,所有用户将必须重新登录。
 *
 * @since 2.6.0
 */
define(‘AUTH_KEY‘,‘6&M#QhjgQ:=C8 `x`/6!E]tB*rAE}n|IL*Qb)]CXeZ^5EK4^I9MzZp532}HZ7;.R‘);
define(‘SECURE_AUTH_KEY‘,‘A3-|;Zc~}n|;NBcdh7EK|@4bOHA7.mRM>?B][email protected] [email protected]+}6MP‘);
define(‘LOGGED_IN_KEY‘,‘,H>[email protected](B$D-TP<y2:>f/FDY]ZE+C831L#xX:3P8+I3s6bX$)[email protected],‘);
define(‘NONCE_KEY‘,‘zosquH8gn>]w?=u}$%zi+f]O7=G/mUGo*FG?44XKG. 8Yie[3kkxL*{:x9Wi2Vg]‘);
define(‘AUTH_SALT‘,‘LHZlsq>*&Yf#ER/i)&5PaV:W/d_UHLgK.=;i-D^U<U6[[email protected]])i/gkL2cgrQS‘);
define(‘SECURE_AUTH_SALT‘,‘GDou;[email protected]>-W2Dc$T&%[email protected],?!5k0n/|+5k*}#{LiV]okbG:bz^x=sF‘);
define(‘LOGGED_IN_SALT‘,‘7K3iVa{Uz?ieOy2N^b%p3J9fU{&#YsIeSVt*XuCrU:c-`F(K^)G_teGEF-d4F~06‘);
define(‘NONCE_SALT‘,‘FL2oIenT)[3AiI,^ooUb~4GXwF t* _W.A:.dD6[lP,>w)e8]}Yr&$brtM/j2&_‘);

/**#@-*/

/**
 * wordpress数据表前缀。
 *
 * 如果您有在同一数据库内安装多个wordpress的需求,请为每个wordpress设置
 * 不同的数据表前缀。前缀名只能为数字、字母加下划线。
 */
$table_prefix  = ‘wp_‘;

/**
 * 开发者专用:wordpress调试模式。
 *
 * 将这个值改为true,wordpress将显示所有用于开发的提示。
 * 强烈建议插件开发者在开发环境中启用WP_DEBUG。
 *
 * 要获取其他能用于调试的信息,请访问Codex。
 *
 * @link https://codex.wordpress.org/Debugging_in_wordpress
 */
define(‘WP_DEBUG‘,false);

/**
 * zh_CN本地化设置:启用ICP备案号显示
 *
 * 可在设置→常规中修改。
 * 如需禁用,请移除或注释掉本行。
 */
define(‘WP_ZH_CN_ICP_NUM‘,true);

/* 好了!请不要再继续编辑。请保存本文件。使用愉快! */

/** wordpress目录的绝对路径。 */
if ( !defined(‘ABSPATH‘) )
define(‘ABSPATH‘,dirname(__FILE__) . ‘/‘);

/** 设置wordpress变量和包含文件。 */
require_once(ABSPATH . ‘wp-settings.PHP‘);

Centos7.4-LNMP快速部署wordpress

Centos7.4-LNMP快速部署wordpress


Centos7.4-LNMP快速部署wordpress


Centos7.4-LNMP快速部署wordpress


Centos7.4-LNMP快速部署wordpress

CentOS 6.4安装配置LNMP服务器搭建Wordpress

CentOS 6.4安装配置LNMP服务器搭建Wordpress

准备:
1.配置防火墙,开启80端口、3306端口

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT

-A INPUT -j REJECT –reject-with icmp-host-prohibited

-A FORWARD -j REJECT –reject-with icmp-host-prohibited

COMMIT

~

二、部署

安装

一.安装Nginx

yum remove httpd* PHP* #删除系统自带的软件包

yum install Nginx -y #安装Nginx

LNMP

chkconfig Nginx on #设置Nginx 开机启动

service Nginx start #启动Nginx

二.安装MysqL

1.安装MysqL

yum install MysqL MysqL-server -y #yum 安装MysqL 直到完成

LNMP

/etc/init.d/MysqLd start #启动MysqL

LNMP

chkconfig MysqLd on #设为开机启动

cp /usr/share/MysqL/my-medium.cnf /etc/my.cnf #拷贝配置文件(注意:如果 /etc目录下面默认有一个my.cnf 直接覆盖即可)

2.为root账户设置密码

MysqL_secure_installation

#回车,根据提示输入Y ,输入2次密码,回车,根据提示依次输入Y,最后出现Thabjs for using MysqL!

LNMP

LNMP

MysqL 密码设置完成,重新启动 MysqL:

/etc/init.d/MysqLd restart #重启

/etc/init.d/MysqLd stop #停止

/etc/init.d/MysqLd start #启动

三.安装PHP5

1.安装PHP5

yum install PHP PHP-fpm -y #安装PHP直至完成

LNMP

2.安装PHP组件,是PHP5支持MysqL

yum install PHP-MysqL PHP-gd libjpeg* PHP-imap PHP-ldap PHP-odbc PHP-pear PHP-xml PHP-xmlrpc PHP-mbstring PHP-mcrypt PHP-bcmath PHP-mhash libmcrypt

#这里选择以上安装包进行安装,根据提示输入Y回车

LNMP

chkconfig PHP-fpm on #设置PHP-fpm 开机启动

/etc/init.d/PHP-fpm start #启动PHP-fpm

配置篇:

一.配置Nginx 支持PHP

cp /etc/Nginx/Nginx.conf /etc/Nginx/Nginx.confbak #备份原有的配置文件

vim /etc/Nginx/Nginx.conf #编辑配置文件

user Nginx Nginx; #修改Nginx 运行账号为;Nginx组的Nginx用户

:wq #保存退出

cp /etc/Nginx/conf.d/default.conf /etc/Nginx/conf.d/default.confbak #备份原有的配置文件

vim /etc/Nginx/conf.d/default.conf #编辑配置文件

index index.PHP index.html index.htm;#添加index.PHP 如图(大概在14行左右):

LNMP

#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.PHP$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.PHP;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

LNMP

#取消FastCGI server 部分location 的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name 或者使用绝对路径

service Nginx restart #重启Nginx

本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2014-08/105128p3.htm

二.PHP 配置

vim /etc/PHP.ini #编辑

date.timezone = PRC #在878行左右 把前面的分号去掉,改为date.timezone = PRC

LNMP

expose_PHP = off #在375行左右禁止显示PHP版本信息

LNMP

short_open_tag = ON #在211行支持PHP短标签

LNMP

:wq #保存退出

三.配置PHP-fpm

cp /etc/PHP-fpm.d/www.conf /etc/PHP-fpm.d/www.confbak #备份原有配置文件

vim /etc/PHP-fpm.d/www.conf #编辑

user = Nginx # 修改用户为Nginx

group = Nginx #修改组为Nginx

:wq #保存退出

LNMP

测试篇

cd /usr/share/Nginx/html

vim index.PHP #添加一下代码

PHPinfo();

?>

:wq #保存退出

chown Nginx.Nginx /usr/share/Nginx/html -R #设置权限

service Nginx restart #重启Nginx

service PHP-fpm restart #重启PHP-fpm

LNMP

在客户端浏览器中输入服务器ip地址,可以看到相关的配置信息

说明lnmp配置成功

到此,CentOS6.4 安装配置LNMP(Nginx+PHP+MysqL)完成,

1.下载 WordPress网站代码

http://cn.wordpress.org/ 在官方网站上下载中文的WordPress网站源码

并解压

2.删除 /usr/share/Nginx/html 下面的文件,并将刚刚解压的wordpress 源码复制到此目录下 (注意:是复制wordpress里面的文件全部复制进去,不是复制wordpress这个文件夹)

LNMP

3.创建wordpress数据库

MysqL -u root -p #以root用户登录 MysqL 输入密码

LNMP

MysqL> create database zrq; #创建名为zrq的数据库

LNMP

MysqL> use zrq; #按回车键出现Database changed 时说明操作成功!)

4.安装wordpress

在客户端打开浏览器输入服务器的ip地址:

LNMP

点击创建配置文件:

LNMP

点击“现在就开始”

LNMP

在提交之前,修改/usr/share/Nginx/html 的权限

chmod 777 -R /usr/share/Nginx/html

修改完之后点击提交:

LNMP

点击进行安装,并输入相关的网站信息:

LNMP

点击安装 wordpress ,出现一下画面说明博客搭建成功。

LNMP

LNMP

登录之后的界面

恭喜你网站搭建成功!

CentOS 6.5安装WordPress(基于LNMP)

CentOS 6.5安装WordPress(基于LNMP)

一、LNMP环境版本说明:

OS:最小化安装CentOS 6.5

NginxNginx-1.10.2.tar.gz

MysqLmysql-5.6.24.tar.gz

PHPPHP-5.6.23.tar.bz2

 

二、搭建LNMP环境(基于最小化安装CentOS 6.5

此处省略,详情参考http://blog.51cto.com/itops/2130205

 

三、安装及配置wordpress

1.下载wordpress

wget http://wordpress.org/latest.tar.gz

tar -xzvf latest.tar.gz -C /usr/local


2.为wordpress在MysqL中创建一个DB及相关用户

#登录MysqL

mysql -u root -p

#创建数据库

CREATEDATABASEwordpress;  #数据库名为wordpress

#创建一个用户

USER wpuser@localhost; #用户名为wpuser

#设置密码

SETPASSWORDFOR@localhost=PASSWORD("wppassword"); #密码为wppassword

#分配用户到DB权限

GRANTALLPRIVILEGES ON wordpress.* TO wpuser@localhost IDENTIFIED BY 'password';

#更新权限

FLUSH PRIVILEGES;

3.配置wordpress

cp /usr/local/wordpress/wp-config-sample.PHP /wordpress/wp-config.php

vi  

/** wordpress数据库的名称 */

define('DB_NAME','wordpress');

/** MysqL数据库用户名 */

define('DB_USER','wpuser');

/** MysqL数据库密码 */

define('DB_PASSWORD','wppassword 

4.配置Nginx访问wordpress

vi /etc/Nginx/Nginx.conf

#
 The default server
server {    listen       80;    server_name  localhost;    #charset koi8-r;    #access_log  logs/host.access.log  main;    location / {        root   /usr/local/wordpress; #wordpress所在目录        index index.PHP  index.html index.htm;    }    error_page  404              /404.html;    location = /404.html {        root   /usr/local/Nginx/html;    # redirect server error pages to the static page /50x.html    #    error_page   500 502 503 504  /50x.html;    location = /50x.html {    # proxy the PHP scripts to Apache listening on 127.0.0.1:80    #location ~ \.PHP$ {    #    proxy_pass   http://127.0.0.1;    #}    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000    location ~ \.PHP$ {        root           /usr/local/wordpress; #wordpress所在目录        fastcgi_pass   127.0.0.1:9000;        fastcgi_index  index.PHP;        fastcgi_param  SCRIPT_FILENAME  /usr/local/wordpress$fastcgi_script_name;        include        fastcgi_params;    # deny access to .htaccess files,if Apache's document root    # concurs with Nginx's one    #location ~ /\.ht {    #    deny  all;}


5.重启Nginx

service Nginx reload


6.然后访问http://ip/,就可以进入wordpress的安装引导界面了。

centos 6.9 快速部署lnmp网站

centos 6.9 快速部署lnmp网站

安装软件

yum install -y PHP PHP-MysqL PHP-fpm Nginx MysqL MysqL-server

MysqL配置

/etc/my.cnf

[client]
port=3306
[MysqL]
default-character-set=utf8

[MysqLd]
skip-name-resolve
port=3306
character-set-server=utf8
default-storage-engine=MyISAM
#支持 INNODB 引擎模式。修改为 default-storage-engine=INNODB 即可。
#如果 INNODB 模式如果不能启动,删除data目录下ib开头的日志文件重新启动。

sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
max_connections=512

query_cache_size=0
table_cache=256
tmp_table_size=18M

thread_cache_size=8
myisam_max_sort_file_size=64G
myisam_sort_buffer_size=35M
key_buffer_size=25M
read_buffer_size=64K
read_rnd_buffer_size=256K
sort_buffer_size=256K

innodb_additional_mem_pool_size=2M

innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=1M

innodb_buffer_pool_size=47M
innodb_log_file_size=24M
innodb_thread_concurrency=8
  • 建立账号
grant all privileges on *.* to root@'%' identified by 'xxx';

grant all privileges on *.* to root@'localhost' identified by 'xxx';

flush privileges;

Nginx配置

server {
    listen               80 default;
    server_name          www.xxx.com;

    client_max_body_size 4M;
    client_body_buffer_size 128k;

    root /opt/www/www.xxx.com;
    index index.PHP;

    location ~ \.PHP$ {
        #try_files $uri $uri/ /index.PHP;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param REDIRECT_STATUS 200;
       # fastcgi_pass unix:/var/run/PHP5-fpm.sock;
        fastcgi_pass 127.0.0.1:9000;
    }
}

PHP-fpm配置

nothing configure

启动

/etc/init.d/PHP-fpm restart
/etc/init.d/MysqLd restart
/etc/init.d/Nginx restart
chkconfig PHP-fpm on
chkconfig MysqLd on
chkconfig Nginx on

CentOS 7 yum安装LAMP,LNMP并搭建WordPress个人博客网站

CentOS 7 yum安装LAMP,LNMP并搭建WordPress个人博客网站

本次实验要进行的是在CentOS7.2,内核版本3.10.0-327.el7.x86_64的环境下搭建LAMP和LNMP,并在此之上做一个wordpress博客网站。

[root@Shining ~]# uname -a
Linux Shining.ACG 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@Shining ~]# cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)

首先介绍一下LAMP和LNMP

LAMP

    LMAP即Linux+Apache+MysqL/MariaDB+Perl/PHP/Python的首字母缩写。这是一组常用来搭建动态网站或者服务器的开源软件。它们本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足鼎立之势,并且该软件开发的项目在软件方面的投资成本较低,因此受到整个IT界的关注。从网站的流量上来说,70%以上的访问流量是LAMP来提供的,LAMP是最强大的网站解决方案。

Linux

    Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户、多任务、支持多线程和多cpu的操作系统。它能运行主要的UNIX工具软件、应用程序和网络协议。它支持32位和64位硬件。Linux继承了Unix以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统。

    本次使用的CentOS为Linux的一个发行版。

Apache  

    Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩展,将Perl/Python等解释器编译到服务器中。

    Apache的主程序名叫httpd,这也是我们实验的时候需要安装的程序之一。

MysqL

    MysqL是一个关系型数据库管理系统,由瑞典MysqL AB 公司开发,目前属于 Oracle 旗下产品。MysqL 最流行的关系型数据库管理系统,在 WEB 应用方面MysqL是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件之一。MysqL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。MysqL所使用的 sql 语言是用于访问数据库的最常用标准化语言。MysqL 软件采用了双授权政策,它分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择 MysqL 作为网站数据库。由于其社区版的性能卓越,搭配 PHP 和 Apache 可组成良好的开发环境。

    本次实验使用的数据库软件为MysqL的一个分支软件,叫做MariaDB。

MariaDB数据库管理系统是MysqL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MysqL,包括API和命令行,使之能轻松成为MysqL的代替品。在存储引擎方面,使用XTradB(英语:XTradB)来代替MysqL的InnoDB。

PHP  

    PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,利于学习,使用广泛,主要适用于Web开发领域。PHP 独特的语法混合了C、Java、Perl以及PHP自创的语法。它可以比CGI或者Perl更快速地执行动态网页。用PHP做出的动态页面与其他的编程语言相比,PHP是将程序嵌入到HTML(标准通用标记语言下的一个应用)文档中去执行,执行效率比完全生成HTML标记的CGI要高许多;PHP还可以执行编译后代码,编译可以达到加密和优化代码运行,使代码运行更快。

LNMP

    LNMP和LAMP的区别就在于使用Nginx而不是Apache。

    Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上Nginx的并发能力确实在同类型的网页服务器中表现较好。

Nginx和Apache的优缺点对比

Nginx 相对 apache 的优点:

    轻量级,同样起web 服务,比apache 占用更少的内存及资源。

    抗并发,Nginx 处理请求是异步非阻塞的,而apache 则是阻塞型的,在高并发下Nginx 能保持低资源低消耗高性能。

    高度模块化的设计,编写模块相对简单。

    社区活跃,各种高性能模块出品迅速啊。

apache 相对Nginx 的优点:

    rewrite ,比Nginx 的rewrite 强大。

    模块超多,基本想到的都可以找到。

    少bug ,Nginx 的bug 相对较多。

    超稳定。

wordpress

    wordpress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MysqL数据库的服务器上架设属于自己的网站。也可以把 wordpress当作一个内容管理系统(CMS)来使用。wordpress是一款个人博客系统,并逐步演化成一款内容管理系统软件,它是使用PHP语言和MysqL数据库开发的。用户可以在支持 PHP 和 MysqL数据库的服务器上使用自己的博客。wordpress有许多第三方开发的免费模板,安装方式简单易用。不过要做一个自己的模板,则需要你有一定的专业知识。比如你至少要懂的标准通用标记语言下的一个应用HTML代码、CSS、PHP等相关知识。wordpress官方支持中文版,同时有爱好者开发的第三方中文语言包,如wopus中文语言包。wordpress拥有成千上万个各式插件和不计其数的主题模板样式。 

下面正式进入实验阶段

Linux,即CentOS的安装在这里不再赘述。

Apache安装

    Apache的软件包名字为httpd,使用yum安装httpd:

[root@Shining ~]# yum install httpd

    httpd安装好之后需要将其启动,启动之前,我们来看一下网络情况:

[root@Shining ~]# ss -tl
State      Recv-Q Send-Q Local Address:Port                 Peer Address:Port                
LISTEN     0      5      192.168.122.1:domain                   *:*                    
LISTEN     0      128        *:ssh                      *:*                    
LISTEN     0      128    127.0.0.1:ipp                      *:*                    
LISTEN     0      100    127.0.0.1:smtp                     *:*                    
LISTEN     0      32        :::ftp                     :::*                    
LISTEN     0      128       :::ssh                     :::*                    
LISTEN     0      128      ::1:ipp                     :::*                    
LISTEN     0      100      ::1:smtp                    :::* 
[root@Shining ~]# ss -tnl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      5      192.168.122.1:53                       *:*                  
LISTEN     0      128          *:22                       *:*                  
LISTEN     0      128    127.0.0.1:631                      *:*                  
LISTEN     0      100    127.0.0.1:25                       *:*                  
LISTEN     0      32          :::21                      :::*                  
LISTEN     0      128         :::22                      :::*                  
LISTEN     0      128        ::1:631                     :::*                  
LISTEN     0      100        ::1:25                      :::*

    可以看到http服务的80端口是没有处于监听状态的。

    接下来,我们启动httpd服务:

[root@Shining ~]# systemctl start httpd

此时,在浏览器中输入localhost会出现Apache的欢迎页面(此处使用CentOS 6.8演示,Cent OS 7效果相同):

捕获.PNG

MysqL

    CentOS 7默认安装了MariaDB,如果机子上没有安装数据库软件的话,可以使用下面的方式安装:

[root@Shining ~]# yum install MysqL

安装完之后开启MysqL服务:

[root@Shining ~]# systemctl start mariadb
[root@Shining ~]# ss -tl
State      Recv-Q Send-Q Local Address:Port                 Peer Address:Port                
LISTEN     0      50         *:MysqL                    *:*                    
LISTEN     0      5      192.168.122.1:domain                   *:*                    
LISTEN     0      128        *:ssh                      *:*                    
LISTEN     0      128    127.0.0.1:ipp                      *:*                    
LISTEN     0      100    127.0.0.1:smtp                     *:*                    
LISTEN     0      128       :::http                    :::*                    
LISTEN     0      32        :::ftp                     :::*                    
LISTEN     0      128       :::ssh                     :::*                    
LISTEN     0      128      ::1:ipp                     :::*                    
LISTEN     0      100      ::1:smtp                    :::*                    
[root@Shining ~]# ss -tnl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      50           *:3306                     *:*                  
LISTEN     0      5      192.168.122.1:53                       *:*                  
LISTEN     0      128          *:22                       *:*                  
LISTEN     0      128    127.0.0.1:631                      *:*                  
LISTEN     0      100    127.0.0.1:25                       *:*                  
LISTEN     0      128         :::80                      :::*                  
LISTEN     0      32          :::21                      :::*                  
LISTEN     0      128         :::22                      :::*                  
LISTEN     0      128        ::1:631                     :::*                  
LISTEN     0      100        ::1:25                      :::*

可以看到,MysqL服务已经开启,监听3306端口。

进入MariaDB

[root@Shining ~]# MysqL
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.44-MariaDB MariaDB Server

copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

显示数据库

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db_name            |
| MysqL              |
| performance_schema |
| test               |
| testdb             |
+--------------------+
6 rows in set (0.00 sec)

MariaDB [(none)]>

创建数据库:

MariaDB [(none)]> create database db_name;

切换数据库:

MariaDB [(none)]> use db_name
Database changed
MariaDB [db_name]>

创建用户:格式为create user '用户名'@'允许用户使用哪个主机登陆' identified by '密码'

    %意思是不限制登陆主机。

MariaDB [db_name]> create user 'username'@'%' identified by '123456';

为用户赋予权限:

MariaDB [db_name]> grant all privileges to 'username'@'%';

显示用户权限:

MariaDB [(none)]> show grants for 'username'@'%';
+---------------------------------------------------------------------------------------------------------+
| Grants for username@%                                                                                   |
+---------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'username'@'%' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |
| GRANT ALL PRIVILEGES ON `db_name`.`db_name` TO 'username'@'%'                                           |
+---------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

退出数据库:

MariaDB [db_name]> exit
Bye

数据库的准备工作完成。

接下来进行PHP的安装:

[root@Shining ~]# yum install PHP PHP-MysqL

安装完成之后来到httpd服务的主目录

[root@Shining ~]# cd /var/www/html/

编辑文件PHPinfo.PHP

[root@localhost html]# vim PHPinfo.PHP

内容为:

<?PHP
echo PHPinfo();

保存并退出。然后,打开浏览器,输入主机ip/PHPinfo.PHP就可以看到PHP的信息:

捕获2.PNG

接下来,下载wordpress:

网址为https://cn.wordpress.org/wordpress-4.5.3-zh_CN.tar.gz

[root@localhost html]# wget https://cn.wordpress.org/wordpress-4.5.3-zh_CN.tar.gz

解压,

[root@localhost html]# tar xvf wordpress-4.5.3-zh_CN.tar.gz

得到wordpress文件夹,将文件夹里的内容复制到/var/www/html下,其中有一个wp-config-sample.PHP,该文件为wordpress的配置文件。复制为wp-config.php即可生效。

编辑wp-config.php :

// ** MysqL 设置 - 具体信息来自您正在使用的主机 ** //
/** wordpress数据库的名称 */
define('DB_NAME', 'database_name_here');

/** MysqL数据库用户名 */
define('DB_USER', 'username_here');

/** MysqL数据库密码 */
define('DB_PASSWORD', 'password_here');

/** MysqL主机 */
define('DB_HOST', 'localhost');

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

/** 数据库整理类型。如不确定请勿更改 */
define('DB_COLLATE', '');

将文件里的database_name_here,username_here,password_here,localhost,分别改成数据库名称,数据库用户名,数据库密码,数据库主机。保存退出便会生效。

接下来,在浏览器中输入wordpress主机地址,即可访问wordpress:

捕获3.PNG

这是提示用户输入数据库信息的页面,如果用户没有配置过wp-config.php文件,便会出现此页面。

捕获4.PNG

在这里输入数据库信息,提交;

blob.png

欢迎页面,输入标题,用户名,密码等信息。点击安装wordpress。

blob.png

blob.png

接下来进行Nginx的安装与配置。

首先,PHP需要安装一个PHP-fpm软件:

[root@localhost wordpress]# yum install PHP-fpm

启动PHP-fpm:

[root@localhost wordpress]# service PHP-fpm start

安装Nginx:

[root@localhost yum.repos.d]# yum install Nginx

配置Nginx配置文件/etc/Nginx/Nginx.conf

[root@Shining /var/www/html]# vim /etc/Nginx/Nginx.conf

添加或修改以下内容:

server {
        listen       80; 
        server_name  172.16.253.159;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / { 
            root   /var/www/html;
            index  index.html index.htm index.PHP;
        }   
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.PHP$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.PHP$ {
            root           /var/www/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.PHP;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
     }

重启Nginx,重启PHP-fpm

[root@localhost yum.repos.d]# service Nginx restart
Stopping Nginx:                                            [Failed]
Starting Nginx:                                            [  OK  ]
[root@localhost yum.repos.d]# service PHP-fpm restart
Stopping PHP-fpm:                                          [  OK  ]
Starting PHP-fpm:                                          [  OK  ]

注意,在启动Nginx之前要关闭httpd服务,因为两者都使用80端口,会造成冲突。

访问网站:

blob.png

注意,如果未启动PHP-fpm服务,则会出现以下错误:

blob.png

总结:

本次实验采用yum安装,所有技术水平较低。实验过程中多次出现问题,好在都解决了。

下面是出现的一些问题。

1、yum源问题。CentOS自带的yum里没有Nginx,自己添加了repo文件。但是执行了一次yum clean all,yum makecache。问题便出现了,原因是有一个源指向cdrom,但是找不到,我挂载cdrom,仍然出问题。然后检查了autofs服务,正常。后来才发现是镜像文件坏掉了……

2、Apache和Nginx区别。开始实验时,我在Apache和Nginx之间摇摆,也不知道这两个的区别,于是就都试了一遍。Apache很简单,安装好启动服务就可以用了。但是Nginx还需要配置,我在这里卡住好久。因为是yum安装,所有配置文件的路径跟网上的教程讲的有所不同,又花了很长时间找配置文件。然后又花了很长时间去配置。最后由于没有启动PHP-fpm,导致出错。结果有花了好长时间才找到这个让人抓狂的错误原因。

3、MysqL的问题。一开始忘了命令。又回去看视频学习。结果第一次添加用户没有添加成功。导致wordpress一直报错。第二次,wordpress由报错,重启后不再报错。原因现在仍然不知道。

4、编写博客时电脑出了问题,重启之后丢了一半的内容(哭瞎了)。以后一定边写边保存!

原创文章,作者:wangshuai,如若转载,请注明出处:http://www.178linux.com/60558

今天关于Centos7.4-LNMP快速部署wordpresscentos7搭建wordpress的讲解已经结束,谢谢您的阅读,如果想了解更多关于CentOS 6.4安装配置LNMP服务器搭建Wordpress、CentOS 6.5安装WordPress(基于LNMP)、centos 6.9 快速部署lnmp网站、CentOS 7 yum安装LAMP,LNMP并搭建WordPress个人博客网站的相关知识,请在本站搜索。

本文标签: