今天想用wordpress搭個博客,個人服務器是騰訊雲的,而後騰訊雲裏有官方文檔搭建的,但它是用centos爲例,php
搞得個人ubuntu跟着它走了些歪路,而後結合網上其它資料,終於一點一點的解決了。html
聲明 :參考這篇博文的儘可能跟個人環境同樣,由於若是不同的話,那些配置文件的位置可能不一樣,這樣就不方便了。mysql
我把遇到的問題都一個個記下來,真的遇到太多坑了。linux
說明 :關於服務器方面,我就不詳細說了,買服務器,買域名這些網上一堆,在這裏就不花篇幅講了。nginx
參考這篇博文的人須要有點linux基礎,不適合小白。或者說,我是爲了記錄遇到的問題才決定寫這篇博文的。web
這裏就不說了,買就完事了。sql
先安裝上,後面會用到。數據庫
apt-get update apt-get install nginx
而後就訪問 http://你的服務器域名或ip地址ubuntu
出現下圖表明安裝成功vim
apt-get -y install php7.0-fpm php-mysql
PHP fix_pathinfo 潛在安全漏洞修復,在/etc/php/7.0/fpm/php.ini中找到
;cgi.fix_pathinfo=1
把1改爲0
cgi.fix_pathinfo=0
重啓
systemctl restart php7.0-fpm
其實也不算配置,就是要建一個數據庫,由於後面的wordpress要用到,我在這裏就順着順序寫了,不用
等到後面
使用 root 用戶登陸到 MySQL 服務器。
mysql -uroot -p
爲 WordPress 建立 MySQL 數據庫 「wordpress」。
CREATE DATABASE wordpress;
爲已建立好的 MySQL 數據庫建立一個新用戶 「user@localhost」。
CREATE USER user@localhost;
併爲此用戶設置密碼「wordpresspassword」。
SET PASSWORD FOR user@localhost=PASSWORD("wordpresspassword");
GRANT ALL PRIVILEGES ON wordpress.* TO user@localhost IDENTIFIED BY'wordpresspassword';
FLUSH PRIVILEGES;
exit;
打開一個默認文件,將裏面內容清空,換上下文。
sudo vim /etc/nginx/sites-available/default
所要替換的內容:
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; } }
sudo vim /etc/php/7.0/fpm/php.ini
而後搜索到session.save_path
/session.save_path
將其值改爲下圖所示,不過也得先肯定哪一個sessions的文件夾對不對
我就是被這個問題坑死的。。。
編輯文件:
sudo vim /etc/php/7.0/fpm/pool.d/www.conf
而後搜索到listen = /run/php/php7.0-fpm.sock
/listen = /run/php/php7.0-fpm.sock
而後將其值改爲9000
listen = 9000
第一個是原來的,我註釋掉了。
sudo vim /usr/share/nginx/html/index.php
裏面內容爲
<?php echo "<title>Test Page</title>"; echo "Hello World!"; ?>
http://雲服務器實例的公網 IP/index.php
測試結果:
至此LNMP環境搭建成功~
rm /usr/share/nginx/html/*
wget https://cn.wordpress.org/wordpress-4.7.4-zh_CN.tar.gz tar zxvf wordpress- 4.7.4-zh_CN.tar.gz
wordpress須要跟數據庫一塊兒用,因此須要把數據庫信息配置到wordpress中,
wordpress的 安裝文件夾包含名爲 wp-config-sample.php 的示例配置文件。
將 wp-config-sample.php
文件複製到名爲 wp-config.php
的文件,
使用如下命令建立新的配置文件,並將原先的示例配置文件保留做爲備份。
cd wordpress/
cp wp-config-sample.php wp-config.php
vim wp-config.php
而後把相應信息填進去,最後一個DB_HOST通常是localhost,不用改。
// ** 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/
輸入訪問地址:http://你的服務器域名或ip地址/wp-admin/install.php
出現下圖
而後填入相關信息完成安裝。
而後後面的博客就隨便大家的喜愛去修改了。
參考連接:
https://cloud.tencent.com/document/product/213/8044
https://www.jianshu.com/p/79942f37b2dc
http://www.javashuo.com/article/p-qooqdhmp-eb.html