权限重置
Link1 Link2 Link3 Link4
# Change permissions for WordPress Folders 755: find /your_wordpress_folder/ -type d -exec chmod 755 {} \; # Change permissions for WordPress Files 644: find /your_wordpress_folder/ -type f -exec chmod 644 {} \; # Change permissions for wp-config.php chmod 600 wp-config.php # set the ownership chown -R nginx:nginx /your_wordpress_folder/ systemctl restart nginx systemctl restart php-fpm setenforce 0 # all done setenforce 1
文章顶部图片规格
1200×300 72dpi 平滑:8 像素 应用画布边界的效果
// Display the total number of published posts using the shortcode 69 function customprefix_total_number_published_posts($atts) { return wp_count_posts('post')->publish; } add_shortcode('published-posts-count', 'customprefix_total_number_published_posts');
- Configure PHP
Open /etc/php.ini file
vim /etc/php.ini
Add the following contents to the file.
file_uploads = On allow_url_fopen = On ; Maximum execution time of each script, in seconds max_execution_time = 300 ; Maximum amount of memory a script may consume (128MB) memory_limit = 256M ; Maximum allowed size for uploaded files. upload_max_filesize = 64M ; Maximum size of POST data that PHP will accept. post_max_size = 64M ; How many GET/POST/COOKIE input variables may be accepted max_input_vars = 15000 date.timezone = Asia/Shanghai
Open /etc/nginx/nginx.conf
Add the following contents to the file.
# set client body size to 64M # # 在WP后台更新主题时,提示:<!-- a padding to disable MSIE and Chrome friendly error page --> # 这是因为上传文件的大小超出了 Nginx 允许的最大值,在 http{} 段中增大nginx上传文件大小限制 # 这个大小client_max_body_size要和php.ini中的post_max_size和upload_max_filesize最大值一致或者稍大,这样就不会因为提交数据大小不一致出现的错误。 client_max_body_size 64M;
- Configure Database For WordPress
Step 1: Login to the database using the password you set for root.
mysql -u root -p
Step 2: Create a database named “wordpress-db”
CREATE DATABASE wordpress-db;
Step 3: Create a new databases user named “wordpress-admin” and set a custom password. This user will be used in the WordPress configuration.
CREATE USER 'wordpress-admin'@'localhost' IDENTIFIED BY 'your_password_here';
Step 4: Grant all privileged on wordpress-db for wordpress-admin user. Replace the password you set for wordpress-admin.
GRANT ALL ON wordpress-db.* TO 'wordpress-admin'@'localhost' IDENTIFIED BY 'your-password-here' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
Step 5: Flush all privileges and exit the db shell.
FLUSH PRIVILEGES; \q
Or Change Password
SET PASSWORD FOR 'tom'@'localhost' = PASSWORD('abedefg123');
- Configure WordPress
Open wp-config.php file And add the following contents to the file.
/** Sets up 'direct' method for wordpress, auto update without ftp */ define( 'FS_METHOD', 'direct'); /** Unblock WP's memory limit and change php.ini's memory_limit field to the same memory size */ define('WP_MEMORY_LIMIT', '256M');
Change the ownership of the wordpress folder to nginx
chown -R nginx:nginx /usr/share/nginx/html/wordpress/
- Symptoms
phpMyAdmin – Error
Error during session start; please check your PHP and/or webserver log file and configure your PHP installation properly. Also ensure that cookies are enabled in your browser. session_start(): open(SESSION_FILE, O_RDWR) failed: Permission denied (13) session_start(): Failed to read session data: files (path: /var/lib/php/session)
- Cause
The permissions for PHP session directory are incorrect or directory does not exist.
- Resolution
1.on RHEL and CentOS systems, if session.save_path is not set, session files will be saved in /var/lib/php/session.
2.Connect to the server via SSH and make sure the directory exists and have proper permissions (1733). If path is /var/lib/php/session:
# stat /var/lib/php/session | grep Access Access: (1733/drwx-wx-wt) Uid: ( 0/ root) Gid: ( 0/ root)
If directory does not exists create it and set valid permissions:
mkdir -p /var/lib/php/session && chmod 1733 /var/lib/php/session
If directory exists but permissions are different, set the correct ones:
chmod 1733 /var/lib/php/session
Note: If the issue persists, disable SELinux:
setenforce 0
https://guide.the7.io/user-guide/the7-dashboard/icon-manager/
icon: https://icomoon.io
配置 nginx
- 在WP后台更新主题或安装插件时,提示:
<!-- a padding to disable MSIE and Chrome friendly error page -->
或提示:
413 Request Entity Too Large errors
或者在安装插件时,提示:
Update Failed: <!DOCTYPE html> Error body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; }
这都是因为上传文件的大小超出了 nginx 允许的最大值,在 http{} 字段中增大 nginx 上传文件大小限制,这个 client_max_body_size 值的大小要和 php.ini 中的 post_max_size 和 upload_max_filesize 最大值一致或者稍大,这样就不会因为提交数据大小不一致出现的错误。在 /etc/nginx/nginx.conf 的 http 字段追加如下参数解决如上问题:
http { ... client_max_body_size 64m; ... }
- 在查看 nginx 的状态:systemctl status nginx,提示:
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:443, ignored nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:80, ignored
那是因为在 /etc/nginx/conf.d 的网站配置中,有一个以上的网站指向了同一个目录,保留一个,移走、删除或找到指向路径的网站指向其它路径即可。
删除WordPress中的注销确认
将如下代码追加到主题中Functions.php文件
/** * Bypass logout confirmation on nonce verification failure */ function logout_without_confirmation($action, $result){ if(!$result && ($action == 'log-out')){ wp_safe_redirect(getLogoutUrl()); exit(); } } add_action( 'check_admin_referer', 'logout_without_confirmation', 1, 2);
禁止图片被自动裁剪
1、后台->设置->媒体(媒体设置):取消勾选:总是裁剪缩略图到这个尺寸(一般情况下,缩略图应保持原始比例),然后,将所有尺寸宽高全部设为0;
2、在WordPress后台设置中打开隐藏的设置连接 http://你的域名/wp-admin/options.php,搜索 medium_large_size_w,并设置 0,保存。
functions.php code
// https://gist.github.com/czenzel/0f5888cbbfa4a857e56361dd3bc19b39 // https://www.mediumtalk.net/fix-featured-image-auto-cropping-wordpress/ add_action( 'init', 'czc_disable_extra_image_sizes' ); add_filter( 'image_resize_dimensions', 'czc_disable_crop', 10, 6 ); function czc_disable_crop( $enable, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) { //Instantly disable this filter after the first run //remove_filter( current_filter(), __FUNCTION__ ); //return image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, false ); return false; } //echo '<pre>'; //print_r(get_intermediate_image_sizes()); //echo '<pre>'; function czc_disable_extra_image_sizes() { foreach ( get_intermediate_image_sizes() as $size ) { remove_image_size( $size ); } }
更改JPEG图片的压缩质量
科普一下:JPEG 在这里所指的是一种压缩方式,用这种压缩格式的文件一般称之为JPEG;此类文件的一般扩展名有:jpeg、jfif、jpg 或 jpe。默认情况下,WordPress会对上传的图片进行压缩,以获得更好的用户体验。默认的压缩质量为 90%,是为优化图片在手机端的加载速度,但也因此造成上传的图片都被压缩、视觉效果变模糊。WordPress提供了 jpeg_quality 钩子,以便让用户可以自定义参数。我们就是借助这个钩子来实现修改图片压缩质量。具体的方法就是将下面的代码添加到当前主题的 functions.php 文件,更改 return 的返回值,例如:希望上传的图片不被压缩,改为 100 即可:
/** * 自定义JPEG图片压缩质量 * https://www.wpdaxue.com/wp_image_editor-jpeg_quality.html */ function wpdx_custom_jpeg_quality() { //根据实际需求,修改下面的数字即可 return 90; } add_filter( 'jpeg_quality', 'wpdx_custom_jpeg_quality');
Replace URLs to HTTPS
适用于域名变化而做全局URL更改
/* WordPress Address (URL) AND Site Address (URL) replace */ UPDATE wp_options SET option_value = replace(option_value, 'http://example.com', 'https://example.com') WHERE option_name = 'home' OR option_name = 'siteurl'; /* Menu structure url replace */ UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://example.com', 'https://example.com') WHERE `meta_key` = '_menu_item_url';
- MySQL UPDATE COMMAND
UPDATE table_name SET field1 = new-value1, field2 = new-value2 [WHERE Clause]