Table of Contents
1. Environment requirements
2. Software installation
1. Install PHP
2. Install MySQL
MySQL download
MySQL installation
MySQL configuration
Create database
2. Install Apache
Apache configuration
3. Install WordPress
Home CMS Tutorial WordPress One article explains how to install WordPress on Mac

One article explains how to install WordPress on Mac

Dec 17, 2021 pm 02:59 PM
mac wordpress

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
Copy after login

Save and exit, and enable the configuration

source .bash_profile
Copy after login

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.
Copy after login

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;
Copy after login

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

Create database
mysql>create database  database-name;
Copy after login

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

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

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

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

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
Copy after login

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('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

接下来正常安装即可。
Copy after login

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 of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

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 Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP vs. Flutter: The best choice for mobile development PHP vs. Flutter: The best choice for mobile development May 06, 2024 pm 10:45 PM

PHP and Flutter are popular technologies for mobile development. Flutter excels in cross-platform capabilities, performance and user interface, and is suitable for applications that require high performance, cross-platform and customized UI. PHP is suitable for server-side applications with lower performance and not cross-platform.

How to change page width in wordpress How to change page width in wordpress Apr 16, 2024 am 01:03 AM

You can easily modify your WordPress page width by editing your style.css file: Edit your style.css file and add .site-content { max-width: [your preferred width]; }. Edit [your preferred width] to set the page width. Save changes and clear cache (optional).

In which folder are wordpress articles located? In which folder are wordpress articles located? Apr 16, 2024 am 10:29 AM

WordPress posts are stored in the /wp-content/uploads folder. This folder uses subfolders to categorize different types of uploads, including articles organized by year, month, and article ID. Article files are stored in plain text format (.txt), and the filename usually includes its ID and title.

Where is the wordpress template file? Where is the wordpress template file? Apr 16, 2024 am 11:00 AM

WordPress template files are located in the /wp-content/themes/[theme name]/ directory. They are used to determine the appearance and functionality of the website, including header (header.php), footer (footer.php), main template (index.php), single article (single.php), page (page.php), Archive (archive.php), category (category.php), tag (tag.php), search (search.php) and 404 error page (404.php). By editing and modifying these files, you can customize the appearance of your WordPress website

How to search for authors in WordPress How to search for authors in WordPress Apr 16, 2024 am 01:18 AM

Search for authors in WordPress: 1. Once logged in to your admin panel, navigate to Posts or Pages, enter the author name using the search bar, and select Author in Filters. 2. Other tips: Use wildcards to broaden your search, use operators to combine criteria, or enter author IDs to search for articles.

MacBook Pro, iMac to get the M4 upgrade later this year followed by MacBook Air in spring of 2025, claims reliable tipster MacBook Pro, iMac to get the M4 upgrade later this year followed by MacBook Air in spring of 2025, claims reliable tipster Jun 25, 2024 am 06:35 AM

Ever since the Apple M4-powered OLED iPad Prolineuparrived, Apple Silicon aficionados have been eagerly awaiting the arrival of the M4 SoC on the Mac lineup. The M4 was undeniably a major leap forward in both compute and graphics performance - leapfr

Apple iPhone 16 is no longer pre-installed with Apple Intelligence Apple iPhone 16 is no longer pre-installed with Apple Intelligence Jul 30, 2024 pm 01:18 PM

According to industry insider Mark Gurman, Apple’s Apple Intelligence will be postponed to October. In other words, it will be pushed first on iOS18.1. Apple iPhone 16 is expected to be released in September, so Apple Intelligence will not be pre-installed. 1. Apple Intelligence Apple Intelligence is a personal intelligence system that uses a powerful generative model to provide new functions for iPhone, iPad and Mac to assist users in communicating, working and expressing. 2. Natural language understanding The large model embedded in Apple Intelligence has a deep understanding of the meaning of language.

Which version of wordpress is stable? Which version of wordpress is stable? Apr 16, 2024 am 10:54 AM

The most stable WordPress version is the latest version because it contains the latest security patches, performance enhancements, and introduces new features and improvements. In order to update to the latest version, log into your WordPress dashboard, go to the Updates page and click Update Now.

See all articles