登录
首页 >  数据库 >  MySQL

Mac 安装WordPress

来源:SegmentFault

时间:2023-01-14 08:56:42 127浏览 收藏

来到golang学习网的大家,相信都是编程学习爱好者,希望在这里学习数据库相关编程知识。下面本篇文章就来带大家聊聊《Mac 安装WordPress》,介绍一下MySQL、MacOS、html5,希望对大家的知识积累有所帮助,助力实战开发!

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,并添加如下内容

1
2
3
4
5
6
7
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

保存并退出,并启用配置

1
source .bash_profile

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

1
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

以下为我的解决方案

1
2
3
4
5
6
7
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;

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

创建数据库

1
mysql>create database  database-name;

2、安装Apache

Mac OSX 自带Apache,无需安装。

Apache配置

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#<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文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!--?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('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
 
接下来正常安装即可。
</pre-->

理论要掌握,实操不能落!以上关于《Mac 安装WordPress》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>
评论列表