WordPress簡易安裝教程
WordPress,可能是比較流行的博客了,於是隨便下下來裝着玩玩。
需要準備的軟件:wordpress, nginx/apache, mysql
wordpress可以從官網下載最新的安裝包;如果想要中文版可移步中文官網。
然後解壓到某個路徑下,如/usr/local/wordpress。大概看一下包裏的東西,會發現好多是php文件,因此需要安裝php環境,並且開啓mysql支持。
環境準備好後,連接到mysql數據庫,創建一個數據庫(database)。然後進入到wordpress目錄下,會發現有一個wp-config-sample.php
,複製一份命名爲wp-config.php
,然後打開它,看到關於數據庫的常量定義:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', '<dbname>' );
/** MySQL database username */
define( 'DB_USER', '<user>' );
/** MySQL database password */
define( 'DB_PASSWORD', '<pass>' );
/** MySQL hostname */
define( 'DB_HOST', '<host>' );
/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
需要把數據庫的配置填充到這些變量定義中,底下兩個可以不改,或者按實際情況填寫。
然後在nginx配置一個server來負載wordpress的請求,貼一段代碼:
server {
listen 80;
server_name wordpress;
location / {
root /home/zeon/documents/web/wordpress;
index index.php index.html index.htm;
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;
}
location ~ \.(css|js|ico)$ {
root /home/zeon/documents/web/wordpress;
}
location ~ \.(gif|jpg|png|jpeg)$ {
gzip on;
root /home/zeon/documents/web/wordpress;
}
}
}
最後,訪問ip:80就可以進到wordpress界面啦!有圖有真相:
記錄兩個坑點。(別笑,要銘記每個坑給的傷痛
-
頁面上提示“critical error in your website”,沒有任何其他的提示信息,這時候需要把調試開關打開,我這裏的情況是php安裝的是7.3.0,屬於比較新的版本,需要開啓mysqli支持,如果php沒裝好那麼可能會報mysql_connect無法加載的錯誤。參考指令:
'./configure' '--prefix=/usr/local/php' '--enable-fpm' '--with-mysqli=mysqlnd' '--with-openssl' '--with-zlib' '--with-pcre-dir=/usr/local/pcre'
-
頁面顯示File not found。nginx日誌Primary script unknown。一是檢查這行配置,確認是
$document_root$fastcgi_script_name
。fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_scrip t_name;
二是要確認root的配置。(我就栽在這了~~)