搜索
首页CMS教程WordPress一文详解Mac如何安装WordPress

一文详解Mac如何安装WordPress

Dec 17, 2021 pm 02:59 PM
macwordpress

下面由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 "/usr/local/www/">

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

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

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

#<VirtualHost *:80>
#    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 *:80>
    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 *:80>
    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('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中文网其他相关文章!

声明
本文转载于:segmentfault。如有侵权,请联系admin@php.cn删除
您可以使用WordPress CMS构建哪种网站?您可以使用WordPress CMS构建哪种网站?May 04, 2025 am 12:06 AM

WordPressCanbuildVariousTypesofwebsites:1)个人博客,EasyTosetUpWithTheMesandPlugins.2)BusinessWebsites,使用drag-and-dropbuilders.3)e-commercePlatforms,forwoocommerceforsemcommerceforseameamseamelesssites.4)communitySites.4)conduction.4)使用bbudicatipration

将WordPress用作CMS的优缺点是什么?将WordPress用作CMS的优缺点是什么?May 03, 2025 am 12:09 AM

WordPressisapowerfulCMSwithsignificantadvantagesandchallenges.1)It'suser-friendlyandcustomizable,idealforbeginners.2)Itsflexibilitycanleadtositebloatandsecurityissuesifnotmanagedproperly.3)Regularupdatesandperformanceoptimizationsarenecessarytomainta

WordPress与其他流行的CMS平台相比如何?WordPress与其他流行的CMS平台相比如何?May 02, 2025 am 12:18 AM

WordPressExcccelineaseeandaDaptability,MakeitiTidealForBeginnersandsMallTomedium-SizedBusinesses.1)siseofuse:wordpressisuser-Frylyly.2)安全:drupalleadswithstrongsecurityfeatures.3)性能:performance:performance formation:ghandoffersefersefersefersefersefersefersefersexcellentperformanceeduetonodeutonode.jsorscor.jssor.jjsy.jjsy.jjsy.4)4)

您可以使用WordPress构建会员网站吗?您可以使用WordPress构建会员网站吗?May 01, 2025 am 12:08 AM

Yes,youcanuseWordPresstobuildamembershipsite.Here'show:1)UsepluginslikeMemberPress,PaidMemberSubscriptions,orWooCommerceforusermanagement,contentaccesscontrol,andpaymenthandling.2)Ensurecontentprotectionwithupdatedpluginsandadditionalsecuritymeasures

WordPress是否需要编码知识作为CMS?WordPress是否需要编码知识作为CMS?Apr 30, 2025 am 12:03 AM

你不需要编程知识就能使用WordPress,但掌握编程可以提升体验。1)使用CSS和HTML可以调整主题样式。2)PHP知识能编辑主题文件,添加功能。3)自定义插件和元标签可优化SEO。4)注意备份和使用子主题以防更新问题。

使用WordPress时的安全考虑是什么?使用WordPress时的安全考虑是什么?Apr 29, 2025 am 12:01 AM

TosecureaWordPresssite,followthesesteps:1)RegularlyupdateWordPresscore,themes,andpluginstopatchvulnerabilities.2)Usestrong,uniquepasswordsandenabletwo-factorauthentication.3)OptformanagedWordPresshostingorsecuresharedhostingwithawebapplicationfirewal

WordPress与其他网站构建者相比如何?WordPress与其他网站构建者相比如何?Apr 28, 2025 am 12:04 AM

WordPressExcelSoverotherWeberteBuilderSduetoItsflexible,可伸缩性,andopen-sourcenature.1)它'saversatilecmswithExtEnsextEnsiveCustomizedOptionsVIATHEMESANDPLUGINS.2)它的alllearbutoffersbutoffersbutoffersbutoffersbutofferspopelyContrololonCemastered.3)

5个WordPress插件,供开发人员在2025年使用5个WordPress插件,供开发人员在2025年使用Apr 27, 2025 am 08:25 AM

2025年网站开发的七个必备WordPress插件 在2025年建立顶级WordPress网站需要速度,响应能力和可扩展性。 实现这种有效的实现通常取决于战略插件的选择。 这篇文章Highlig

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能