標籤:htm php.ini chkconfig conf root 設定 sha html 使用者
使用 Yum 安裝必要軟體
yum install nginx php php-fpm php-mysql mysql-server -y
將各軟體佈建為開機啟動
chkconfig nginx on
chkconfig mysqld on
chkconfig php-fpm on
配置 Nginx
vim /etc/nginx/conf.d/default.conf
按字母“I”鍵或 “Insert” 鍵切換至編輯模式,將已有內容全部清除,複製並粘貼以下內容到 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;
}
} index index.php index.html index.htm;
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
啟動 Nginx
service nginx start
配置 MySQL
啟動 MySQL 伺服器
service mysqld start
設定 MySQL 伺服器 root 使用者的密碼,本教程設定為 “123456”,後續步驟中需要用到此使用者名稱和密碼
/usr/bin/mysqladmin -u root password “123456”
配置 PHP
啟動 PHP-FPM 服務
service php-fpm start
開啟/etc/php.ini檔案
vim /etc/php.ini
進入後直接輸入以下內容,斷行符號定位到 “session.save_path” 的位置:
session.save_path = “/var/lib/php/session”
更改/var/lib/php/session目錄下所有檔案的屬組都改成 nginx 和 nginx
chown -R nginx:nginx /var/lib/php/session
請使用以下命令在 Web 目錄下建立index.php檔案
vim /usr/share/nginx/html/index.php
Test Page“;
echo “Hello World!”;
?>
先刪除網站根目錄下的index.html檔案
rm /usr/share/nginx/html/index.html
依次下載 WordPress 並解壓到目前的目錄
wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
tar zxvf wordpress-4.9.4-zh_CN.tar.gz
設定資料庫
使用 root 使用者登入到 MySQL 伺服器
mysql -uroot -p
為 WordPress 建立 MySQL 資料庫 “wordpress”
CREATE DATABASE wordpress;
為已建立好的 MySQL 資料庫建立一個新使用者 “[email protected]
CREATE USER [email protected];
並為此使用者佈建密碼“wordpresspassword”
SET PASSWORD FOR [email protected]=PASSWORD(“wordpresspassword”);
為建立的使用者開通資料庫 “wordpress” 的完整存取。
GRANT ALL PRIVILEGES ON wordpress.* TO [email protected] IDENTIFIED BY ‘wordpresspassword’;
使用以下命令使所有配置生效
FLUSH PRIVILEGES;
配置完成,退出 MySQL
exit
寫入資料庫資訊
建立新設定檔
cd wordpress/
cp wp-config-sample.php wp-config.php
開啟並編輯新建立的設定檔
vim wp-config.php
// MySQL settings – You can get this info from your web host //
/* The name of the database for WordPress /
define(‘DB_NAME’, ‘wordpress’);
/* MySQL database username /
define(‘DB_USER’, ‘user’);
/* MySQL database password /
define(‘DB_PASSWORD’, ‘wordpresspassword’);
/* MySQL hostname /
define(‘DB_HOST’, ‘localhost’);
安裝 WordPress
mv * /usr/share/nginx/html/
在 網頁瀏覽器地址欄輸入 WordPress 網站的 IP 位址
CentOS 搭建WordPress個人網站