centos+nginx+wordpress建站
1 搭建LNMP環境
Linux:Linux 操作系統,本文以 CentOS 8.4 為例。
Nginx:Web 服務器,本文以 Nginx 1.18 為例。
mariadb:數據庫,本文以 mariadb 10.4 為例。
PHP:腳本語言,本文以 PHP 7.4 為例。
1.1 Mariadb
1.1.1 Mariadb安裝
添加源
vim /etc/yum.repos.d/MariaDB.repo ##新建配置文件 ##將一下文件復制進去 # MariaDB 10.4 CentOS repository list - created 2020-06-01 04:02 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.4/centos8-amd64 module_hotfixes=1 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1保存退出后執行dnf install
sudo dnf install MariaDB-server sudo systemctl start mariadb1.1.2 Mariadb配置
執行以下命令,進入 MariaDB。
mysql執行以下命令,創建 MariaDB 數據庫。例如 “wordpress”。
CREATE DATABASE wordpress;執行以下命令,創建一個新用戶。例如 “user”,登錄密碼為 123456。
CREATE USER 'user'@'localhost' IDENTIFIED BY '123456';執行以下命令,賦予用戶對 “wordpress” 數據庫的全部權限。
GRANT ALL PRIVILEGES ON wordpress.* TO 'user'@'localhost' IDENTIFIED BY '123456';可以不用設置root賬戶登錄密碼
然后更新配置退出。
1.2 Nginx
1.2.1 nginx安裝
dnf -y install http://nginx.org/packages/centos/8/x86_64/RPMS/nginx-1.18.0-1.el8.ngx.x86_64.rpm可以去http://nginx.org/packages/centos/8/x86_64/RPMS/?spm=a2c4g.11186623.2.31.557423bfYPMd6u獲取最新的包名并安裝
查看版本
1.2.2 nginx配置
修改配置
cd /etc/nginx/conf.d
cp default.conf default.conf.bak
執行以下命令,打開 default.conf 文件。
vim default.conf
修改配置為下
注意fastcgi_pass和/etc/php-fpm.d/www.conf一致,取127.0.0.1:9000;
1.2.3 nginx其他配置
SSL配置
按照騰訊云SSL配置文檔進行,下載證書并配置,具體配置可以看下方的配置詳情。
文件上傳2M限制解除
修改/etc/nginx/nginx.conf中頭的大小限制。
client_max_body_size 100m;另外還要修改/etc/php.ini文件,見后文。
nginx最終配置
最后我的配置default.conf配置如下,還配置了http轉https、rewrite /wordpress / permanent;等,修改了server_name的配置。
server {listen 443 ssl;server_name *.sidney-tan.com;ssl_certificate sidney-tan.com_bundle.crt;ssl_certificate_key sidney-tan.com.key;ssl_session_timeout 5m;ssl_protocols TLSv1.2 TLSv1.3;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;ssl_prefer_server_ciphers on;rewrite /wordpress / permanent;#charset koi8-r;#access_log /var/log/nginx/log/host.access.log main;root /usr/share/nginx/html/wordpress;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;} } server {listen 80;server_name *.sidney-tan.com;return 301 https://$host$request_uri; }1.3 PHP的安裝和配置
1.3.1 PHP的安裝
dnf -y install epel-release dnf update epel-release dnf clean all dnf makecache dnf module enable php:7.4 dnf install php php-curl php-dom php-exif php-fileinfo php-fpm php-gd php-hash php-json php-mbstring php-mysqli php-openssl php-pcre php-xml libsodium php -v啟動
systemctl start php-fpm systemctl enable php-fpm驗證
echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php訪問
http://云服務器實例的公網 IP/index.php1.3.2 PHP的配置
修改文件為nginx的user和group
vi /etc/php-fpm.d/www.conf搜索user以及grooup,把apache改為nginx
1.3.3 PHP有關特殊問題
照片裁剪錯誤解決
修改/etc/php.ini文件,最后的extension,然后重啟php
[gd] ; Tell the jpeg decode to ignore warnings and try to create ; a gd image. The warning will then be displayed as notices ; disabled by default ; http://php.net/gd.jpeg-ignore-warning ;gd.jpeg_ignore_warning = 1 ; extension = /usr/lib64/php/modules/gd.so文件上傳2M限制解除
修改/etc/nginx/nginx.conf中頭的大小限制。
client_max_body_size 100m;打開后/etc/php.ini文件,找到并設置以下選項的值:
upload_max_filesize = 100M post_max_size = 105M memory_limit = 128M max_execution_time = 30 max_input_time = 602 wordpress搭建
2.1 下載wordpress
rm -rf /usr/share/nginx/html/index.php cd /usr/share/nginx/html wget https://cn.wordpress.org/wordpress-5.0.4-zh_CN.tar.gz #可以去官網找最新版 tar zxvf wordpress-5.0.4-zh_CN.tar.gz2.2 修改wordpress配置文件
cd /usr/share/nginx/html/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', '123456');/** MySQL hostname */define('DB_HOST', 'localhost');為了支持更新插件和素材,需要在此文件中再添加一下配置:
if ( !defined('ABSPATH') )define('ABSPATH', dirname(__FILE__) . '/'); define('WP_TEMP_DIR', ABSPATH.'wp-content/tmp'); define("FS_METHOD", "direct"); define("FS_CHMOD_DIR", 0777); define("FS_CHMOD_FILE", 0777); define('ALLOW_UNFILTERED_UPLOADS', true);并且修改wordpress文件夾為nginx可以訪問的權限
chown -R nginx:nginx /usr/share/nginx/html/wordpress3 wordpress使用
url/wp-login.php去登錄
注意后臺設置url要設置成真實的url。
4 參考文章
騰訊云wordpress配置
手動搭建LNMP環境
mariadb安裝
nginx ssl證書部署
總結
以上是生活随笔為你收集整理的centos+nginx+wordpress建站的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Cocos论坛九问九答
- 下一篇: 关于命令行上执行java命令的错误分析