wordpress IIRF伪静态规则

将以下规则保存为iirf.ini放到网站根目录即可实现伪静态。
RewriteBase /

#store original URL in custom header (substitute for missing REQUEST_URI header in IIS)
RewriteHeader X-REWRITE-URL: ^$ %{REQUEST_URI}

#uploaded files
RewriteRule ^(.*/)?files/$ index.php [L]
RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RedirectRule ^(.+)$ $1/ [R=301]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . – [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

彻底解决由require(‘./wp-blog-header.php’)导致的500错误

这个问题困扰我好几天了,今天总算是搞定了。

之前查了很多资料,断断续续做了不少功课。但都没实质性进展。

刚开始的症状就是首页500错,但是后台可以正常进入。

查资料找到如下方案

/** Loads the WordPress Environment and Template */
require(‘./wp-blog-header.php’);

修改为

/** Loads the WordPress Environment and Template */
require(‘wp-blog-header.php’);

这还不算完,如果以后客户装WP,每次都这个错误,那会很麻烦。

于是继续找解决方案。

后来在某博文看到一篇文章,提到可能是因为上级目录没有相应权限,导致了require函数读取文件时遭到拒绝,于是给WEB根加上了IIS-WPG用户的读取权限,然后还原代码到

/** Loads the WordPress Environment and Template */
require(‘./wp-blog-header.php’);

至此,500错误消失,博客已经可以正常打开。

php 压缩网站上的文件,并返回下载

set_options ( array ('basedir' => dirname ($modpath ), 'inmemory' => 0, //不在内存压缩.而是直接存放到磁盘.如果要压缩下载,则可以选择为1
'recurse' => 1, //是否压缩子目录,resurse,递归的意思?
'storepaths' => 1, //是否存储目录结构,我选是。
'overwrite' => 1, //是否覆盖
'level' => 5, //压缩比
'name' => $zipFileName, //压缩最后生成的文件名,无需再次设置。这里是为了解说方便才放上来的。
'prepend' => "", //未知
'followlinks' => 0, //未知
'method' => 1, //未知
'sfx' => "", //自解压
'type' => "zip", //是zip还是tar...,无需设置,这里为了方便解说。放上来。
'comment' => "" ) );
$files = array("*.*");
//可以将文件名单独列出来加进去,但是文件名必须在basedir下,文件名支持*.*表示压缩全部。
$archive->add_files($files); //加$files数组里的文件名
// 正式写入磁盘
$archive->create_archive();
@header("Content-Disposition: attachment; filename=\"$zipFileName\"");
@header ( "Content-Length: " . filesize ($zipFileName ) );
@readfile( $zipFileName);
?>

FTP在线备份Mysql数据(无需登录phpmyadmin or Cpanel等)

 其实有时候是会遇到这样的困惑的,因为某些原因不便或无法登录数据库的管理后台而又需要将数据备份出来的时候,这个时候也许就会手足无措了,那么我们在不登录数据库管理后台或者其他诸如Cpanel管理平台的情况下怎么将Mysql数据备份出来呢?很简单,只需要写一个代码文件就可以搞定。

  在当前web目录下新建一个php文件(名字可以自定义,如:backupdatabase.php),添加以下内容:

   db-`date +%Y%m%d `.sql” ) ; ?>

保存之后访问该文件,即可在当前web目录下面生成一个名为:”db-当前年月日.sql”的文件,即以数据库的备份文件。

PS:需要注意的是防止数据泄漏和使文件可写,建议备份完之后删除该文件

解密DirectAdmin的Custombuild

1. What is custombuild?
Custombuild is a tool, which can install/update:

  • Apache 1.3, 2.0 or 2.2
  • AWstats
  • Autoconf
  • Automake
  • cURL
  • Dovecot
  • Exim configuration files
  • FreeType
  • GD
  • libiconv
  • libjpeg
  • libpng
  • libmcrypt
  • libmhash
  • mod_perl
  • MySQL
  • PHP (with or without suPHP) 4, 5 or 6
  • ProFTPD
  • Pure-FTPd
  • SpamAssassin
  • Webalizer
  • Zend Optimizer
  • Zlib

Update web-applications as:

  • Atmail Open webmail
  • Roundcube webmail
  • Squirrelmail webmail
  • phpMyAdmin
  • UebiMiau webmail

2. Why should I use it?
Custombuild is able to install PHP with suPHP, all versions of PHP (4,5,6), Pure-FTPd, SpamAssassin, ProFTPD, MySQL, Exim, RoundCube webmail, Atmail lite webmail, and so on. It has an options file, which allows you to use 2 copies of PHP, choose Apache 2.0 or 2.2, option to rewrite all configs if they got damaged etc. It can also show (./build versions) or update all needed software with only 1 command (./build update_versions). CustomBuild can send you email notifications about the updates too.

3. How to install custombuild?
1.1:

Code:
cd /usr/local/directadmin
wget http://files.directadmin.com/services/custombuild/1.1/custombuild.tar.gz
tar xvzf custombuild.tar.gz
cd custombuild
./build

1.2 BETA:

Code:
cd /usr/local/directadmin
wget http://files.directadmin.com/services/custombuild/1.2/custombuild.tar.gz
tar xvzf custombuild.tar.gz
cd custombuild
./build

When you edit options.conf file, run:

Code:
./build update_data

You need to run this command for the first time:

Code:
./build all d

4. How to use options.conf?

  • Do not set both CLI and CGI of the same PHP version to “yes”.
  • After the changes every time run “./build update_data”

5. How to see what’s set in the options.conf file?
Use “./build options” to see what’s set in the options.conf file. The output will be something like:

Quote:
Apache: 1.3.37
Dovecot: 1.0.3
MySQL: 5.0.45
PHP: 5.2.3 as CLI and 4.4.7 as CGI with mail() header patch
Run “clean” every time: yes

6. What each option does in options.conf?

PHP options:

  • default_php – this option is only used when 2 versions of PHP are installed on the system. Possible values: 4 (available only in 1.1 version of CustomBuild), 5, 6 (available from 1.2 version of CustomBuild) (default: the latest version of PHP)
  • php5_ver – select PHP5 branch. Possible values: 5.2, 5.3 (default: 5.2)
  • phpX_cli – install/update PHP as CLI (default option) using “./build php” or “./build all”. Possible values: yes/no (default: yes (for the latest version of PHP).
  • phpX_cgi – install/update PHP as CGI using “./build php” or “./build all”. Possible values: yes/no (default: no).
  • php_ini – update PHP configuration file using “./build php-ini” or “./build all”. Possible values: yes/no (default: no). This option is only available from CustomBuild 1.2.
  • php_ini_type – this option is used to set what type of php.ini file CustomBuild needs to use while executing “./build php-ini”. Possible values: dist/recommended (default: recommended). This option is only available from CustomBuild 1.2.
  • zend – install/update Zend Optimizer using “./build zend” or “./build all”. Possible values: yes/no (default: no).

MySQL options:

  • mysql – this option is used to choose the version of MySQL. Possible values: 4.1, 5.0, 5.1 (default: 5.0).
  • mysql_inst – install/update MySQL using “./build mysql” or “./build all”. Possible values: yes/no (default: no).
  • mysql_backup – backup MySQL every time with MySQL update. Possible values: yes/no (default: yes).

Apache options:

  • apache_ver – this option is used to choose the version of Apache. Install/update it using “./build apache”. Possible values: 1.3, 2.0, 2.2 (default: 2.2).

Web applications:

  • phpmyadmin – install/update phpMyAdmin using “./build phpmyadmin” or “./build all”. Possible values: yes/no (default: yes).
  • atmail – install/update Atmail Open webmail using “./build atmail” or “./build all”. Possible values: yes/no (default: no).
  • squirrelmail – install/update SquirrelMail webmail using “./build squirrelmail” or “./build all”. Possible values: yes/no (default: yes).
  • roundcube – install/update RoundCube webmail using “./build roundcube” or “./build all”. Possible values: yes/no (default: yes).
  • uebimiau – install/update UebiMiau webmail using “./build uebimiau” or “./build all”. Possible values: yes/no (default: no).

Mail options:

  • exim – install/update Exim using “./build exim” or “./build all”. Possible values: yes/no (default: no). This option is only available from CustomBuild 1.2.
  • mail-header-patch – use PHP mail() header patch whith PHP installation/update. Possible values: yes/no (default: yes). No longer available since PHP 5.3.0.
  • dovecot – install/update Dovecot using “./build dovecot” or “./build all”. Possible values: yes/no (default: yes).
  • eximconf – update exim configuration file (/etc/exim.conf) using “./build exim_conf” or “./build all”. Possible values: yes/no (default: no).

Jailed shell options:

  • jail – install/update jailed shell programs using “./build all_jail”. Possible values: yes/no (default: no).

FTP options:

  • proftpd – install/update ProFTPD using “./build proftpd” or “./build all”. Possible values: yes/no (default: yes).
  • pureftpd – install/update Pure-FTPD using “./build pureftpd” or “./build all”. Possible values: yes/no (default: no).

Statistics options:

  • awstats – install/update AWstats using “./build awstats” or “./build all”. Possible values: yes/no (default: no).
  • webalizer – install/update webalizer using “./build webalizer” or “./build all”. Possible values: yes/no (default: yes).

Crontab options:

  • cron – enable crontab for CustomBuild, use “./build cron” to set-up. Possible values: yes/no (default: no).
  • email – set email for notifications. Possible values: any email address (default: [email protected]).
  • notifications – enable email notifications about the updates. Possible values: yes/no (default: yes).
  • da_autoupdate – Update DirectAdmin automatically when update is available. Possible values: yes/no (default: yes).
  • updates – update software/applications automatically when updates are available. Possible values: yes/no (default: no).
  • webapps_updates – update (automatically) only web applications (as phpMyAdmin, RoundCube, Atmail, SquirrelMail etc.). Possible values: yes/no (default: no).

CustomBuild options:

  • custombuild – version of the CustomBuild script that you want to use. Possible values: 1.1/1.2 (default: your version).
  • autover – this option is used to download versions.txt every time with every “./build” command. Possible values: yes/no (default: no).
  • bold – turn bolded text on/off. Possible values: yes/no (default: yes).
  • clean – execute “./build clean” every time. Possible values: yes/no (default: yes).
  • cleanapache – exclude apache from “./build clean”. Possible values: yes/no (default: no). This option is only available from CustomBuild 1.2.
  • clean_old_tarballs – execute “./build clean_old_tarballs” every time. Possible values: yes/no (default: yes).
  • clean_old_webapps -execute “./build clean_old_webapps” every time. Possible values: yes/no (default: yes).
  • fileserver – this option is used to set the server to download files from. Value “1” means files.directadmin.com server and value “2” means files4.directadmin.com server (Europe). Possible values: 1/2 (default: 1). This option is only available from CustomBuild 1.2.

7. How to use suPHP?

  • Do not set chmod >755 to directories or files in them.

8. Where the suPHP log is located?

Code:
/var/log/suphp.log

9. Why do I get “500 Internal server error”?
Check your suPHP log for any errors. The most common issues are:

  • file or directory has chmod >755
  • file or directory is not owned by the user.

10. How do I include this script by default with the DirectAdmin install?
Type the following before running the setup.sh:
CustomBuild 1.1:

Code:
echo "1.1" > /root/.custombuild

CustomBuild 1.2:

Code:
echo "1.2" > /root/.custombuild

11. I’ve messed up my apache (httpd) configs, how I can restore working versions?
Type:

Code:
./build rewrite_confs

12. How to make PHP6, PHP5 or PHP4 default for 1 host if both are installed as CGI?
Add this to .htaccess for PHP4 as default:

Code:
<FilesMatch "\.(inc|php|php3|php4|php5|php6|phtml|phps)$">
AddHandler x-httpd-php4 .php
</FilesMatch>

Add this to .htaccess for PHP5 as default:

Code:
<FilesMatch "\.(inc|php|php3|php4|php5|php6|phtml|phps)$">
AddHandler x-httpd-php5 .php
</FilesMatch>

Add this to .htaccess for PHP6 as default:

Code:
<FilesMatch "\.(inc|php|php3|php4|php5|php6|phtml|phps)$">
AddHandler x-httpd-php6 .php
</FilesMatch>

13. How to make PHP6, PHP5 or PHP4 default for 1 host if it’s installed as CLI?
Add the following code to .htaccess:

Code:
<FilesMatch "\.(inc|php|php3|php4|php5|php6|phtml|phps)$">
AddHandler application/x-httpd-php .php
</FilesMatch>

14. How to update everything what’s needed?
Firstly, you need to run:

Code:
./build update

To fetch the latest versions file.

Run this if you want to look what updates are available:

Code:
./build versions

Run this if you want to update everything what’s possible:

Code:
./build update_versions

15. I have installed PHP6 (or PHP5, PHP4) as CGI. How do I need configure them?
PHP4 configuration file is located here: /usr/local/etc/php4/cgi/php.ini
PHP5 configuration file is located here: /usr/local/etc/php5/cgi/php.ini
PHP6 configuration file is located here: /usr/local/etc/php6/cgi/php.ini
suPHP configuration file is located here: /usr/local/suphp/etc/suphp.conf

16. I have installed PHP6 (or PHP5, PHP4) as CGI. Where can I find the bin file?
PHP4: /usr/local/php4/bin/php
PHP5: /usr/local/php5/bin/php-cgi
PHP6: /usr/local/php6/bin/php-cgi

17. I have installed both PHP5 and PHP6 (or PHP4) as CGI, but I see a CLI version in /usr/local/bin/php. Why?
CLI version of PHP is needed for DirectAdmin. It must exist as CLI for the DirectAdmin skins.

18. When I restart apache I get this error: Invalid command ‘suPHP_UserGroup’. How can I solve it?
Probably you had compiled suPHP manually with –with-setid-mode=owner. You need to compile it again with –with-setid-mode=paranoid, or do:

Code:
cd /usr/local/directadmin/custombuild
./build update
./build clean
./build suphp

19. I have installed PHP6 (or PHP5, PHP4) as CGI, but I can not use IP/~user now. Why?
http://help.directadmin.com/item.php?id=176

20. I have installed PHP as CGI and I get the “Invalid command ‘php_admin_flag’, perhaps misspelled or defined by a module not included in the server configuration error now. What do I need to do?
You have an old copy of DirectAdmin templates that only work with PHP as CLI. You need to update your copy of DirectAdmin and execute this command:

Code:
echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue

21. How to fix “gcc: /usr/lib/mysql/libmysqlclient.so: No such file or directory“?

Code:
cp /usr/lib/libmysqlclient.* /usr/lib/mysql/

For 64-bit OS:

Code:
cp /usr/lib/libmysqlclient.* /usr/lib64/mysql/

22. I have installed PHP as CGI and I get some errors when trying to use the webmail. Why?
You get them because some folders/files are owned by apache, and they need to be owned by the user. Use this to fix the problem:
Squirrelmail:

Code:
chown -R webapps:webapps /var/www/html/squirrelmail

Uebimiau (/webmail):

Code:
chown -R webapps:webapps /var/www/html/webmail

Roundcube:

Code:
chown -R webapps:webapps /var/www/html/roundcube

23. Is it possible to use custom configuration files for PHP, Apache, SuPHP?
Yes it is, CustomBuild checks for “custom” directory in /usr/local/directadmin/custombuild. So, just use:

Code:
cd /usr/local/directadmin/custombuild
cp -Rp configure custom

It will create custom directory for you, and now you can just edit configuration files from the custom directory. If you want – you can have only 1 custom configuration file, all the others will be used from “configure” directory then (and will be updated with “./build update”).

24. I made a script that installs apache modules automatically, but I need to include their settings into the httpd.conf file. Is there an easy way to do that?
CustomBuild creates ability to include modules settings easily into the apache configuration file. You just need to create a file in /etc/httpd/conf/extra (or the other directory) and include it in /etc/httpd/conf/extra/httpd-includes.conf. It will automatically load your settings and CustomBuild won’t rewrite the file with “./build rewrite_confs”. If you need a custom PHP or Apache configuration file – just upload it to custom directory. E.g. if you have /usr/local/directadmin/custombuild/custom/ap2/configure.php5 file it will use it instead of /usr/local/directadmin/custombuild/configure/ap2/configure.php5.

25. How to fix “configure: error: Size of “void *” is less than size of “long”“?
You do not have /usr/local/lib in /etc/ld.so.conf file. Use the following commands to fix the problem:

Code:
touch /etc/ld.so.conf
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig

26. Is it possible to see what configuration files CustomBuild is using at the moment?
Yes, it is. CustomBuild has a new feature now:

Code:
./build used_configs

It will show something like:

Quote:
Apache configuration file: /usr/local/directadmin/custombuild/configure/ap2/configure.apache
PHP4 configuration file: /usr/local/directadmin/custombuild/custom/suphp/configure.php4
PHP5 configuration file: /usr/local/directadmin/custombuild/custom/ap2/configure.php5
ProFTPD configuration file: /usr/local/directadmin/custombuild/configure/proftpd/configure.proftpd

It will detect files from “custom” folder too.

27. I can not start apache because of “Invalid command ‘suPHP_Engine’, perhaps misspelled or defined by a module not included in the server configuration” error. What is wrong?
You have suPHP compiled in “owner” instead of “paranoid” mode. Use the following command to fix the problem:

Code:
./build suphp

28. Is it possible to change an option without editing options.conf file?
Yes, it is. Just run:

Code:
./build set option_name value

29. Is it possible to make PHP more secure using the CustomBuild script?
Yes, it is. You need to run “./build secure_php”. At the moment it disables some dangerous PHP functions as:

Code:
exec, system, passthru, shell_exec, escapeshellarg, escapeshellcmd, proc_close, proc_open, dl, popen, show_source

If you have any requests for the FAQ – feel free to post them into this thread.