采用企业级LNMP环境实现Wordpress中文站点

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了采用企业级LNMP环境实现Wordpress中文站点相关的知识,希望对你有一定的参考价值。

操作系统:CentOS release 6.8 (Final)

Web服务器软件:nginx-1.6.3.tar.gz

数据库系统:mysql 5.5.52

php版本:php 5.3.3

站点程序:wordpress-4.7.4-zh_CN.tar.gz
任务:分别采用单台服务器和双台服务器实现LNMP架构。

附件:提供所有配置源码下载。

检查安装Nginx所需要的lib

[[email protected]~]#rpm -qa pcre pcre-devel 

[[email protected]~]# yum install pcre pcre-devel  –y

[[email protected]~]# yum install openssl openssl-devel  –y

 开始安装Nginx

[[email protected]]# wget http://nginx.org/download/nginx-1.6.3.tar.gz

[[email protected]]# ls  -l nginx-1.6.3.tar.gz

[[email protected]]# useradd  nginx -s /sbin/nologin –M

[[email protected]]# tar xf  nginx-1.6.3.tar.gz

[[email protected]]# cd nginx-1.6.3

[[email protected]x-1.6.3]#./configure\

--user=nginx\

--group=nignx\

--prefix=/application/nginx\

--with-http_stub_status_module\

--with-http_ssl_module

[[email protected]]#make

[[email protected]]#make install

 启动并检查安装结果:

启动前检查配置文件语法:

[[email protected]]# /application/nginx/sbin/nginx -t

nginx: theconfiguration file /application/nginx/conf/nginx.conf syntax is ok

nginx:[emerg] getgrnam("nignx") failed

nginx:configuration file /application/nginx/conf/nginx.conf test failed

[[email protected]]# cat error.log

2017/07/1216:15:07 [emerg] 17992#0: getgrnam("nignx") failed

[[email protected]]# vi nginx.conf

#user  nobody;  #去掉最前面的#号即解决启动错误的问题

nginx: option"-s" requires parameter

[[email protected]]# /application/nginx/sbin/nginx –t   #检查语法

nginx: theconfiguration file /application/nginx/conf/nginx.conf syntax is ok

nginx:configuration file /application/nginx/conf/nginx.conf test is successful

 

[[email protected]]# /application/nginx/sbin/nginx   #启动Nginx服务

nginx:[emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)  #存在端口冲突

 

#原因是Apache与Nginx默认都是80端口

[[email protected]]# lsof  -i:80    #Nginx服务对应的端口存在冲突

COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

httpd   1451  root    4u  IPv6 10731      0t0  TCP *:http (LISTEN)

httpd   1496 apache    4u IPv6  10731      0t0 TCP *:http (LISTEN)

httpd   1497 apache    4u IPv6  10731      0t0 TCP *:http (LISTEN)

httpd   1498 apache    4u IPv6  10731      0t0 TCP *:http (LISTEN)

httpd   1499 apache    4u IPv6  10731      0t0 TCP *:http (LISTEN)

httpd   1500 apache    4u IPv6  10731      0t0 TCP *:http (LISTEN)

httpd   1501 apache    4u IPv6  10731      0t0 TCP *:http (LISTEN)

httpd   1502 apache    4u IPv6  10731      0t0 TCP *:http (LISTEN)

httpd   1503 apache    4u IPv6  10731      0t0 TCP *:http (LISTEN)

 #修改nginx默认端口,改为8080端口

server {

        listen       8080;

        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root   html;

            index  index.html index.htm;

        }

[[email protected]acticonf]# pkill nginx   #杀掉进程,以便重启Nginx服务

[[email protected]]# /application/nginx/sbin/nginx

 

[[email protected]]# lsof -i:8080     #Nginx服务对应的端口成功启动  

COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

nginx  17530   root   6u  IPv4 3271777      0t0 TCP *:webcache (LISTEN)

nginx  17531nobody    6u  IPv4 3271777      0t0 TCP *:webcache (LISTEN)

 

[[email protected]]# netstat -lnt|grep 80

tcp    0   0 0.0.0.0:8080      0.0.0.0:* LISTEN

tcp   0      0 :::36780           :::*    LISTEN     

tcp        0     0 :::80         :::*    LISTEN 


[[email protected]]# ps -ef|grep nginx

root      3000 15790  0 16:22 pts/0    00:00:00 /application/nginx/sbin/nginx

root      6336 15790  0 16:36 pts/0    00:00:00 grep nginx

root     17530    1  0 16:28 ?        00:00:00 nginx: master process/application/nginx/sbin/nginx

nobody   17531 17530 0 16:28 ?        00:00:00 nginx:worker process       

root     31232 15790  0 16:20 pts/0    00:00:00 /application/nginx/sbin/nginx

检查Nginx启动实际效果:

[[email protected]]# wget 127.0.0.1:8080    #查看本地的index.html文件

[[email protected]]# curl  127.0.0.1:8080    #直接在屏幕上输出效果

<!DOCTYPEhtml>

<html>

<head>

<title>Welcometo nginx!</title>

<style>

    body {

        width: 35em;

        margin: 0 auto;

        font-family: Tahoma, Verdana, Arial,sans-serif;

    }

</style>

</head>

<body>

<h1>Welcometo nginx!</h1>

<p>Ifyou see this page, the nginx web server is successfully installed and

working.Further configuration is required.</p>

<p>Foronline documentation and support please refer to

<ahref="http://nginx.org/">nginx.org</a>.<br/>

Commercialsupport is available at

<ahref="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thankyou for using nginx.</em></p>

</body>

</html>

[[email protected]]# ../sbin/nginx -V

nginxversion: nginx/1.6.3

built by gcc4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)

 

检查安装php所需要的lib 

#yum instal zlib-devel libxml2-devel libjped-devel libjpeg-turbo-devel libiconv-devel -y

# yum instal lfreetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel –y

# yum install libmcrypt-devel

# yum install mhash

# yum install mcrypt -y

[[email protected]]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

[[email protected]]# tar zxf libiconv-1.14.tar.gz

[[email protected]]# ./configure  --prefix=/usr/local/libiconv

[[email protected]]# make && make install

 

开始安装php

[[email protected]~]# mkdir /home/tools –p

[[email protected]]# wget http://mirrors.sohu.com/php/php-5.3.27.tar.gz

[[email protected] tools]# tar zxf php-5.3.27.tar.gz

[[email protected]]# cd php-5.3.27

[[email protected]]# ./configure  \

--prefix=/application/php5.3.27 \

--with-mysql=/application/mysql  \

--with-iconv-dir=/usr/local/libiconv \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-libxml-dir=/usr \

--enable-xml \

--disable-rpath \

--enable-fpm \

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--with-curl \

--with-curlwrappers \

--enable-mbregex \

--with-mcrypt \

--with-gd \

--enable-gd-native-ttf \

--with-openssl \

--with-mhash \

--enable-pcntl \

--enable-sockets \

--with-xmlrpc \

--enable-zip \

--enable-soap \

--enable-short-tags \

--enable-zend-multibyte \

--enable-static \

--with-xsl \

--enable-safe-mode \

--enable-ftp

……

checking forCygwin environment... no

checking formingw32 environment... no

checking foregrep... grep -E

checking fora sed that does not truncate output... /bin/sed

checking hostsystem type... config.sub: missing argument

Try`config.sub --help‘ for more information.

 checkingtarget system type... config.sub: missing argument

Try`config.sub --help‘ for more information.

 checking forgcc... no

checking forcc... no

configure:error: no acceptable cc found in $PATH

解决上述问题:

# yum install -y gcc-c++

[[email protected]]#./configure  \    #重新编译

--prefix=/application/php5.3.27 \

--with-mysql=/application/mysql  \

--with-iconv-dir=/usr/local/libiconv \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-libxml-dir=/usr \

--enable-xml \

--disable-rpath \

--enable-fpm \

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--with-curl \

--with-curlwrappers \

--enable-mbregex \

--with-mcryp t\

--with-gd \

--enable-gd-native-ttf \

--with-openssl \

--with-mhash \

--enable-pcntl \

--enable-sockets \

--with-xmlrpc \

--enable-zip \

--enable-soap \

--enable-short-tags \

--enable-zend-multibyte \

--enable-static \

--with-xsl  \

--enable-safe-mode \

--enable-ftp

 

#重新配置后的问题:

configure:error: Cannot find MySQL header files under /application/mysql.

Note that theMySQL client library is not bundled anymore!

#不管怎么变更该数据库的路径,还是编译通还过

解决办法就是:

#mkdir /usr/lib/msyql –p   

#cp  /usr/lib64/mysql/*  /usr/lib/mysql/

然后进行./configure即可,如果服务器没有/usr/lib/mysql/ 目录,则在/usr/lib/目录下创建mysql目录即可

+--------------------------------------------------------------------+

|License:                                                          |

| Thissoftware is subject to the PHP License, available in this     |

|distribution in the file LICENSE.  Bycontinuing this installation |

| process,you are bound by the terms of this license agreement.     |

| If you donot agree with the terms of this license, you must abort |

| theinstallation process at this point.                            |

+--------------------------------------------------------------------+

Thank you forusing PHP.

[[email protected]]#make    #编译

[[email protected]]#make install   #安装

/home/tools/php-5.3.27/build/shtoolinstall -c ext/phar/phar.phar /application/php5.3.27/bin

ln -s -f/application/php5.3.27/bin/phar.phar /application/php5.3.27/bin/phar

InstallingPDO headers:  /application/php5.3.27/include/php/ext/pdo/

[[email protected]]# ln  -s/application/php5.3.27/  /application/php  #设置软链接

[[email protected]]# ls  -l /application/php

lrwxrwxrwx 1root root 23 Jul 12 17:14 /application/php -> /application/php5.3.27/

 

[[email protected]]# cp php.ini-production  /application/php/lib/php.ini  #拷贝php的配置文件到PHP默认目录

在linux上编译安装PHP时,为什么php/etc/目录下没有找到php-fpm.conf.default这个文件?

解答:原因在拷贝配置文件执行时,有部分代码没有执行。

注意:当执行一大块代码结束后并没有报错,但没有执行的配置语句会重新显示出来。

[[email protected]]# cd  /application/php/etc/     #配置文件php-fpm.confs

[[email protected]]# ll

total 28

-rw-r--r-- 1root root  1232 Jul 12 17:41 pear.conf

-rw-r--r-- 1root root 21683 Jul 12 17:41 php-fpm.conf.default

[[email protected]]# cp php-fpm.conf.default php-fpm.conf

启动PHP服务php-fpm:

[[email protected]]# /application/php/sbin/php-fpm

检查php服务php-fpm的进程及启动端口的情况:

[[email protected]]# ps -ef|grep php-fpm

root     23321    1  0 17:43 ?        00:00:00 php-fpm: master process(/application/php5.3.27/etc/php-fpm.conf)

nginx    23322 23321 0 17:43 ?        00:00:00 php-fpm:pool www           

nginx    23323 23321 0 17:43 ?        00:00:00 php-fpm:pool www            

root     23325 15790  0 17:43 pts/0    00:00:00 grep php-fpm

[[email protected]]# lsof -i :9000  

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

php-fpm23321  root    7u IPv4 3871264      0t0  TCP localhost:cslistener (LISTEN)

php-fpm 23322nginx    0u  IPv4 3871264      0t0 TCP localhost:cslistener (LISTEN)

php-fpm 23323nginx    0u  IPv4 3871264      0t0 TCP localhost:cslistener (LISTEN)

 

配置Nginx支持PHP程序请求访问

#vi nginx.conf   #修改配置文件

location~.*\.(php|php5)?$ {

               root html;

              fastcgi_pass 127.0.0.1:9000;

              fastcgi_index index.php;

              include fastcgi.conf;

          }

#检查并启动Nginx

[[email protected]]# ../sbin/nginx -t

nginx: theconfiguration file /application/nginx/conf/nginx.conf syntax is ok

nginx:configuration file /application/nginx/conf/nginx.conf test is successful

[[email protected]]# ../sbin/nginx -s reload

测试LNMP环境生效的情况:

[[email protected]]# echo "<?php phpinfo(); ?>" >test_info.php

[[email protected]]# cat test_info.php

<?phpphpinfo(); ?>


PHP连接MySQL的情况进行测试:

[[email protected]]# vi test_mysql.php

<?php

$link_id=mysql_connect(‘localhost‘,‘root‘,‘*****‘)or mysql_error();

if($link_id){

    echo "mysql successful byskyboy!";

}else{

    echo mysql_error();

  }

?>

 

下面部署一个wordpress程序服务:

1.先创建一个专用的数据库WordPress

[[email protected]]# mysql -uroot –p

mysql>create database wordpress;

Query OK, 1row affected (0.00 sec)

mysql>show databases like ‘wordpress‘;

+----------------------+

| Database(wordpress) |

+----------------------+

|wordpress            |

+----------------------+

1 row in set(0.00 sec)

 

Nginx及PHP环境配置准备:

         location / {

            root   html;

            index  index.php index.html index.htm;

        }

         location ~.*\.(php|php5)?$ {

              root  html;

              fastcgi_pass 127.0.0.1:9000;

              fastcgi_index index.php;

              include fastcgi.conf;

          }

[[email protected]]# wget  https://tw.wordpress.org/wordpress-4.8-zh_TW.tar.gz

[[email protected]]# tar xf wordpress-4.8-zh_TW.tar.gz

[[email protected]]# mkdir blog

[[email protected]]# mv wordpress blog/

[[email protected]]# chown  -R nginx.nginx blog

测试情况:浏览器显示Filenot found.

解答:原因是解析不到程序,建设直接放到html目录下,避免发生找不到程序的问题。

 [[email protected]]# cp wp-config-sample.php  wp-config.php

 [[email protected]]# vi  wp-config.php #配置数据库名、用户名和密码即可

 配置成功。

以上是通过一台服务器架构LNMP;

下面通过两台服务器架设LNMP,也很简单:

.8服务器: 做Nginx服务器,将wordpress放到nginx的html目录下,配wp-config.php文件。

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

define(‘DB_NAME‘, ‘wordpress‘);

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

define(‘DB_USER‘, ‘***‘);

/** MySQL数据库密码 */

define(‘DB_PASSWORD‘, ‘*****‘);

/** MySQL主机 */

define(‘DB_HOST‘, ‘.9服务器IP‘);

.9服务器:做Mysql服务器,创建wordpress数据库。

测试运行结果:http://117.40.239.8:8080/wordpress

本文出自 “sky9890” 博客,请务必保留此出处http://sky9896.blog.51cto.com/2330653/1946894

以上是关于采用企业级LNMP环境实现Wordpress中文站点的主要内容,如果未能解决你的问题,请参考以下文章

lnmp环境下搭建wordpress博客程序

企业级LNMP实例搭建

lnmp下实现部署wordpress和phpmyadmin,并实现https和URL重定向

lnmp下实现部署wordpress和phpmyadmin,并实现https和URL重定向

CentOS7——搭建LNMP环境(WordPress案例)

搭建 LNMP+WordPress 环境