溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

采用企業(yè)級LNMP環(huán)境實(shí)現(xiàn)Wordpress中文站點(diǎn)

發(fā)布時(shí)間:2020-07-09 00:06:57 來源:網(wǎng)絡(luò) 閱讀:919 作者:sky9890 欄目:建站服務(wù)器

操作系統(tǒng):CentOS release 6.8 (Final)

Web服務(wù)器軟件:Nginx-1.6.3.tar.gz

數(shù)據(jù)庫系統(tǒng):MySQL 5.5.52

PHP版本:php 5.3.3

站點(diǎn)程序:wordpress-4.7.4-zh_CN.tar.gz
任務(wù):分別采用單臺服務(wù)器和雙臺服務(wù)器實(shí)現(xiàn)LNMP架構(gòu)。

附件:提供所有配置×××。

檢查安裝Nginx所需要的lib

[root@Cacti~]#rpm -qa pcre pcre-devel 

[root@Cacti~]# yum install pcre pcre-devel  –y

[root@Cacti~]# yum install openssl openssl-devel  –y

 開始安裝Nginx

[root@Cactitools]# wget http://nginx.org/download/nginx-1.6.3.tar.gz

[root@Cactitools]# ls  -l nginx-1.6.3.tar.gz

[root@Cactitools]# useradd  nginx -s /sbin/nologin –M

[root@Cactitools]# tar xf  nginx-1.6.3.tar.gz

[root@Cactitools]# cd nginx-1.6.3

[root@Cactinginx-1.6.3]#./configure\

--user=nginx\

--group=nignx\

--prefix=/application/nginx\

--with-http_stub_status_module\

--with-http_ssl_module

[root@Cactinginx-1.6.3]#make

[root@Cactinginx-1.6.3]#make install

 啟動并檢查安裝結(jié)果:

啟動前檢查配置文件語法:

[root@Cactinginx-1.6.3]# /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

[root@Cactilogs]# cat error.log

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

[root@Cacticonf]# vi nginx.conf

#user  nobody;  #去掉最前面的#號即解決啟動錯(cuò)誤的問題

nginx: option"-s" requires parameter

[root@Cacticonf]# /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

 

[root@Cacticonf]# /application/nginx/sbin/nginx   #啟動Nginx服務(wù)

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

 

#原因是Apache與Nginx默認(rèn)都是80端口

[root@Cacticonf]# lsof  -i:80    #Nginx服務(wù)對應(yīng)的端口存在沖突

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默認(rèn)端口,改為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;

        }

[root@Cacticonf]# pkill nginx   #殺掉進(jìn)程,以便重啟Nginx服務(wù)

[root@Cacticonf]# /application/nginx/sbin/nginx

 

[root@Cacticonf]# lsof -i:8080     #Nginx服務(wù)對應(yīng)的端口成功啟動  

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)

 

[root@Cacticonf]# 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 


[root@Cacticonf]# 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啟動實(shí)際效果:

[root@Cacticonf]# wget 127.0.0.1:8080    #查看本地的index.html文件

[root@Cacticonf]# 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>

<h2>Welcometo nginx!</h2>

<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

<a>nginx.org</a>.<br/>

Commercialsupport is available at

<a>nginx.com</a>.</p>

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

</body>

</html>

[root@Cacticonf]# ../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

[root@Cactitools]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

[root@Cactitools]# tar zxf libiconv-1.14.tar.gz

[root@Cactilibiconv-1.14]# ./configure  --prefix=/usr/local/libiconv

[root@Cactilibiconv-1.14]# make && make install

 

開始安裝php

[root@Cacti~]# mkdir /home/tools –p

[root@Cactitools]# wget http://mirrors.sohu.com/php/php-5.3.27.tar.gz

[root@Cacti tools]# tar zxf php-5.3.27.tar.gz

[root@Cactitools]# cd php-5.3.27

[root@Cactiphp-5.3.27]# ./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++

[root@Cactiphp-5.3.27]#./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!

#不管怎么變更該數(shù)據(jù)庫的路徑,還是編譯通還過

解決辦法就是:

#mkdir /usr/lib/msyql –p   

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

然后進(jìn)行./configure即可,如果服務(wù)器沒有/usr/lib/mysql/ 目錄,則在/usr/lib/目錄下創(chuàng)建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.

[root@Cactiphp-5.3.27]#make    #編譯

[root@Cactiphp-5.3.27]#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/

[root@Cactiphp-5.3.27]# ln  -s/application/php5.3.27/  /application/php  #設(shè)置軟鏈接

[root@Cactiphp-5.3.27]# ls  -l /application/php

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

 

[root@Cactiphp-5.3.27]# cp php.ini-production  /application/php/lib/php.ini  #拷貝php的配置文件到PHP默認(rèn)目錄

在linux上編譯安裝PHP時(shí),為什么php/etc/目錄下沒有找到php-fpm.conf.default這個(gè)文件?

解答:原因在拷貝配置文件執(zhí)行時(shí),有部分代碼沒有執(zhí)行。

注意:當(dāng)執(zhí)行一大塊代碼結(jié)束后并沒有報(bào)錯(cuò),但沒有執(zhí)行的配置語句會重新顯示出來。

[root@Cactiphp-5.3.27]# cd  /application/php/etc/     #配置文件php-fpm.confs

[root@Cactietc]# 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

[root@Cactietc]# cp php-fpm.conf.default php-fpm.conf

啟動PHP服務(wù)php-fpm:

[root@Cactietc]# /application/php/sbin/php-fpm

檢查php服務(wù)php-fpm的進(jìn)程及啟動端口的情況:

[root@Cactietc]# 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

[root@Cactietc]# 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

[root@Cacticonf]# ../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

[root@Cacticonf]# ../sbin/nginx -s reload

測試LNMP環(huán)境生效的情況:

[root@Cactihtml]# echo "<?php phpinfo(); ?>" >test_info.php

[root@Cactihtml]# cat test_info.php

<?phpphpinfo(); ?>


PHP連接MySQL的情況進(jìn)行測試:

[root@Cactihtml]# 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();

  }

?>

 

下面部署一個(gè)wordpress程序服務(wù):

1.先創(chuàng)建一個(gè)專用的數(shù)據(jù)庫WordPress

[root@Cactihtml]# 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環(huán)境配置準(zhǔn)備:

         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;

          }

[root@Cactihtml]# wget  https://tw.wordpress.org/wordpress-4.8-zh_TW.tar.gz

[root@Cactihtml]# tar xf wordpress-4.8-zh_TW.tar.gz

[root@Cactihtml]# mkdir blog

[root@Cactihtml]# mv wordpress blog/

[root@Cactihtml]# chown  -R nginx.nginx blog

測試情況:瀏覽器顯示Filenot found.

解答:原因是解析不到程序,建設(shè)直接放到html目錄下,避免發(fā)生找不到程序的問題。

 [root@Cactiwordpress]# cp wp-config-sample.php  wp-config.php

 [root@Cactiwordpress]# vi  wp-config.php #配置數(shù)據(jù)庫名、用戶名和密碼即可

 配置成功。

以上是通過一臺服務(wù)器架構(gòu)LNMP;

下面通過兩臺服務(wù)器架設(shè)LNMP,也很簡單:

.8服務(wù)器: 做Nginx服務(wù)器,將wordpress放到nginx的html目錄下,配wp-config.php文件。

/** WordPress數(shù)據(jù)庫的名稱 */

define('DB_NAME', 'wordpress');

/** MySQL數(shù)據(jù)庫用戶名 */

define('DB_USER', '***');

/** MySQL數(shù)據(jù)庫密碼 */

define('DB_PASSWORD', '*****');

/** MySQL主機(jī) */

define('DB_HOST', '.9服務(wù)器IP');

.9服務(wù)器:做Mysql服務(wù)器,創(chuàng)建wordpress數(shù)據(jù)庫。


技巧:當(dāng)服務(wù)器每次重啟的時(shí)候需要nginx、php-fpm服務(wù)自動啟動。

#vi /etc/rc.local     #在默尾增加兩條命令

/application/nginx/sbin/nginx   

/application/php/sbin/php-fpm


運(yùn)行結(jié)果:http://117.40.239.8:8080/wordpress

附件:http://down.51cto.com/data/2366842
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI