apache/重装windows后如何修复apache2,并注册为系统服务

一般来说首次安装apache时建议安装到非windows系统所在分区,这样在windows崩溃重装后,可以不用再次进行“安装配置apache”这样重复性工作,而是直接重新注册apache为系统服务就很可以了。

这里讲一下apache重新注册为系统服务的方法(这里以apache2.0.55 win32版为例说明)。

软件的说明文档是很有用的东西,比用google在无数的结果里找寻更更准确;当然,很多软件——尤其是自由软件free software——多是英文文档,因此直接看文档常常会有一些难度。笔者的E文也不好,看还是尽量看一些英文文档,个人认为这是很有用的。

apache安装目录里有bin/目录,apache的可执行程序就在这里,里面最主要的就是Apache.exe (某些版本可能是httpd.exe)

查看apache.exe的帮助文档,在命令行里执行:

httpd.exe -?

得到如下的说明:

D:\Program Files\Apache Group\Apache2\bin>Apache.exe -?
Usage: Apache.exe [-D name] [-d directory] [-f file]
[-C "directive"] [-c "directive"]
[-w] [-k start|restart|stop|shutdown]
[-k install|config|uninstall] [-n service_name]
[-v] [-V] [-h] [-l] [-L] [-t] [-S]
Options:
-D name           : define a name for use in <IfDefine name> directives
-d directory      : specify an alternate initial ServerRoot
-f file           : specify an alternate ServerConfigFile
-C "directive"    : process directive before reading config files
-c "directive"    : process directive after reading config files
-n name           : set service name and use its ServerConfigFile
-k start          : tell Apache to start
-k restart        : tell running Apache to do a graceful restart
-k stop|shutdown  : tell running Apache to shutdown
-k install        : install an Apache service
-k config         : change startup Options of an Apache service
-k uninstall      : uninstall an Apache service
-w                : hold open the console window on error
-e level          : show startup errors of level (see LogLevel)
-E file           : log startup errors to file
-v                : show version number
-V                : show compile settings
-h                : list available command line options (this page)
-l                : list compiled in modules
-L                : list available configuration directives
-t -D DUMP_VHOSTS : show parsed settings (currently only vhost settings)
-S                : a synonym for -t -D DUMP_VHOSTS
-t                : run syntax check for config files

注意其中参数 -k install,就是注册为系统服务的,

在命令行里执行

D:\Program Files\Apache Group\Apache2\bin>Apache.exe -k install

就可以了,执行完毕后,并没有消息提示,看到系统服务里可以看到 apache2 这样服务的存在.

Apache.exe注册为windows服务时还可以使用以下参数:
apache -k install -n "服务名"
要安装一个使用特定配置的服务,安装时指定配置文件:
apache -k install -n "服务名" -f "\my server\conf\my.conf"
要移除一个Apache服务,使用:
apache -k uninstall -n "服务名"
如果没有指定服务名,缺省地,将使用"Apache2"。

MySQL错误:Incorrect file format/数据表“使用中”解决手记

硬盘出错,windows开机自动执行磁盘查检。开始工作时,web程序运行异常,有这样的信息:

130: Incorrect file format xx_messages'

看来是MySQL表损坏了,到phpmyadmin里,这个表显示状态为“使用中”,工具栏里的“操作”里,找“修复表”,但奇怪的是没有这一项,只有“强制更新表 ("FLUSH") ”(看来问题还是比较严重的),点了照例提示错误: Incorrect file format 'xx_messages'
google一下,有不少人也遇到这样问题,解决方法当然都是说修复表之类的,那直接运行SQL命令。在phpmyadmin里运行:
check table xx_messages;
analyze table xx_messages;
repair table xx_messages;
结果还是没用,照例“ Incorrect file format 'xx_messages'”
看来网上的说法不见得能解决我的问题,求人不如求已,自己解决。
到mysql数据库目录时,看看文件是不是正常,要不然就把以前备份的导进去。
该表相关的三个文件,xx_messages.MYI 的文件大小是0,看来是索引坏了,从以前的备份文件里,直接拷出来,替换这个0大小文件(其它两个文件没有替换),phpmyadmin提示错误

#1194 - Table 'bne9pb_messages' is marked as crashed and should be repaired

肯定是索引问题,昨天对表结构做过修改,用老的索引文件,肯定不对的,那就修复表:

repair table bne9pb_messages;

问题解决。不过所有数据都没有了,成了空表,这无所谓,反正是本地开发用的;如果是服务器上的表的话,一定要事先备份的,不然真的欲哭无泪的。

这次只是索引文件坏了,如果数据文件都坏了,那就只能根据旧数据备份重新改动了。

仅仅索引坏掉,其实运行
REPAIR TABLE xx_messages  USE_FRM;
应该就可以解决了;这样应该还可以保留原有数据不丢失,不过没有试,这次没做坏文件备份,没法再捣腾捣腾。