CentOS搭建wordpress

最后更新于:2023-04-14 11:14:22

【一】创建配置WordPress数据库

  1. 登入mysql
mysql -u root -p

输入root账户密码即可进入

2. 创建wordpress数据库

CREATE DATABASE wordpress;

3. 创建wordpress数据库账户&&设置密码

CREATE USER book@localhost IDENTIFIED BY 'z1024789';

4. 授予wordpress数据库账户在wordpress数据库上所需权限

GRANT ALL PRIVILEGES ON wordpress.* TO book@localhost;

5. 刷新数据库缓存

FLUSH PRIVILEGES;

6. 退出数据库

exit

【二】安装wordpress

1. 安装zip压缩

yum install -y unzip zip

2. 进入nginx发布主目录

cd /var/www/html

3. 上传下载好的wordpress安装包

rz

4. 解压安装包

unzip -q wordpress-5.8-zh_CN.zip

5. 移动到主目录

cp -rf wordpress/* /var/www/html/

6. 删除多余目录

rm -rf wordpress

7. 给目录权限

chmod -R 777 /var/www/html/

8. 新建uploads文件夹并给权限

mkdir -p /var/www/html/wp-content/uploads
chmod -R 777 /var/www/html/wp-content/uploads

9. 配置wordpress数据库

cd /var/www/html
cp wp-config-sample.php wp-config.php
vim wp-config.php

找到配置数据库代码,按i键修改

define(‘DB_NAME’, ‘wordpress’);
define(‘DB_USER’, ‘book’);
define(‘DB_PASSWORD’, ‘z1024789’);

修改完毕按ESC取消输入,再按

:wq!

保存并退出

10. nginx配置文件nginx.conf

cd /usr/local/nginx/conf
vim nginx.conf
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;
	root  /var/www/wordpress;
	index  index.php index.html index.htm;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /var/www/wordpress;
            index index.php index.html index.htm;
	    try_files $uri $uri/ /index.php?$args;
        }
	rewrite /wp-admin$ $scheme://$host$uri/ permanent;
	location ~ \.php$ {
	root  /var/www/wordpress;
	fastcgi_pass   127.0.0.1:9000;
	fastcgi_index  index.php;
	fastcgi_param  SCRIPT_FILENAME  /var/www/wordpress$fastcgi_script_name;
	include        fastcgi_params;
	
	}
	}


	server {
	listen 8090;
	server_name 127.0.0.1;
	access_log /usr/local/phpMyAdmin/phpmyadmin-access.log;
	location / {
	root /usr/local/phpMyAdmin/;
	index index.php;
	}
	location ~ \.php$ {
	root /usr/local/phpMyAdmin/;
	fastcgi_pass  127.0.0.1:9000;
	#fastcgi_pass  unix:/var/run/php-fpm/php-fpm.sock;
	fastcgi_index index.php;
	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	include fastcgi_params;
	}
	location ~ /\.ht {
	deny all;
	}
	}


        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.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$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$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;
        #}
    


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}

11. 重启nginx mysql php服务

systemctl daemon-reload
systemctl restart nginx.service
systemctl restart mysqld.service
systemctl restart php-fpm.service

12. 配置WordPress数据库信息即可

http://yourIP/wp-admin/install.php

wordpress后台固定链接修改自定义结构