LNMP環境搭建wordpress博客及僞靜態

WordPress是使用PHP語言開發的博客平臺,是一款開源的軟件,用戶能夠在支持PHP和MySQL數據庫的服務器上架設屬於本身的網站。也能夠把 WordPress看成一個內容管理系統CMS)來使用。由於使用者衆多,因此WordPress社區很是活躍,有豐富的插件模板資源。使用WordPress能夠快速搭建獨立的博客網站。php

官網:https://cn.wordpress.org/中文文檔:https://codex.wordpress.org/zh-cn:Main_Pagehtml

1、LNMP環境的搭建詳情:http://www.javashuo.com/article/p-sargnajw-d.htmlmysql

2、搭建wordpress bolog博客程序準備:nginx

mysql數據庫配置準備:sql

登錄mysql數據庫:數據庫

mysql –uroot –p123456vim

建立並受權一個專用的數據庫wordpress用於存放blog數據:瀏覽器

create database wordpress;安全

show database like ‘wordpress’;服務器

grant all on worpress.* to worpress@'localhost' identified by '123456';

注:當數據庫和php服務不在同一臺機器上,可執行以下命令受權

grant all on wordpress.* to wordpress@’192.168.0.%’ identified by ‘123456’;

刷新權限,使得建立的用戶生效:

flush privileges;   

查看用戶對應的權限:

select user,host from mysql.user where user='wordpress';  

博客程序下載:

[root@bqh-118 blog]# wget https://cn.wordpress.org/wordpress-4.2.2-zh_CN.tar.gz
[root@bqh-118 blog]# ls
wordpress-4.2.2-zh_CN.tar.gz
[root@bqh-118 blog]# tar xf wordpress-4.2.2-zh_CN.tar.gz 
[root@bqh-118 blog]# ll
總用量 6572
drwxr-xr-x 5 nobody nfsnobody    4096 5月  20 2015 wordpress
-rw-r--r-- 1 root   root      6722406 6月  23 12:05 wordpress-4.2.2-zh_CN.tar.gz
[root@bqh-118 blog]# mv wordpress/* .
[root@bqh-118 blog]# ls
index.php    wordpress-4.2.2-zh_CN.tar.gz  wp-comments-post.php  wp-includes        wp-mail.php       xmlrpc.php
license.txt  wp-activate.php               wp-config-sample.php  wp-links-opml.php  wp-settings.php
readme.html  wp-admin                      wp-content            wp-load.php        wp-signup.php
wordpress    wp-blog-header.php            wp-cron.php           wp-login.php       wp-trackback.php
[root@bqh-118 blog]#rm –rf wordpress/    #刪掉,避免帶路徑

nginx環境配置準備:

[root@bqh-118 conf]# vim 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  www.test.com; 
        root  html/blog;
    location / { 
            index  index.php index.html index.htm;
           }
        location ~ .*\.(php|php5)?$ {
           fastcgi_pass 127.0.0.1:9000;
       fastcgi_index index.php;
       include fastcgi.conf;
         }
        error_page   500 502 503 504  /50x.html;
     }
}

 php環境配置準備:

[root@bqh-118 html]# chown -R root.root blog/
[root@bqh-118 html]# find ./blog/ -type f|xargs chmod 644
[root@bqh-118 html]# find ./blog/ -type d|xargs chmod 755
[root@bqh-118 html]# mkdir -p ./blog/wp-content/uploads

可是這樣設置用戶沒法更改頭像,上傳圖片,咱們能夠單獨給他們設置權限。

[root@bqh-118 html]# chown -R nginx.nginx ./blog/wp-content/uploads  #網站上傳目錄權限,沒有則建立一個便可

修改全部php文件屬主爲root,避免網站php程序遭到篡改

[root@bqh-118 html]# find ./blog/ -type f -name "*.php"|xargs chown -R root.root

如今咱們啓動nginx服務、php服務、mysql服務:

[root@bqh-118 html]# /application/nginx/sbin/nginx 
[root@bqh-118 html]# /application/php/sbin/php-fpm
[root@bqh-118 html]# /etc/init.d/mysqld start

打開瀏覽器:www.test.com

因爲前期咱們把權限搞了,如今須要複製出來,手動建立wp-config.php文件傳上去便可。固然也能夠在前面把安全下降777也行,後期再加固權限。

此時咱們查詢下數據庫裏面的信息:

ok,咱們如今發一個博客試試:

咱們查看一下上傳圖片路徑,發現有多張圖片,緣由是博客優化圖片來着(主頁展現圖片跟文章展現圖片大小)

同時咱們還發現網址後面帶參數,說明是動態博客。

下面咱們爲wordpress博客設置僞靜態規則:

1.打開博客後臺登陸進去----設置----固定鏈接----自定義結構,輸入下面的代碼保存便可:

自定義結構幫助:https://codex.wordpress.org/Using_Permalinks

2. nginx配置文件的server容器中添加下面的代碼:紅色部分

[root@bqh-118 conf]# vim 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  www.test.com; 
        root  html/blog;
    location / { 
            index  index.php index.html index.htm;
 if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; }
    }
        location ~ .*\.(php|php5)?$ {
           fastcgi_pass 127.0.0.1:9000;
       fastcgi_index index.php;
       include fastcgi.conf;
         }
        error_page   500 502 503 504  /50x.html;
     }
}
[root@bqh-118 conf]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful
[root@bqh-118 conf]# /application/nginx/sbin/nginx -s reload

 咱們進入mysql 能夠查看到原始的地址加以對比:

[root@bqh-118 conf]# mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 118
Server version: 5.5.32 MySQL Community Server (GPL)

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> use wordpress;
Database changed
mysql> show tables;
+-----------------------+
| Tables_in_wordpress   |
+-----------------------+
| bh_commentmeta        |
| bh_comments           |
| bh_links              |
| bh_options            |
| bh_postmeta           |
| bh_posts              |
| bh_term_relationships |
| bh_term_taxonomy      |
| bh_terms              |
| bh_usermeta           |
| bh_users              |
+-----------------------+
11 rows in set (0.00 sec)

mysql> select * from bh_posts\G;

php.ini 配置文件的深刻解析詳情見:https://www.jb51.net/article/38632.htm

相關文章
相關標籤/搜索