1. 程式人生 > >centos6.8使用WordPress搭建個人部落格

centos6.8使用WordPress搭建個人部落格

一、搭建LNMP

1.安裝Nginx

安裝Nginx

[[email protected] ~]# yum -y install nginx 
Loaded plugins: fastestmirror
Setting up Install Process
Determining fastest mirrors
base                            | 3.7 kB     00:00     
base/primary_db                 | 4.7 MB     00:00     
epel                            | 3.2 kB     00:00     
epel/primary                    | 3.2 MB     00:00     
.........................................................省略中間,直到看到
Complete!

配置/etc/nginx/conf.d/default.conf檔案,將檔案內容修改如下

[[email protected] ~]# vim /etc/nginx/conf.d/default.conf  

server {
listen       80;
root   /usr/share/nginx/html;
server_name  localhost;


#charset koi8-r;
#access_log  /var/log/nginx/log/host.access.log  main;
location / {
    index index.php index.html index.htm;
}

#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   /usr/share/nginx/html;
}

#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
fastcgi_pass   127.0.0.1:9000;
fastcgi_index   index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
include        fastcgi_params;
}
}

啟動Nginx

[[email protected] ~]# service nginx start
Starting nginx:                                     
  [  OK  ]

設定開機自啟

[[email protected] ~]# chkconfig nginx on

測試Nginx是否安裝成功,在瀏覽器中輸入伺服器IP地址,若顯示如下,則代表成功。

2.安裝MySQL

使用命令安裝MySQL

[[email protected] ~]# yum -y install mysql-server
..........................................................
Installed:
    mysql-server.x86_64 0:5.1.73-8.el6_8                 

Dependency Installed:
  mysql.x86_64 0:5.1.73-8.el6_8                        
  perl-DBD-MySQL.x86_64 0:4.013-3.el6                  
  perl-DBI.x86_64 0:1.609-4.el6                        

Complete!

啟動MySQL

[[email protected] ~]# service mysqld start

Initializing MySQL database:  WARNING: The host 'catyuan' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h catyuan password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                      [  
OK  ]
Starting mysqld:                                      [  
OK  ]

將MySQL設定為開機自啟

[[email protected] ~]# chkconfig mysqld on

設定MySQL使用者的root密碼為123456。可自己設定。

[[email protected] ~]# /usr/bin/mysqladmin -u root password '123456'

3.安裝PHP

使用命令安裝PHP以及相關擴充套件包

[[email protected] ~]# yum install php php-fpm php-mysql -y
.....................................
Dependency Installed:
  apr.x86_64 0:1.3.9-5.el6_9.1                         
  apr-util.x86_64 0:1.3.9-3.el6_0.1                    
  apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1               
  httpd.x86_64 0:2.2.15-69.el6.centos                  
  httpd-tools.x86_64 0:2.2.15-69.el6.centos            
  mailcap.noarch 0:2.1.31-2.el6                        
  php-cli.x86_64 0:5.3.3-49.el6                        
  php-common.x86_64 0:5.3.3-49.el6                     
  php-pdo.x86_64 0:5.3.3-49.el6                        

Complete!

啟動php-fpm程序

[[email protected] ~]# service php-fpm start
Starting php-fpm:                                     [  
OK  ]

將php-fpm設定為開機自啟

[[email protected] ~]# chkconfig php-fpm on

二、安裝配置WordPress

1.安裝WordPress

a.使用yum命令安裝WordPress,使用yum下載的為英文版

[[email protected] ~]# yum install wordpress -y

b.中文版下載命令為

[[email protected] ~]# wget https://cn.wordpress.org/wordpress-4.7.4-zh_CN.tar.gz

解壓

[[email protected] ~]# tar zxvf wordpress-4.7.4-zh_CN.tar.gz

2.配置資料庫

登入MySQL資料庫

[[email protected] ~]# mysql -uroot -p
Enter password: 
輸入剛才設定上網MySQL的密碼
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> 

給WordPress建立一個數據庫,資料庫名字為wordpress

mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)

為建立好的資料庫建立一個使用者user

mysql> create user [email protected];
Query OK, 0 rows affected (0.00 sec)

給user使用者設定密碼‘123456’

mysql> set password for [email protected]=password("123456");
Query OK, 0 rows affected (0.00 sec)

給user使用者開通資料庫wordpress的完全訪問權

mysql>  grant all privileges on wordpress.* to [email protected] identified by '123456';
Query OK, 0 rows affected (0.00 sec)

使用下面命令使上一條命令生效

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

退出MySQL

mysql> exit
Bye

3.將資料庫資訊寫入WordPress的配置檔案中

切換到wordpress目錄下

[[email protected] wordpress]# cd wordpress

建立新配置檔案,將wp-config-sample.php檔案複製到名為wp-config.php的檔案,使用以下命令建立新的配置檔案,並將原先的示例配置檔案保留作為備份。

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

開啟新的配置檔案

[[email protected] wordpress]# vim wp-config.php

在wp-config.php檔案裡找到以下內容,並填入

// ** MySQL 設定 - 具體資訊來自您正在使用的主機 ** //
/** WordPress資料庫的名稱 */
define('DB_NAME', 'wordpress');

/** MySQL資料庫使用者名稱 */
define('DB_USER', 'user');

/** MySQL資料庫密碼 */
define('DB_PASSWORD', '123456');

/** MySQL主機 */
define('DB_HOST', 'localhost');

/** 建立資料表時預設的文字編碼 */
define('DB_CHARSET', 'utf8');

/** 資料庫整理型別。如不確定請勿更改 */
define('DB_COLLATE', '');

4.配置WordPress

先刪除網站根目錄下的index.html檔案

[[email protected] wordpress]# rm /usr/share/nginx/html/index.html

將安裝的檔案移動到web 伺服器的根目錄/usr/share/ngnix/html

[[email protected] wordpress]# mv * /usr/share/nginx/html/

重啟Nginx

[[email protected] ~]# service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]

找一個瀏覽器,輸入公網IP地址。填寫資訊進行註冊。

在這裡插入圖片描述
5.配置域名解析
購買一個域名,在雲解析上新增解析,使用者即可通過域名進行訪問

6.關於進入WordPress的登入頁面
瀏覽器導航欄輸入 IP/wp-login.php