記錄一下 Macbook 本地折騰 Wordpress 的完整程序
第一步 安裝 MySQL
詳見上一篇筆記 MacOS 安裝 MySQL 與配置環境變數
第二步 新建資料庫、用戶、分配權限
mysql> create database 資料庫名;
//注意SQL命令結尾要帶分號
mysql> SELECT md5('你打算設定的密碼');
// MD5函式接受一個引數,該引數是要加密的字串
// 用 MD5函式的回傳值作為密碼
mysql> CREATE USER '用戶名' IDENTIFIED WITH mysql_native_password BY '密碼';
mysql> GRANT CREATE,SELECT, INSERT, UPDATE,DELETE ON 資料庫名.* TO '用戶名'@'localhost';
// 資料庫名.* 表示資料庫里的所有資料表
注意上面用了 IDENTIFIED WITH mysql_native_password BY
是為了避免報錯“The server requested authentication method unknown to the client”
原因:從Mysql5 到Mysql8啟用了新的加密方法,
詳見 【Linux】php連接mysql8報錯:The server requested authentication method unknown to the client
查看當前用戶(自己)權限:
show grants;
查看其他 MySQL 用戶權限:
show grants for xxx@localhost;
第三步 Apache配置
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/libphp7.so
第四步 安裝 Wordpress
-
從 WordPress的官網下載安裝包
-
解壓到 /usr/local/www/ 檔案夾
-
復制 /wordpress 里的 wp-config-example.conf 并重命名為 wp-config.conf

- 修改 wp-config.conf
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', '資料庫名' );
/** Database username */
define( 'DB_USER', '用戶名' );
/** Database password */
define( 'DB_PASSWORD', '密碼' );
/** Database hostname */
// define( 'DB_HOST', 'localhost' );
define( 'DB_HOST', '127.0.0.1' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
/**
* 開發者專用: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);
第五步 運行
啟動Apache:
sudo apachectl start
重啟Apache:
sudo apachectl restart
停止Apache:
sudo apachectl stop
瀏覽器中輸入:http://localhost/wordpress/wp-admin/ 即可訪問
至此,可以愉快地玩耍了??

參考文章:
Mac 安裝WordPress
怎樣在 macOS 本地環境安裝 WordPress,除錯排版樣式
PHP錯誤:SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
Mac 本地安裝 wordpress
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/519223.html
標籤:其他
