详解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;

安装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/"

为什么把Apache的网站根目录放在/usr/local/www/这里?

答:不需要修改权限,不需要折腾。

把这行的注释去掉

#LoadModule php5_module libexec/apache2/libphp5.so

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

#

# 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

#

里面有2个例子,复制一个修改如下

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

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

现在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的官网cn.wordpress.org

上下载安装包,解压并重命名为WordPress01,放到/usr/local/www/WordPress目录下面。

修改WordPress01里面的wp-config-example.conf的内容如下并重命名为wp-config.conf

/**

* 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('DB_NAME', 'WordPress');

/** MySQL数据库用户名 */

define('DB_USER', 'root');

/** MySQL数据库密码 */

define('DB_PASSWORD', '123456');

/** MySQL主机 */

define('DB_HOST', 'localhost');

/** 创建数据表时默认的文字编码 */

define('DB_CHARSET', 'utf8');

/** 数据库整理类型。如不确定请勿更改 */

define('DB_COLLATE', '');

/**#@+

* 身份认证密钥与盐。

*

* 修改为任意独一无二的字串!

* 或者直接访问{@link https://api.wordpress.org/secret-key/1.1/salt/

* WordPress.org密钥生成服务}

* 任何修改都会导致所有cookies失效,所有用户将必须重新登录。

*

* @since 2.6.0

*/

define('AUTH_KEY', 'put your unique phrase here');

define('SECURE_AUTH_KEY', 'put your unique phrase here');

define('LOGGED_IN_KEY', 'put your unique phrase here');

define('NONCE_KEY', 'put your unique phrase here');

define('AUTH_SALT', 'put your unique phrase here');

define('SECURE_AUTH_SALT', 'put your unique phrase here');

define('LOGGED_IN_SALT', 'put your unique phrase here');

define('NONCE_SALT', 'put your unique phrase here');

/**#@-*/

/**

* WordPress数据表前缀。

*

* 如果您有在同一数据库内安装多个WordPress的需求,请为每个WordPress设置

* 不同的数据表前缀。前缀名只能为数字、字母加下划线。

*/

$table_prefix = 'wp_';

/**

* 开发者专用:WordPress调试模式。

*

* 将这个值改为true,WordPress将显示所有用于开发的提示。

* 强烈建议插件开发者在开发环境中启用WP_DEBUG。

*

* 要获取其他能用于调试的信息,请访问Codex。

*

* @link https://codex.wordpress.org/Debugging_in_WordPress

*/

define('WP_DEBUG', true);

/**

* zh_CN本地化设置:启用ICP备案号显示

*

* 可在设置→常规中修改。

* 如需禁用,请移除或注释掉本行。

*/

define('WP_ZH_CN_ICP_NUM', true);

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

/** WordPress目录的绝对路径。 */

if ( !defined('ABSPATH') )

define('ABSPATH', dirname(__FILE__) . '/');

/** 设置WordPress变量和包含文件。 */

require_once(ABSPATH . 'wp-settings.php');

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

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

* 数据库用户名和密码正确。

* 数据库已经启动并能访问。

如果以上无误,请修改wp-config.conf文件中的

/** MySQL主机 */

define('DB_HOST', 'localhost');

改为:

/** MySQL主机 */

define('DB_HOST', '127.0.0.1');

或者是 MySQL主机的IP

接下来正常安装即可。

以上就是一文详解Mac如何安装WordPress的详细内容,更多请关注php中文网其它相关文章!

1、本站所有资源来源于用户上传和网络,版权争议与本站无关,版权归原创者所有,如有侵权请邮件联系我们!
2、分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3、不得使用于非法商业用途,商用请购买正版,不得违反国家法律。否则后果自负!
4、本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5、如有链接无法下载、失效或广告,请联系管理员处理!
6、本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7、不保证所有资源都完整可用,不排除存在加密、BUG、需要授权或者残缺的可能,由于资源的特殊性,下载后一律不予退货!
8、本文来自炫客网搜集整理,如有侵权请联系管理员删除,转载请注明出处:https://www.xuankewang.com/2405.html

联系我们

173-662-005

在线咨询: QQ交谈

邮件:woowuo@126.com

工作时间:周一至周五,10:30-18:30,节假日休息

关注微信
我已知晓并同意