PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

一文详解Mac如何安装WordPress

藏色散人
藏色散人 转载
2021-12-17 14:59:34 5420浏览

下面由wordpress/" target="_blank">wordpress教程栏目给大家介绍mac如何安装wordpress,希望对需要的朋友有所帮助!

Mac 安装WordPress

一、环境要求

  • PHP 5.2.4或更新版本

  • MySQL 5.0或更新版本

  • WebServer(可以选择Apache、nginx等支持PHP的,这里我选择Apache)

二、软件安装

1、安装PHP

Mac OSX 自带PHP,无需安装。

不建议通过brew、源码安装等方式升级PHP7。若需要可在虚拟机中测试。

2、安装MySQL

MySQL下载

访问MySQL的官网 http://www.mysql.com/downloads/ 在页面中会看到“MySQL Community Server”下方有一个“download”按钮,点击该按钮。

进入MySQL的下载界面 http://www.mysql.com/downloads/mysql/,下面罗列的都是在Mac OS上能用的MySQL的版本,选择需要的版本点击下载。

然后会跳转到另外一个界面,这个界面是提示你需不需要注册的,直接选择最下面的“No thanks,just take me to downloads!”,然后这才真正跳转到了下载的界面,这个界面列了很多的供下载的服务器,选择一个服务器进行下载就OK了。

MySQL安装

双击下载下来的文件,一般里面会有几个文件,5.6以上的包里面没有MySQL.prefPane文件,但是会默认安装;5.6以下则需要自己手动安装。  
安装完成后,会在系统的(偏好设置)里面出现MySQL的管理按钮,通过这个按钮可以启动和停止MySQL。

⚠️注意:MySQL安装完成时,会以弹窗的形式显示初始密码,请保存好该密码!!!

MySQL配置

打开命令行  
编辑.bash_profile,并添加如下内容

vi .bash_profile  
tcsh下添加如下内容:
alias mysql /usr/local/mysql/bin/mysql
alias mysqladmin /usr/local/mysql/bin/mysqladmin
bash下添加如下内容:
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin

保存并退出,并启用配置

source .bash_profile

初次使用MySQL时需要修改密码,表现为以下错误

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

具体可以参照官网的例子解决  
http://dev.mysql.com/doc/refman/5.7/en/alter-user.html    
http://dev.mysql.com/doc/refman/5.6/en/alter-user.html

以下为我的解决方案

mysql> SELECT 1;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement

mysql> SET PASSWORD = PASSWORD('new_password');
Query OK, 0 rows affected (0.01 sec)  
  
mysql> quit;

现在就可以使用新密码重新登录数据库

创建数据库
mysql>create database  database-name;

2、安装Apache

Mac OSX 自带Apache,无需安装。

Apache配置

根目录配置文件为/etc/apache2/httpd.conf

sudo vi /etc/apache2/httpd.conf

搜索DocumentRoot(操作按ESC + shift + :+ /DocumentRoot)

修改为如下内容即可
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
DocumentRoot "/usr/local/www/"
<directory>

为什么把Apache的网站根目录放在/usr/local/www/这里?  
答:不需要修改权限,不需要折腾。

把这行的注释去掉
#LoadModule php5_module libexec/apache2/libphp5.so</directory>

多站点配置文件为/etc/apache2/extra/httpd-vhosts.conf

#<virtualhost>
#    ServerAdmin webmaster@dummy-host2.example.com
#    DocumentRoot "/usr/docs/dummy-host2.example.com"
#    ServerName dummy-host2.example.com
#    ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
#    CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
#</virtualhost>

里面有2个例子,复制一个修改如下
<virtualhost>
    DocumentRoot "/usr/local/www/WordPress/WordPress01"
    ServerName WordPress01
    ErrorLog "/private/var/log/apache2/WordPress01-error_log"
    CustomLog "/private/var/log/apache2/WordPress01-access_log" common
</virtualhost><virtualhost>
    DocumentRoot "/usr/local/www/WordPress/WordPress02"
    ServerName WordPress02
    ErrorLog "/private/var/log/apache2/WordPress02-error_log"
    CustomLog "/private/var/log/apache2/WordPress02-access_log" common
</virtualhost>

现在apache多站点配置好了。

修改/etc/hosts文件

sudo vi /etc/hosts
修改如下内容,

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1        localhost
255.255.255.255  broadcasthost
127.0.0.1        WordPress01
127.0.0.1        WordPress02
127.0.0.1        phpMyAdmin
::1              localhost

启动Apache:
sudo apachectl start

现在可以通过在浏览器中输入:localhost/WordPress01 访问 WordPress01 的内容了

重启Apache:
sudo apachectl restart

停止Apache:
sudo apachectl stop

三、安装WordPress

到WordPress的官网  
https://cn.wordpress.org/  
上下载安装包,解压并重命名为WordPress01,放到/usr/local/www/WordPress目录下面。  
修改WordPress01里面的wp-config-example.conf的内容如下并重命名为wp-config.conf

<?php /**
 * WordPress基础配置文件。
 *
 * 这个文件被安装程序用于自动生成wp-config.php配置文件,
 * 您可以不使用网站,您需要手动复制这个文件,
 * 并重命名为“wp-config.php”,然后填入相关信息。
 *
 * 本文件包含以下配置选项:
 *
 * * MySQL设置
 * * 密钥
 * * 数据库表名前缀
 * * ABSPATH
 *
 * @link https://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php
 *
 * @package WordPress
 */

// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define(&#39;DB_NAME&#39;, &#39;WordPress&#39;);

/** MySQL数据库用户名 */
define(&#39;DB_USER&#39;, &#39;root&#39;);

/** MySQL数据库密码 */
define(&#39;DB_PASSWORD&#39;, &#39;123456&#39;);

/** MySQL主机 */
define(&#39;DB_HOST&#39;, &#39;localhost&#39;);

/** 创建数据表时默认的文字编码 */
define(&#39;DB_CHARSET&#39;, &#39;utf8&#39;);

/** 数据库整理类型。如不确定请勿更改 */
define(&#39;DB_COLLATE&#39;, &#39;&#39;);

/**#@+
 * 身份认证密钥与盐。
 *
 * 修改为任意独一无二的字串!
 * 或者直接访问{@link https://api.wordpress.org/secret-key/1.1/salt/
 * WordPress.org密钥生成服务}
 * 任何修改都会导致所有cookies失效,所有用户将必须重新登录。
 *
 * @since 2.6.0
 */
define(&#39;AUTH_KEY&#39;,            &#39;put your unique phrase here&#39;);
define(&#39;SECURE_AUTH_KEY&#39;,     &#39;put your unique phrase here&#39;);
define(&#39;LOGGED_IN_KEY&#39;,       &#39;put your unique phrase here&#39;);
define(&#39;NONCE_KEY&#39;,           &#39;put your unique phrase here&#39;);
define(&#39;AUTH_SALT&#39;,           &#39;put your unique phrase here&#39;);
define(&#39;SECURE_AUTH_SALT&#39;,    &#39;put your unique phrase here&#39;);
define(&#39;LOGGED_IN_SALT&#39;,      &#39;put your unique phrase here&#39;);
define(&#39;NONCE_SALT&#39;,          &#39;put your unique phrase here&#39;);

/**#@-*/

/**
 * WordPress数据表前缀。
 *
 * 如果您有在同一数据库内安装多个WordPress的需求,请为每个WordPress设置
 * 不同的数据表前缀。前缀名只能为数字、字母加下划线。
 */
$table_prefix  = &#39;wp_&#39;;

/**
 * 开发者专用:WordPress调试模式。
 *
 * 将这个值改为true,WordPress将显示所有用于开发的提示。
 * 强烈建议插件开发者在开发环境中启用WP_DEBUG。
 *
 * 要获取其他能用于调试的信息,请访问Codex。
 *
 * @link https://codex.wordpress.org/Debugging_in_WordPress
 */
define(&#39;WP_DEBUG&#39;, true);

/**
 * zh_CN本地化设置:启用ICP备案号显示
 *
 * 可在设置→常规中修改。
 * 如需禁用,请移除或注释掉本行。
 */
define(&#39;WP_ZH_CN_ICP_NUM&#39;, true);

/* 好了!请不要再继续编辑。请保存本文件。使用愉快! */

/** WordPress目录的绝对路径。 */
if ( !defined(&#39;ABSPATH&#39;) )
    define(&#39;ABSPATH&#39;, dirname(__FILE__) . &#39;/&#39;);

/** 设置WordPress变量和包含文件。 */
require_once(ABSPATH . &#39;wp-settings.php&#39;);

现在可以通过在浏览器中输入:localhost/WordPress01 安装WordPress了。

⚠️注意:这里很有可能会在浏览器中看到“链接数据库发生错误”,需要确认以下内容:

* 数据库用户名和密码正确。
* 数据库已经启动并能访问。

如果以上无误,请修改wp-config.conf文件中的  
/** MySQL主机 */
define(&#39;DB_HOST&#39;, &#39;localhost&#39;);

改为:
/** MySQL主机 */
define(&#39;DB_HOST&#39;, &#39;127.0.0.1&#39;);

或者是 MySQL主机的IP

接下来正常安装即可。
声明:本文转载于:segmentfault,如有侵犯,请联系admin@php.cn删除