WordPress 是一款經常使用的搭建我的博客網站軟件,該軟件使用 PHP 語言和 MySQL 數據庫開發。php
以 Linux 系統 CentOS 6.x 爲例,搭建一個 WordPress 我的站點,具體操做方法以下:html
一、搭建LNMP環境,即Linux、Nginx、Mysql、Phpmysql
二、初始化環境配置linux
三、WordPress下載、安裝、配置nginx
一、搭建LNMP環境,Nginx、Mysql、Phpsql
yum install nginx mysql-server php php-mysql php-fpm -y
如上圖,沒有顯示Nginx安裝成功,單獨yum安裝,顯示沒有可用的nginx包,這是由於沒有Nginx的yum源數據庫
解決方法:下載安裝nginx源vim
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
再次yum安裝centos
yum install nginx -y
成功!!!瀏覽器
二、初始化環境配置
2.1 配置nginx
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/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;
}
# 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$ {
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;
#}
}
啓動Nginx服務
/etc/init.d/nginx start
測試:打開瀏覽器,輸入linux系統的IP
成功!!!
2.2 配置php
/etc/php-fpm start
vim /etc/php.ini
/session.save_path 定位到相應行
session.save_path = "/var/lib/php/session"
更改/var/lib/php/session目錄下全部文件的屬組都改爲 nginx 和 nginx
chown -R nginx: /var/lib/php/session/
驗證環境變量
vim /usr/share/nginx/html/index.php
測試:打開瀏覽器,輸入linux系統的:IP/index.php
成功!!!
2.3 配置mysql
登陸mysql
建立數據庫,建立用戶名密碼及其權限
三、WordPress下載、安裝、配置
下載軟件
cd
wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
解壓、配置
tar -zxvf wordpress-4.9.4-zh_CN.tar.gz
cd wordpress
cp wp-config-sample.php wp-config.php
vim wp-config.php
將WordPress站點文件拷貝到/usr/share/nginx/html/目錄下
\cp -r ./* /usr/share/nginx/html/
測試:打開瀏覽器,輸入linux系統的IP
搭建成功,後續註冊安裝便可使用!!!
PS:添加開機自啓動
chkconfig | grep -E "nginx |php-fpm|mysqld"|awk -F ' ' '{print "chkconfig",$1,"on"}'|bash