CentOS 6.4 安裝配置LNMP服務器(Nginx+PHP+MySQL) 及搭建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

登錄之後的界面


恭喜你網站搭建成功!

 

本篇文章來源於 Linux公社網站(www.linuxidc.com)  原文鏈接:http://www.linuxidc.com/Linux/2014-08/105128p5.htm

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章