search
HomeCMS TutorialWordPressOne article explains how to install WordPress on Mac

The following tutorial column of WordPress will introduce to you how to install WordPress on Mac. I hope it will be helpful to friends in need!

Mac installation WordPress

1. Environment requirements

  • PHP 5.2.4 or newer version

  • MySQL 5.0 or newer version

  • WebServer (you can choose Apache, nginx, etc. that support PHP, here I choose Apache)

2. Software installation

1. Install PHP

Mac OSX comes with PHP, no need to install it.

It is not recommended to upgrade PHP7 through brew, source code installation, etc. Test in a virtual machine if necessary.

2. Install MySQL

MySQL download

Visit MySQL’s official website http://www.mysql.com/downloads/ You will see “MySQL Community Server” on the page "There is a "download" button below, click the button.

Enter the MySQL download interface http://www.mysql.com/downloads/mysql/. Listed below are the versions of MySQL that can be used on Mac OS. Select the required version and click to download.

Then it will jump to another interface. This interface prompts you whether you need to register or not. Just select "No thanks, just take me to downloads!" at the bottom, and then this will actually jump to it. Download interface, this interface lists many servers for downloading, just select a server to download.

MySQL installation

Double-click the downloaded file. Generally, there will be several files in it. There is no MySQL.prefPane file in the package above 5.6, but it will be installed by default; below 5.6, you need to manually Install.
After the installation is completed, the MySQL management button will appear in the system (Preferences), through which you can start and stop MySQL.

⚠️Note: When the MySQL installation is completed, the initial password will be displayed in a pop-up window, please save the password! ! !

MySQL configuration

Open the command line
Edit .bash_profile and add the following content

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

Save and exit, and enable the configuration

source .bash_profile

First time When using MySQL, you need to change the password, which is manifested as the following error

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

Please refer to the official website for examples
http://dev.mysql.com/doc/refman/5.7/en/alter-user. html
http://dev.mysql.com/doc/refman/5.6/en/alter-user.html

The following is my solution

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;

You can use it now Log in to the database again with a new password

Create database
mysql>create database  database-name;

2. Install Apache

Mac OSX comes with Apache, no need to install it.

Apache configuration

The root directory configuration file is/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>

The multi-site configuration file is/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多站点配置好了。

Modify the /etc/hosts file

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

3. Install WordPress

Go to the WordPress official website
https://cn.wordpress.org/
Download the installation package, unzip it and rename it to WordPress01, and put it under the /usr/local/www/WordPress directory.
Modify the content of wp-config-example.conf in WordPress01 as follows and rename it to 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

接下来正常安装即可。

The above is the detailed content of One article explains how to install WordPress on Mac. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:segmentfault. If there is any infringement, please contact admin@php.cn delete
Can I learn WordPress in 3 days?Can I learn WordPress in 3 days?Apr 09, 2025 am 12:16 AM

Can learn WordPress within three days. 1. Master basic knowledge, such as themes, plug-ins, etc. 2. Understand the core functions, including installation and working principles. 3. Learn basic and advanced usage through examples. 4. Understand debugging techniques and performance optimization suggestions.

Is WordPress a CMS?Is WordPress a CMS?Apr 08, 2025 am 12:02 AM

WordPress is a Content Management System (CMS). It provides content management, user management, themes and plug-in capabilities to support the creation and management of website content. Its working principle includes database management, template systems and plug-in architecture, suitable for a variety of needs from blogs to corporate websites.

What is the WordPress good for?What is the WordPress good for?Apr 07, 2025 am 12:06 AM

WordPressisgoodforvirtuallyanywebprojectduetoitsversatilityasaCMS.Itexcelsin:1)user-friendliness,allowingeasywebsitesetup;2)flexibilityandcustomizationwithnumerousthemesandplugins;3)SEOoptimization;and4)strongcommunitysupport,thoughusersmustmanageper

Should I use Wix or WordPress?Should I use Wix or WordPress?Apr 06, 2025 am 12:11 AM

Wix is ​​suitable for users who have no programming experience, and WordPress is suitable for users who want more control and expansion capabilities. 1) Wix provides drag-and-drop editors and rich templates, making it easy to quickly build a website. 2) As an open source CMS, WordPress has a huge community and plug-in ecosystem, supporting in-depth customization and expansion.

How much does WordPress cost?How much does WordPress cost?Apr 05, 2025 am 12:13 AM

WordPress itself is free, but it costs extra to use: 1. WordPress.com offers a package ranging from free to paid, with prices ranging from a few dollars per month to dozens of dollars; 2. WordPress.org requires purchasing a domain name (10-20 US dollars per year) and hosting services (5-50 US dollars per month); 3. Most plug-ins and themes are free, and the paid price ranges from tens to hundreds of dollars; by choosing the right hosting service, using plug-ins and themes reasonably, and regularly maintaining and optimizing, the cost of WordPress can be effectively controlled and optimized.

Is WordPress still free?Is WordPress still free?Apr 04, 2025 am 12:06 AM

The core version of WordPress is free, but other fees may be incurred during use. 1. Domain names and hosting services require payment. 2. Advanced themes and plug-ins may be charged. 3. Professional services and advanced features may be charged.

Is WordPress easy for beginners?Is WordPress easy for beginners?Apr 03, 2025 am 12:02 AM

WordPress is easy for beginners to get started. 1. After logging into the background, the user interface is intuitive and the simple dashboard provides all the necessary function links. 2. Basic operations include creating and editing content. The WYSIWYG editor simplifies content creation. 3. Beginners can expand website functions through plug-ins and themes, and the learning curve exists but can be mastered through practice.

Why would anyone use WordPress?Why would anyone use WordPress?Apr 02, 2025 pm 02:57 PM

People choose to use WordPress because of its power and flexibility. 1) WordPress is an open source CMS with strong ease of use and scalability, suitable for various website needs. 2) It has rich themes and plugins, a huge ecosystem and strong community support. 3) The working principle of WordPress is based on themes, plug-ins and core functions, and uses PHP and MySQL to process data, and supports performance optimization.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)