一文詳解Mac如何安裝WordPress

下面由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  接下來正常安裝即可。

? 版權聲明
THE END
喜歡就支持一下吧
點贊10 分享