centos+nginx+wordpress建站
1 搭建LNMP環(huán)境
Linux:Linux 操作系統(tǒng),本文以 CentOS 8.4 為例。
Nginx:Web 服務(wù)器,本文以 Nginx 1.18 為例。
mariadb:數(shù)據(jù)庫(kù),本文以 mariadb 10.4 為例。
PHP:腳本語(yǔ)言,本文以 PHP 7.4 為例。
1.1 Mariadb
1.1.1 Mariadb安裝
添加源
vim /etc/yum.repos.d/MariaDB.repo ##新建配置文件 ##將一下文件復(fù)制進(jìn)去 # 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保存退出后執(zhí)行dnf install
sudo dnf install MariaDB-server sudo systemctl start mariadb1.1.2 Mariadb配置
執(zhí)行以下命令,進(jìn)入 MariaDB。
mysql執(zhí)行以下命令,創(chuàng)建 MariaDB 數(shù)據(jù)庫(kù)。例如 “wordpress”。
CREATE DATABASE wordpress;執(zhí)行以下命令,創(chuàng)建一個(gè)新用戶。例如 “user”,登錄密碼為 123456。
CREATE USER 'user'@'localhost' IDENTIFIED BY '123456';執(zhí)行以下命令,賦予用戶對(duì) “wordpress” 數(shù)據(jù)庫(kù)的全部權(quán)限。
GRANT ALL PRIVILEGES ON wordpress.* TO 'user'@'localhost' IDENTIFIED BY '123456';可以不用設(shè)置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
執(zhí)行以下命令,打開(kāi) default.conf 文件。
vim default.conf
修改配置為下
注意fastcgi_pass和/etc/php-fpm.d/www.conf一致,取127.0.0.1:9000;
1.2.3 nginx其他配置
SSL配置
按照騰訊云SSL配置文檔進(jìn)行,下載證書(shū)并配置,具體配置可以看下方的配置詳情。
文件上傳2M限制解除
修改/etc/nginx/nginx.conf中頭的大小限制。
client_max_body_size 100m;另外還要修改/etc/php.ini文件,見(jiàn)后文。
nginx最終配置
最后我的配置default.conf配置如下,還配置了http轉(zhuǎn)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啟動(dòng)
systemctl start php-fpm systemctl enable php-fpm驗(yàn)證
echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php訪問(wèn)
http://云服務(wù)器實(shí)例的公網(wǎng) IP/index.php1.3.2 PHP的配置
修改文件為nginx的user和group
vi /etc/php-fpm.d/www.conf搜索user以及grooup,把a(bǔ)pache改為nginx
1.3.3 PHP有關(guān)特殊問(wèn)題
照片裁剪錯(cuò)誤解決
修改/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;打開(kāi)后/etc/php.ini文件,找到并設(shè)置以下選項(xiàng)的值:
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 #可以去官網(wǎng)找最新版 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可以訪問(wèn)的權(quán)限
chown -R nginx:nginx /usr/share/nginx/html/wordpress3 wordpress使用
url/wp-login.php去登錄
注意后臺(tái)設(shè)置url要設(shè)置成真實(shí)的url。
4 參考文章
騰訊云wordpress配置
手動(dòng)搭建LNMP環(huán)境
mariadb安裝
nginx ssl證書(shū)部署
總結(jié)
以上是生活随笔為你收集整理的centos+nginx+wordpress建站的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Cocos论坛九问九答
- 下一篇: 关于命令行上执行java命令的错误分析