0x00.启用缓存功能无效
即:设置→WP-Super Cache→启用缓存功能无效无法更新。
进入控制台,wp-config.php 添加:
define('WP_CACHE',true);
0x01.无法写入缓存文件…
即提示:Could not rename temporary file to configuration file….
进入控制台:
su root chmod 755 /www/wwwroot/async.website/wp-content
即:设置→WP-Super Cache→启用缓存功能无效无法更新。
进入控制台,wp-config.php 添加:
define('WP_CACHE',true);
即提示:Could not rename temporary file to configuration file….
进入控制台:
su root chmod 755 /www/wwwroot/async.website/wp-content
无需设置,安装完即可食用
将下列代码复制至主题→编辑→functions.php
add_action( 'load-themes.php', 'no_category_base_refresh_rules'); add_action('created_category', 'no_category_base_refresh_rules'); add_action('edited_category', 'no_category_base_refresh_rules'); add_action('delete_category', 'no_category_base_refresh_rules'); function no_category_base_refresh_rules() { global $wp_rewrite; $wp_rewrite -> flush_rules(); } // register_deactivation_hook(__FILE__, 'no_category_base_deactivate'); // function no_category_base_deactivate() { // remove_filter('category_rewrite_rules', 'no_category_base_rewrite_rules'); // // We don't want to insert our custom rules again // no_category_base_refresh_rules(); // } // Remove category base add_action('init', 'no_category_base_permastruct'); function no_category_base_permastruct() { global $wp_rewrite, $wp_version; if (version_compare($wp_version, '3.4', '<')) { // For pre-3.4 support $wp_rewrite -> extra_permastructs['category'][0] = '%category%'; } else { $wp_rewrite -> extra_permastructs['category']['struct'] = '%category%'; } } // Add our custom category rewrite rules add_filter('category_rewrite_rules', 'no_category_base_rewrite_rules'); function no_category_base_rewrite_rules($category_rewrite) { //var_dump($category_rewrite); // For Debugging $category_rewrite = array(); $categories = get_categories(array('hide_empty' => false)); foreach ($categories as $category) { $category_nicename = $category -> slug; if ($category -> parent == $category -> cat_ID)// recursive recursion $category -> parent = 0; elseif ($category -> parent != 0) $category_nicename = get_category_parents($category -> parent, false, '/', true) . $category_nicename; $category_rewrite['(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]'; $category_rewrite['(' . $category_nicename . ')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]'; $category_rewrite['(' . $category_nicename . ')/?$'] = 'index.php?category_name=$matches[1]'; } // Redirect support from Old Category Base global $wp_rewrite; $old_category_base = get_option('category_base') ? get_option('category_base') : 'category'; $old_category_base = trim($old_category_base, '/'); $category_rewrite[$old_category_base . '/(.*)$'] = 'index.php?category_redirect=$matches[1]'; //var_dump($category_rewrite); // For Debugging return $category_rewrite; } // Add 'category_redirect' query variable add_filter('query_vars', 'no_category_base_query_vars'); function no_category_base_query_vars($public_query_vars) { $public_query_vars[] = 'category_redirect'; return $public_query_vars; } // Redirect if 'category_redirect' is set add_filter('request', 'no_category_base_request'); function no_category_base_request($query_vars) { //print_r($query_vars); // For Debugging if (isset($query_vars['category_redirect'])) { $catlink = trailingslashit(get_option('home')) . user_trailingslashit($query_vars['category_redirect'], 'category'); status_header(301); header("Location: $catlink"); exit(); } return $query_vars; }
//获取post_views function get_post_views ($post_id) { $count_key = 'views'; $count = get_post_meta($post_id, $count_key, true); if ($count == '') { delete_post_meta($post_id, $count_key); add_post_meta($post_id, $count_key, '0'); $count = '0'; } echo number_format_i18n($count); } //设置post_views function set_post_views () { global $post; $post_id = $post -> ID; $count_key = 'views'; $count = get_post_meta($post_id, $count_key, true); if (is_single() || is_page()) { if ($count == '') { delete_post_meta($post_id, $count_key); add_post_meta($post_id, $count_key, '0'); } else { update_post_meta($post_id, $count_key, $count + 1); } } } add_action('get_header', 'set_post_views');
echo get_post_views(get_the_ID());
即可输出访问次数。
1核 1GB 1M 的50G空间的基础服务器完全可以承载小型个人博客的流量。
设置服务器管理员密码,并向服务器安装Unbuntu镜像,登陆。
sudo apt-get install apache2 -y
安装完成后可以通过访问服务器地址查看是否出现Apache2 Ubuntu Default Page并显示It works.
sudo apt-get install php7.0 -y
sudo apt-get install libapache2-mod-php7.0
sudo apt-get install mysql-server -y
期间会需要输入两次密码以设置密码。
sudo apt-get install php7.0-mysql
a.安装 phpmyadmin,安装过程中,遇到lighthttpd/apache2时请选择 apache2 ,再输入root密码 和数据库密码。
sudo apt-get install phpmyadmin -y
b.建立 /var/www/html 下的软连接:
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
c.重启apache2和MySQL 服务(以后对apache2进行更改后也要重启以生效)
sudo service mysql restart sudo systemctl restart apache2.service
wget https://cn.wordpress.org/wordpress-4.7.4-zh_CN.zip
下载完成后解压缩
sudo unzip wordpress-4.7.4-zh_CN.zip
a.进入 mysql,输入MySQL密码:
mysql -u root -p
b.为 wordpress 创建一个叫 wordpress 的数据库
CREATE DATABASE wordpress;
c.数据库设置一个用户 wordpressuser,并设置密码:password123
CREATE USER wordpressuser; SET PASSWORD FOR wordpressuser= PASSWORD("password123");
d.给用户数据库的访问权限并生效配置
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser IDENTIFIED BY"password123"; FLUSH PRIVILEGES;
e.退出Mysql
exit;
a.把 wordpress 文件夹里的文件都复制到 /var/www/html/ 文件夹
sudo mv wordpress/* /var/www/html/
b.修改权限
sudo chmod -R 777 /var/www/html/
c.将apache指定到index.html
sudo mv /var/www/html/index.html /var/www/html/index~.html
d.重启apache
sudo systemctl restart apache2.service
输入服务器地址访问。
以腾讯云举例
选购好域名后,登陆云服务器控制台,选择要添加解析的域名,点击添加解析→新手快速添加→网站解析→输入要云服务器IP→确定
编辑php.ini文件.(可能在 /etc/php.ini 或者 /etc/php.d/cgi/php.ini 或者 /usr/local/etc/php.ini)
我的php.ini在etc/php/7.0/apache2下
vi /etc/php/7.0/apache2/php.ini
upload_max_filesize = 64M memory_limit = 64M post_max_size = 64M
sudo /etc/init.d/apache2 restart
mkdir fonts
cp xxx.ttf /www/wwwroot/async.website/wp-content/themes/xxx/fonts
chmod -R 777 fonts
@font-face { font-family: xxx; src: url(https://xxxx.xxx/wp-content/themes/xxx/fonts/xxx.ttf); /*修改url为自己的字体路径*/ font-weight: normal; }
.site-description { display: inline-block; margin-top: 15px; margin-bottom: 0; font-size: 50px; font-family:Debby; line-height: 1.1; }