1. 程式人生 > >WordPress建站踩坑

WordPress建站踩坑

近日在自己伺服器上嘗試使用WordPress搭建了一下自己的部落格,因為第一次折騰,所以遇到了一些坑,在這裡記錄一下,避免下次再踩的同時也可以與大家共同分享。

網上教程大多是使用lnmp一鍵安裝包來一鍵安裝nginx、mysql、php環境。我這邊由於一些原因,手動安裝了nginx和php環境。具體安裝步驟網上教程很多,不再累述。

問題一:

在安裝WordPress的時候遇到了問題,由於第一次接觸php,在安裝過程中都是按照網上教程來做,php的在nginx配置檔案nginx.conf中的配置未完成。導致WordPress的啟動url需要多一層/wordpress。

此時nginx中配置檔案的server部分如下



    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  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   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # 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  /usr/local/nginx/html/$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


   

下面部分的意思是在訪問.php檔案的時候,網站根目錄為/usr/local/nginx/html

        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;
            include        fastcgi_params;
        }

解壓後的wordpress檔案位置如圖所示:

使用 按步驟操作後,在登陸之後直接報了403 Forbidden nginx/1.14.0。

上網查閱資料後發現是nginx.conf配置檔案未配置。備份nginx.conf檔案後進行修改。server部分程式碼如下:

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/local/nginx/html/wordpress;
            index  index.html index.htm index.php;
        }

        #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   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /usr/local/nginx/html/wordpress;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

重新安裝wordpress後問題解決。

問題二:

wordpress配置過程中,無法建立目錄 uploads/年/月份,沒有上級目錄的寫許可權。

WordPress剛開始搭建,暫時遇到這些小坑,若之後有問題,會繼續記錄分享。