=Start=
缘由:
住的地方网络太差了,经常是文章编辑到一半、命令操作到一半的时候,网络断了——比如昨晚在测试「在Linux系统中禁用用户帐号」的时候,在把一个常用用户临时禁用了之后,断网了,而我本地又没有root的私钥,看来是得重装系统了!WTF!!!没办法,为了减少网络不好对自己的影响,所以就考虑本地搭建一个WordPress环境。
正文:
Mac上自带了Apache和PHP,所以只需要安装MySQL和WordPress,然后根据实际情况修改配置文件(httpd.conf/php.ini/my.cnf)就行,大体步骤如下:
1.启动Apache
apachectl -v apachectl -h apachectl status sudo apachectl start
Mac上Apache默认的配置文件在:
/etc/apache2/httpd.conf
Mac上Apache的默认Web目录为(在Apache的配置文件中由 DocumentRoot 指令设定,可以根据自己的情况进行修改):
/Library/WebServer/Documents
2.开启Apache对PHP文件的解析
在终端中输入`sudo vim /etc/apache2/httpd.conf`,修改Apache的配置文件,查找 `LoadModule php5_module libexec/apache2/libphp5.so` 这一行,把前面的#号去掉,保存并退出。重启Apache服务 `sudo apachectl restart` 。
3.安装并启动MySQL
$ brew search mysql $ brew install mysql $ mysql.server status $ mysql.server start #手工启动MySQL 或 $ brew services start mysql #将MySQL设置成开机启动
4.安装WordPress
1.下载WordPress $ wget http://wordpress.org/latest.tar.gz -O wordpress-4.6.1.tar.gz 或 $ wget https://cn.wordpress.org/wordpress-4.5.3-zh_CN.tar.gz 2.为WordPress创建数据库 CREATE DATABASE IF NOT EXISTS mac_wp; CREATE USER 'user'@'localhost' IDENTIFIED BY 'pa33word'; GRANT ALL PRIVILEGES ON mac_wp.* TO 'user'@'localhost'; FLUSH PRIVILEGES; 3.将WordPress解压至Web目录并修改相关权限 $ sudo tar zxf wordpress-4.6.1.tar.gz -C /Library/WebServer/Documents/ $ sudo mv /Library/WebServer/Documents/{wordpress,notes} $ sudo chown -R www:www /Library/WebServer/Documents/notes 4.为WordPress添加VirtualHost设置 $ sudo vim /etc/apache2/httpd.conf -#Include /private/etc/apache2/extra/httpd-vhosts.conf +Include /private/etc/apache2/extra/httpd-vhosts.conf $ sudo vim /private/etc/apache2/extra/httpd-vhosts.conf <VirtualHost *:80> DocumentRoot "/Library/WebServer/Documents/notes" ServerName localhost ErrorLog "/private/var/log/apache2/notes-error_log" CustomLog "/private/var/log/apache2/notes-access_log" common </VirtualHost> 5.通过浏览器按照提示进行安装 http://127.0.0.1:80/ 注意在MySQL那里「127.0.0.1」和「localhost」是存在区别的,建议用「127.0.0.1」避免错误。
- 在Mac下配置wordpress开发环境:Apache+php+MySql+Wordpress
- Mac OS X Mavericks 配置 Apache+Mysql+PHP 详细教程
- Mac上的Apache不解析PHP
http://stackoverflow.com/questions/11276571/enabling-php-not-working-after-enabling-on-osx-lion
http://stackoverflow.com/questions/6790568/how-do-you-get-php-working-on-mac-os-x - Installing Apache, PHP, and MySQL on Mac OS X Yosemite
- 在Mac上配置Apache的 VirtualHosts
更多参考链接:
php.ini的安全配置
- http://stackoverflow.com/questions/17944698/best-php-ini-settings-to-improve-security
- http://www.cyberciti.biz/tips/php-security-best-practices-tutorial.html
- https://www.minitek.gr/blog/the-6-most-important-security-settings-in-php-ini
- https://www.owasp.org/index.php/PHP_Configuration_Cheat_Sheet
- http://security.stackexchange.com/questions/7083/php-ini-security-setting-after-attack
- 一个php.ini安全性设置扫描工具
register_globals = off allow_url_fopen = off magic_quotes_gpc expose_php = off safe_mode = off session.use_trans_sid = off
PHP MySQL 连接数据库
- http://www.w3school.com.cn/php/php_mysql_connect.asp
- http://www.runoob.com/php/php-mysql-connect.html
<?php // $servername = "localhost"; $servername = "127.0.0.1"; $username = "user"; $password = "pa33word"; // 创建连接 $conn = mysqli_connect($servername, $username, $password); // 检测连接 if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } echo "连接成功"; mysqli_close($con); ?>
为网站添加icon
苹果的icon下载『apple icon download』
https://www.iconfinder.com/search/?q=apple
=END=
《 “在Mac本地搭建WordPress环境” 》 有 7 条评论
WordPress 使用 mod_rewrite 来实现「固定链接」的功能(Apache)
https://codex.wordpress.org/zh-cn:%E6%9C%AF%E8%AF%AD%E8%A1%A8#mod_rewrite
https://codex.wordpress.org/Using_Permalinks
如何将大文件导入WordPress
`
$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
$ php wp-cli.phar –info
$ chmod +x wp-cli.phar
$ sudo mv wp-cli.phar /usr/local/bin/wp
$ wp core version –path=/path/to/wordpress
$ wp theme list –path=/path/to/wordpress
$ wp import aspire.wordpress.2017-01-12.xml –authors=create –path=/path/to/wordpress
`
http://wordpress.stackexchange.com/a/242534
http://wp-cli.org/commands/import/
https://github.com/wp-cli/wp-cli
当WordPress博客所在主机的IP发生变化时,该如何处理?
http://stackoverflow.com/questions/535534/wordpress-host-ip-changed
https://codex.wordpress.org/Changing_The_Site_URL
`
方法一:直接修改WordPress数据库表的对应字段
use wordpress;
desc wp_options;
select count(*) from wp_options;
select * from wp_options where option_name IN(‘siteurl’,’home’);
update wp_options set option_value=’https://ixyzero.com/blog’ where option_name = ‘siteurl’;
update wp_options set option_value=’https://ixyzero.com/blog’ where option_name = ‘home’;
方法二:修改 wp-config.php 文件内容以间接达到目标
define(‘WP_HOME’, ‘https://ixyzero.com/blog’);
define(‘WP_SITEURL’, ‘https://ixyzero.com/blog’);
方法三:修改所使用主题中的 functions.php 文件内容
update_option(‘siteurl’, ‘https://ixyzero.com/blog/’);
update_option(‘home’, ‘https://ixyzero.com/blog/’);
`
macOS 10.14 Mojave Apache Setup: Multiple PHP Versions
https://getgrav.org/blog/macos-mojave-apache-multiple-php-versions
macOS 10.14 Mojave Apache Setup: MySQL, APC & More…
https://getgrav.org/blog/macos-mojave-apache-mysql-vhost-apc
`
$ httpd -V
$ sudo vim /path/to/httpd.conf
…
DocumentRoot
…
ErrorLog
`
WordPress Apache伪静态规则
https://www.wpyou.com/wordpress-apache-rewrite.html
`
1. 开启 Apache 的 url rewrite功能
grep –color “LoadModule rewrite_module” /etc/apache2/httpd.conf
sudo vim /etc/apache2/httpd.conf
sudo vim /private/etc/apache2/extra/httpd-vhosts.conf
AllowOverride All
2. 在WordPress站点根目录创建 .htaccess 文件
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
3. 在WordPress的 后台【 设置 – 固定链接 】里自定义静态化结构。
`
wordpress二次开发主题如何不被更新[wordpress子主题教程详解]
https://www.admin122.com/2124.html
「网站」当WordPress主题需要升级时,怎么保存之前主题所更改的设置
https://zhuanlan.zhihu.com/p/84528098
WordPress主题二次开发-使用子主题的详细说明
https://www.themepark.com.cn/wordpresszteckf-syzztdxa.html
WordPress主题制作 之 添加自动检测更新和一键升级功能
https://www.wpdaxue.com/automatic-updates-for-commercial-themes.html
为WordPress主题添加“自动更新”功能
https://zmingcx.com/wordpress-theme-automatic-update-feature.html
修改wordpress中twentytwelve主题显示文章摘要
http://www.zzbiji.com/2071.html
`
最直白的说明就是,找到主题中的 content.php 文件中的下面这一部分:
is_search()
修改成下面的内容(增加几个判断条件):
is_search() || is_category() || is_archive() || is_home()
`