在服務器上搭建wordpress個人博客 php7.2+nginx+mysql+wordperss


買了台VPS,准備搭建一個博客。用過幾個博客框架還是覺得Wordpress好用。主題多,插件也非常的便利,而且大多還免費開源。搭建也很簡單,其實安裝好php+mysql+nginx+wordpress就差不多了。其他的需要一些簡單的配置就可以掛上去了。

輸入以下命令安裝MySQL+nginx+php:

sudo apt-get update
apt-get install mysql server mysql-client
apt-get install nginx
apt-get install php7.2 php-mysql php7.2-fpm php-pear php7.2-curl php7.2-json php7.2-cgi php7.2-mysql

查看安裝版本 nginx -v / mysql -v / php7.2 -v

 

使用FTP上傳SSL證書

如果沒有安裝可以查看我 安裝vsftpd文
沒有SSL證書可以去freessl.cn免費獲取一個證書
 
 
這里我使用MacOS自帶的 scp命令
 
工作目錄移動到你SSL證書文件路徑下然后執行以下命令:
Filepath 是你的文件名 root你服務器用戶名 serverhost服務器地址 :~ (上傳到~路徑)
sudo scp filepath root@serverhost:~ 
解壓證書放到/etc/ssl/wordpress/下(按照你的需求選擇,這里的演示將使用該路徑)
解壓命令
zip文件解壓
sudo unzip youfile.zip -d /etc/ssl/wordpress/
tar文件解壓
tar -zxvf youfile.tar -c /etc/ssl/wordpress

 

 
 
修改nginx配置文件
路徑一般在:vi /etc/nginx/sites-available/default 
修改內容如下:
 
server {
        #監聽80http端口
        #listen 80 default_server;
        #listen [::]:80 default_server;

        # SSL configuration
        #SSL配置 監聽443SSL端口 https
         listen 443 ssl;
         listen [::]:443 ssl;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;
        #網站路徑。
        root /var/www/wordpress;
       #SSL證書配置 注意 這里要填寫你證書的路徑里的兩個文件,這里是我的pem和key文件
        ssl_certificate /etc/ssl/wordpress/fechain.pem;
        ssl_certificate_key /etc/ssl/wordpress/private.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;
        # Add index.php to the list if you are using PHP
        #網站主頁配置 php主頁記得加index.php
        index index.html index.htm index.php;
        #填寫你的服務器
        server_name hhxblog.ml;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #啟用php,fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;對應你的php-fpm版本
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }

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

 

 
重啟nginx
service nginx start (這里報錯可能是上面的配置錯誤了)
 

使用wget獲取並解壓wordpress

cd /var/www
sudo wget https://wordpress.org/latest.zip
unzip latest.zip
 

MySQL數據庫配置 

參考官網 https://codex.wordpress.org/zh-cn:安裝WordPress#.E6.AD.A5.E9.AA.A43:.E8.AE.BE.E7.BD.AEwp-config.php
參考代碼搬運:
$ mysql -u adminusername -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5340 to server version: 3.23.54

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE DATABASE databasename;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"hostname"
    -> IDENTIFIED BY "password";
Query OK, 0 rows affected (0.00 sec)
  
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> EXIT
Bye
$ 
 

修改wordpress配置文件

cd 你的wordpress路徑/
sudo mv wp-config-sample.php wp-config.php
vi wp-config.php(根據提示填寫數據庫信息)
 
填寫你數據庫信息 參考官網 :https://codex.wordpress.org/zh-cn:編輯_wp-config.php
注意:配置里的 Authentication Unique Keys and Salts 需要填寫
官網生成AUKS地址: https://api.wordpress.org/secret-key/1.1/salt/
 
然后打開你的網站按照提示配置即可完成安裝!
https://youhost/
 
辛苦碼字,轉載請著名出處! https://www.hhxblog.ml


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM