最近折腾的一些问题记载

prefork OR worker?

这次有一件很郁闷的事就是,把PHP编译了几次。。。
在 ubuntu 12.04 直接 apt-get install apache2
结果,它默认给我安装的是worker方式工作的apache.

然后,编译完PHP的SO模块后,apache无法启动:

[crit] Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP.
Pre-configuration failed
Action 'configtest' failed.

在stackoverflow上找了下,有蛮多人遇到此问题,但是没有找到答案。
后来,我在了下php的官方文档,才发现是apache2版本的问题。

Warning

We do not recommend using a
threaded MPM in production with Apache 2. Use the prefork MPM, which is
the default MPM with Apache 2.0 and 2.2.
For information on why, read the related FAQ entry on using
Apache2 with a threaded MPM

所以,将php编译为apache sapi module时,要选择安装prefork MPM的Apache.

运行 apache2 -l,如有 woker.c 则是worker方式,若 有prefork.c,则是prefork模式的。
可能是我好久没用ubuntu,忘记这回事了。貌似ubuntu 默认是使用worker模式运行apache的。
好吧,我卸载之,再安装:

1
apt-get install apache2-mpm-prefork

apache error.log错误Invalid command 'Header'

Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration

产生这个错误是因为 headers 模块没有启用。
在ubuntu下可以很方便地用 a2enmod 和a2dismod 来启用和禁用模块。a2enmod headers后即可。


关于php的配置文件的位置

apache是如何查找 php的配置文件呢?
官方有说明: http://www.php.net/manual/en/configuration.file.php
有:
SAPI module 的PHPIniDir指令 指定的路径。
-c command line option in CGI and CLI
PHPRC环境变量的值
当前工作目录(except CLI)
The web server's directory (for SAPI modules), or directory of PHP (otherwise in Windows).
Windows directory (C:\windows or C:\winnt) (for Windows), or --with-config-file-path compile time option.
所以,对于服务器的全局配置来说,一般通过编译时的 --with-config-file-path来指定目录,或者通过PHPIniDir指令在apache配置文件中指定。


关于Warning: mysql_connect(): [2002] No such file or directory错误

在mysql / mysqli 模块已经正常加载的情况下,连接数据库时报此错误。
解决:把localhost 换成 127.0.0.1 后正常了。。。(可以肯定localhost是正常指向了127.0.0.1的,奇怪的问题。。。)
网上的解决办法

If you are also getting this error, follow the steps below to diagnose and fix it.

  1. Narrow down error to mysql_connect() or mysql_pconnect().
  2. Make a phpinfo() page.  Look for ‘mysql.default_socket‘, ‘mysqli.default_socket‘, and ‘pdo_mysql.default_socket‘.  Remember their value; this is where PHP is trying to connect to MySQL.
  3. Start mysql.  Execute ‘
    1
    STATUS;

    ‘ and look for the ‘UNIX socket‘ value.  If doesn’t match the value from phpinfo(), that’s the culprit.

  4. Open your php.ini file (which is also found on your phpinfo() page as ‘Loaded Configuration File‘) and change all the occurrences of the incorrect socket location to the correct socket location from MySQL.
  5. Restart Apache (on OSX:
    1
    sudo apachectl restart

    ) and try reloading your page.

stackoverflow上的类似问题:http://stackoverflow.com/questions/4219970/warning-mysql-connect-2002-no-such-file-or-directory-trying-to-connect-vi


关于Ubuntu上从源码编译安装软件

ubuntu平台上有一个名为checkinstall的工具。可以生成debian包并安装从源码编译的程序,并将安装后的软件纳入包管理。
因此,在ubuntu上,尽量使用 ./configure && make && checkinstall 三步曲。
Ubuntu官方相关文档: https://help.ubuntu.com/community/CompilingEasyHowTo

https://help.ubuntu.com/community/CheckInstall

更多
One Response Post a comment

Leave a Reply

Note: You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS