<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WordPress &#8211; 秋山砚语</title>
	<atom:link href="https://gsfall.cn/archives/category/all/wordpress/feed" rel="self" type="application/rss+xml" />
	<link>https://gsfall.cn</link>
	<description>GushanFall&#039;s Blog</description>
	<lastBuildDate>Thu, 24 Apr 2025 02:18:07 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://gsfall.cn/wp-content/uploads/2025/04/cropped-icon-32x32.png</url>
	<title>WordPress &#8211; 秋山砚语</title>
	<link>https://gsfall.cn</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>WordPress 环境搭建教程</title>
		<link>https://gsfall.cn/archives/67</link>
					<comments>https://gsfall.cn/archives/67#respond</comments>
		
		<dc:creator><![CDATA[GushanFall]]></dc:creator>
		<pubDate>Wed, 09 Apr 2025 07:48:39 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[已分类]]></category>
		<category><![CDATA[教程]]></category>
		<guid isPermaLink="false">https://gsfall.cn/?p=67</guid>

					<description><![CDATA[Ubuntu + PHP + Nginx + MySQL + Wordpress 的建站过程]]></description>
										<content:encoded><![CDATA[
<h1 class="wp-block-heading">为什么要写该教程</h1>



<p>本文是对自己安装 WordPress 过程的一个总结。在安装过程中，翻阅了很多资料、教程，但是没有完全满足个人要求的教程。有的是其他环境比如 Apache2 ，有的是 CentOS。</p>



<p>所以既然自己成功安装了 WordPress，就顺便记录一下自己的安装过程，给可能需要的人提供一点帮助。</p>



<p>搭建过程主要参考了 <a href="https://www.cnblogs.com/frank3215/p/wordpress-ubuntu.html">总结｜在Ubuntu 22.04上设立WordPress &#8211; frank3215 &#8211; 博客园</a>，是在该作者的基础上进行增改，也增加了一些操作解释。</p>



<h1 class="wp-block-heading">环境要求</h1>



<ol class="wp-block-list">
<li><code>Ubuntu</code></li>



<li><code>PHP 7.4</code> / <code>PHP 8.0</code> （据说 <code>PHP 8.1</code> 可能会产生错误，但没亲自试过）</li>



<li><code>Nginx</code></li>



<li><code>MySQL 8.0+</code></li>
</ol>



<p>如果是其他的环境，本文可能提供不了帮助。</p>



<h1 class="wp-block-heading">安装依赖</h1>



<p>开始之前，更新软件包索引</p>



<pre class="wp-block-code"><code>sudo apt-get update</code></pre>



<h2 class="wp-block-heading">Nginx</h2>



<pre class="wp-block-code"><code>sudo apt-get install nginx</code></pre>



<h2 class="wp-block-heading">MySQL</h2>



<pre class="wp-block-code"><code># 安装 mysql 及所需依赖
sudo apt-get install mysql-client-core-8.0 mysql-server-core-8.0 mysql-server mysql-client --fix-missing 
# 启动 mysql 服务
sudo service mysql start</code></pre>



<h2 class="wp-block-heading">PHP</h2>



<p>添加第三方软件源以安装 PHP</p>



<pre class="wp-block-code"><code>sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https
LC_ALL=C.UTF-8 sudo add-apt-repository ppa:ondrej/php</code></pre>



<p>更新软件源</p>



<pre class="wp-block-code"><code>sudo apt update</code></pre>



<p>安装 <code>php8.0</code></p>



<pre class="wp-block-code"><code>sudo apt-get install php8.0 php8.0-cli php8.0-fpm php8.0-mysql php8.0-opcache php8.0-mbstring php8.0-xml php8.0-gd php8.0-curl php8.0-cgi</code></pre>



<p>如果要安装 <code>php7.4</code> ，请参考 <a href="https://www.cnblogs.com/frank3215/p/wordpress-ubuntu.html">总结｜在Ubuntu 22.04上设立WordPress &#8211; frank3215 &#8211; 博客园</a></p>



<p>设置开机自启动</p>



<pre class="wp-block-code"><code>sudo systemctl enable php8.0-fpm</code></pre>



<p>下面的命令可以查看运行状态</p>



<pre class="wp-block-code"><code>sudo systemctl status php8.0-fpm</code></pre>



<p>注意：<code>/etc/php/8.0/fpm/php.ini</code> 中可修改上传文件的大小限制</p>



<h1 class="wp-block-heading">安装并配置 WordPress</h1>



<h2 class="wp-block-heading">下载 WordPress</h2>



<p>下载并解压最新版的 WordPress</p>



<pre class="wp-block-code"><code>wget https://wordpress.org/latest.zip 
unzip latest.zip

# 如果未安装 unzip 请提前安装
sudo apt install unzip</code></pre>



<h2 class="wp-block-heading">用 MySQL 建立数据库</h2>



<p>以管理员登录数据库</p>



<pre class="wp-block-code"><code>sudo mysql -u adminusername -p</code></pre>



<p>创建数据库 <code>wordpress</code></p>



<pre class="wp-block-code"><code>CREATE DATABASE wordpress;</code></pre>



<p>创建用户和设置密码（ <code>password</code> 可以自己任意设置），并给予权限</p>



<pre class="wp-block-code"><code>CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'wordpress'@'localhost';
FLUSH PRIVILEGES;
EXIT;</code></pre>



<h2 class="wp-block-heading">修改 <code>wp-config.php</code></h2>



<p>进入 <code>wordpress</code> 文件夹，复制 <code>wp-config-sample.php</code> 为 <code>wp-config.php</code></p>



<pre class="wp-block-code"><code>cd wordpress 
cp wp-config-sample.php wp-config.php</code></pre>



<p>打开 <code>wp-config.php</code> ，修改以下内容</p>



<p>首先修改数据库设置， <code>password</code> 为前面设置的密码</p>



<pre class="wp-block-code"><code>// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** Database username */
define( 'DB_USER', 'wordpress' );

/** Database password */
define( 'DB_PASSWORD', 'password' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );</code></pre>



<p>然后找到以下内容，填入 <a href="https://api.wordpress.org/secret-key/1.1/salt/">生成器</a> 中随机生成的值</p>



<pre class="wp-block-code"><code>/** Authentication Unique Keys and Salts. */
define( 'AUTH_KEY',         '' );
define( 'SECURE_AUTH_KEY',  '' );
define( 'LOGGED_IN_KEY',    '' );
define( 'NONCE_KEY',        '' );
define( 'AUTH_SALT',        '');
define( 'SECURE_AUTH_SALT', '' );
define( 'LOGGED_IN_SALT',   '' );
define( 'NONCE_SALT',       '' );</code></pre>



<p>最后回到上一级目录，将整个 <code>wordpress</code> 移动到 <code>/var/www/html/</code> 中，这是 Nginx 服务器的默认文件目录</p>



<pre class="wp-block-code"><code>cd ..
sudo mv wordpress /var/www/html/wordpress</code></pre>



<p>设置正确的文件权限和所有权，以确保</p>



<ul class="wp-block-list">
<li>Web 服务器（<code>www-data</code> 用户）能够读取和写入必要的文件。</li>



<li>其他用户只能读取文件和目录，而不能修改它们。</li>
</ul>



<pre class="wp-block-code"><code>chown -R www-data:www-data /var/www/html
sudo find /var/www/html/wordpress -type d -exec chmod 755 {} \;
sudo find /var/www/html/wordpress -type f -exec chmod 644 {} \;</code></pre>



<h2 class="wp-block-heading">配置 Nginx</h2>



<p>修改 <code>/etc/nginx/sites-available/wordpress</code>，没有则自己创建，其中 <code>example.com</code> 改为自己的域名</p>



<pre class="wp-block-code"><code># WordPress 站点配置文件
server {
    # 监听 HTTP 请求
    listen 80;
    listen &#91;::]:80;

    # 定义网站的域名
    server_name example.com;

    # 设置网站的根目录
    root /var/www/html/wordpress;

    # 定义默认的索引文件
    index index.php index.html index.htm index.nginx-debian.html;

    # 处理网站根路径请求
    location / {
        # 如果请求的文件或目录不存在，则转发到 index.php
        try_files $uri $uri/ /index.php?$args;
    }

    # 处理 WordPress 站点地图
    location ~* /wp-sitemap.*\.xml {
        # 如果站点地图文件不存在，则转发到 index.php
        try_files $uri $uri/ /index.php$is_args$args;
    }

    # 设置上传文件大小限制
    client_max_body_size 100M;

    # 处理 PHP 文件
    location ~ \.php$ {
        # 将 PHP 文件的处理请求转发到 PHP-FPM 服务
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;

        # 设置脚本文件路径
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        # 包含 FastCGI 参数文件
        include fastcgi_params;
        include snippets/fastcgi-php.conf;

        # 设置 FastCGI 缓冲区大小
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 128k;

        # 拦截并处理 PHP 错误
        fastcgi_intercept_errors on;
    }

    # 启用 Gzip 压缩
    gzip on;
    gzip_comp_level 6;  # 压缩级别
    gzip_min_length 1000;  # 最小压缩长度
    gzip_proxied any;  # 允许对代理请求进行压缩
    gzip_disable "msie6";  # 禁止对 IE6 浏览器进行压缩

    # 定义需要压缩的 MIME 类型
    gzip_types
        application/atom+xml
        application/geo+json
        application/javascript
        application/x-javascript
        application/json
        application/ld+json
        application/manifest+json
        application/rdf+xml
        application/rss+xml
        application/xhtml+xml
        application/xml
        font/eot
        font/otf
        font/ttf
        image/svg+xml
        text/css
        text/javascript
        text/plain
        text/xml;

    # 处理静态资源（图片、音频、视频等）
    location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
        # 设置缓存过期时间为 90 天
        expires 90d;

        # 关闭访问日志记录
        access_log off;
    }

    # 处理字体和 SVG 文件
    location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
        # 允许跨域请求这些资源
        add_header Access-Control-Allow-Origin "*";

        # 设置缓存过期时间为 90 天
        expires 90d;

        # 关闭访问日志记录
        access_log off;
    }

    # 保护敏感文件（如 .htaccess）
    location ~ /\.ht {
        # 禁止访问这些文件
        deny all;

        # 关闭日志记录
        access_log off;
        log_not_found off;
    }
}</code></pre>



<p>最后在 Nginx Web 服务器中启动 WordPress 站点，并检查配置文件是否正确，最后重启 Nginx 服务</p>



<pre class="wp-block-code"><code>sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx</code></pre>



<p>现在应该可以在 <code>example.com</code> 上看见 WordPress 页面</p>



<p>如果没有域名，则可通过 80 端口访问，在此之前，先将服务器上的 80 端口转发到本地</p>



<p>WordPress 安装界面如下</p>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img fetchpriority="high" decoding="async" width="415" height="584" src="https://gsfall.cn/wp-content/uploads/2025/04/wordpress-install.png" alt="wordpress 安装界面" class="wp-image-78" style="width:424px;height:auto" srcset="https://gsfall.cn/wp-content/uploads/2025/04/wordpress-install.png 415w, https://gsfall.cn/wp-content/uploads/2025/04/wordpress-install-213x300.png 213w" sizes="(max-width: 415px) 100vw, 415px" /></figure>
</div>


<h1 class="wp-block-heading">更简单的方法</h1>



<p>如果在阿里云上购买的云服务器，可以直接在镜像市场中寻找对应的 WordPress 镜像，即开即用。</p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://gsfall.cn/archives/67/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
