笔记——》wordpress(三):发布wordpress站点到linux服务器

2023年 10月 12日 55.0k 0

摘要

前两篇笔记已经知道了什么是wordpress和做wordpress的内容采集。那么剩下的事情就是 把wordpress发布到服务器上线了。

步骤

wordpress 运行需要php、nginx环境。所以我们的服务器上需要有php环境,nginx环境。 这个基础环境配置,网上有很多教程,本篇不赘述了。由于不借助宝塔面板,我们需要做的有以下几点:

1、上传wordpres文件

  • 首先,在服务器上新建一个目录,随便哪个位置都行,比如我的目录名叫 kuaJing
  • 通过xftp工具把本地文件(phpEnvwwwlocalhost 路径下的)上传到服务器上,就是wordpress主目录及子目录所有文件
  • image.png

    2、修改config配置文件

    修改数据库连接配置,使之能连接到远程数据库。

    
    /** Database username */
    define( 'DB_USER', 'root' );
    
    /** Database password */
    define( 'DB_PASSWORD', '123456' );
    
    /** Database hostname */
    define( 'DB_HOST', 'xxxx.mysql.rds.aliyuncs.com' );
    
    /** Database charset to use in creating database tables. */
    define( 'DB_CHARSET', 'utf8mb4' );
    

    3,修改nginx配置

  • 执行命令查看nginx安装路径where is nginx
  • 通过上一步可以查到nginx的安装目录,cd 到安装目录的conf目录下,vim nginx.conf 文件
  • 把下面的 配置添加到 nginx.conf文件中,一个conf文件是运行多个server的,别添加到另一个server区块里面了
  • 其中:

    • server_name 是服务器的外网ip
    • root 是wordpress的目录
    • 其他的配置就直接复制,不用修改
    upstream php {
            server unix:/tmp/php-cgi.socket;
            server 127.0.0.1:9000;
    	}
    
    server {
            ## Your website name goes here.
            server_name 105.xxx.xxx.193;
            ## Your only path reference.
            root /root/build/kuaJing;
            ## This should be in your http block and if it is, it's not needed here.
            index index.php;
    
            location = /favicon.ico {
                    log_not_found off;
                    access_log off;
            }
    
            location = /robots.txt {
                    allow all;
                    log_not_found off;
                    access_log off;
            }
    
            location / {
                    # This is cool because no php is touched for static content.
                    # include the "?$args" part so non-default permalinks doesn't break when using query string
                    try_files $uri $uri/ /index.php?$args;
            }
    
            location ~ .php$ {
                    #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                    include fastcgi_params;
                    fastcgi_intercept_errors on;
                    fastcgi_pass php;
                    #The following parameter can be also included in fastcgi_params file
                    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            }
    
            location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
                    expires max;
                    log_not_found off;
            }
    }
    

    修改完之后执行命令,service nginx restart,nginx就会重启,此时我们在浏览器输入服务器ip,也就是上面配置的 server_name中的ip,就可以看到wordpress页面啦。

    小问题解决

    1、网址域名映射

    我们正式上线后,如果要给站点做推广,直接丢过去一个ip地址,说访问这个ip就能看到网站,这肯定不合理的。我们需要用域名映射到这个ip,比如我是阿里云服务器,就可以

    在阿里云控制台=》云解析DNS=》xxx.com(域名实例)=》解析设置=》添加记录

    给ip套一个域名,就正规多了,以后就可以用域名访问wordpress了,此时可以说网站已上线。

    2、域名跳转到localhost或host

    当我们用域名跳转到wordpress首页时,此时在页面上 不论点哪个菜单还是按钮,都会跳到localhost上,这种情况下就要修改数据库配置了

    select * from wp_options where option_name in ('siteurl','home');
    

    把通过上面的sql查询到的数据的option_value从 localhost或者ip 更新成 域名 即可。

    3、文件权限

    当我们在已经上线的网站上 上传媒体库文件或安装插件的时候,可能会提示 上传失败 或是安装失败。大概率是因为权限问题导致的 ,我们按照下面的配置操作,应该能解决问题

    举个例子,假如我们到媒体库上传图片提示失败,那我们点到uploads目录,右键

    image.png

    点击其他、勾选写入、点击确定

    image.png

    相关文章

    服务器端口转发,带你了解服务器端口转发
    服务器开放端口,服务器开放端口的步骤
    产品推荐:7月受欢迎AI容器镜像来了,有Qwen系列大模型镜像
    如何使用 WinGet 下载 Microsoft Store 应用
    百度搜索:蓝易云 – 熟悉ubuntu apt-get命令详解
    百度搜索:蓝易云 – 域名解析成功但ping不通解决方案

    发布评论