Home  >  Article  >  CMS Tutorial  >  One article explains how to install WordPress on Mac

One article explains how to install WordPress on Mac

藏色散人
藏色散人forward
2021-12-17 14:59:345659browse

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

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

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

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多站点配置好了。

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

接下来正常安装即可。

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.com. If there is any infringement, please contact admin@php.cn delete