2009-12-29

Linux下编译安装Apache/Nginx/Lighttpd+PHP+MySQL

Views: 38798 | 1 Comment

使用Ubuntu Linux, 编译过程提示缺啥补啥即可.

Apache:

./configure --prefix=/home/work/httpd --enable-so --enable-rewrite --enable-vhost-alias

配置文件:

LoadModule php5_module        modules/libphp5.so
AddType application/x-httpd-php .php
# PhpIniDir /home/work/php/php.ini

MYSQL:

./configure  --prefix=/home/work/mysql\
 --with-unix-socket-path=/home/work/mysql/tmp/mysql.sock\
 --with-big-tables\
 --without-readline\
 --without-libedit\
 --with-plugins=innobase

groupadd mysql
useradd  -s /bin/false -g mysql -pmysql mysql
/home/work/mysql/bin/mysql_install_db --user=mysql
cp support-files/my-medium.cnf /home/work/mysql/etc/my.cnf

启动:

/home/work/mysql/share/mysql/mysql.server start

修改密码 mysqladmin password 'xxx'

出错: Starting MySQL.Manager of pid-file quit without updating fi[FAILED]
解决: 权限问题, 或者 bin/mysql_install_db --user=mysql.

innodb

如果还不支持innodb, 进入mysql命令行执行:
install plugin innodb soname 'ha_innodb.so';

单独编译 Mysql 客户端

--without-server

Mysql命令行按Delete键输出"~"的问题

这是因为, Mysql默认用了一个叫 libedit 的东西来替代 libreadline, 只要换回 libreadline 就 OK 了. 编译时加上参数:

 --without-readline\
 --without-libedit\

执行 mysql --version 看输出.

(正确)mysql Ver ... using readline 5.1
(错误)mysql Ver ... using EditLine wrapper

PHP:

PHP 一定要安装 APC 模块, 否则性能会下降不少: http://pecl.php.net/package/APC (编译PHP模块的方法)

APC 和 php-5.4.9 fpm 有冲突, 会导致

*** glibc detected *** php-fpm: free(): invalid pointer: 0xb7641328 ***

可以换用 xcache: http://xcache.lighttpd.net/

用Apache

./configure  --prefix=/home/work/php-5.4.9 --with-config-file-path=/home/work/php-5.4.9 \
--with-mysql=/home/work/mysql \
--with-pdo-mysql=/home/work/mysql \
--enable-mbstring \
--with-apxs2=/home/work/httpd/bin/apxs \
--with-gettext \
--enable-soap \
--enable-fastcgi \
--with-zlib \
--enable-fpm \
--with-curl \
--with-gd \
--with-mcrypt \
--enable-sockets

将源码目录下的php.ini-dist文件改名为php.ini, 拷贝到/home/work/php目录下.

用Lighttpd

./configure --prefix=/home/work/litty/php --with-config-file-path=/home/work/litty/php\
 --with-mysql=/home/work/mysql\
 --enable-mbstring\
 --with-pdo-mysql=/home/work/mysql\
 --with-gettext\
 --enable-soap\
 --with-zlib\
 --enable-fastcgi\
 --enable-force-cgi-redirect\
 --with-gd\
 --with-jpeg=/usr/lib

需要安装libjpeg62_dev

不能同时使用apxs2和fastcgi.

配置Apache虚拟主机

<VirtualHost *:80>
    DocumentRoot "/home/work/htdocs/ideawu.net"
    ServerName ideawu.net
    ServerAlias ideawu.net *.ideawu.net
    ErrorLog "/home/work/logs/ideawu.net-error.log"
    CustomLog "/home/work/logs/ideawu.net-access.log" common
    
    DirectoryIndex index.php index.html index.htm

    <Directory "/home/work/htdocs/ideawu.net">
        Options FollowSymLinks

        AllowOverride None 

        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

安装配置Nginx

upstream php {
    # server unix:/tmp/php-cgi.socket;
    server 127.0.0.1:9000;
}

# 在 server 下, 不在 location 里
root   /*/htdocs;

安装配置Lighttpd(litty)

$HTTP["host"] =~ "(.*\.)?ideawu.net" {
	server.name = "www.ideawu.net"
	server.document-root = "/home/work/htdocs/ideawu.net/"
	server.errorlog = "/home/work/litty/logs/ideawu.net-error.log"
	accesslog.filename = "/home/work/litty/logs/ideawu.net-access.log"
}

fastcgi.server = ( ".php" =>
	(
		(
			"socket" => "/tmp/php-fastcgi.socket",
			"bin-path" => "/home/work/litty/php/bin/php-cgi",
			#"min-procs" => 2, #这个参数在新版本里已经不起作用了.
			"max-prccs" => 16,
			"bin-environment" => (
				"PHP_FCGI_CHILDREN" => "1",
				"PHP_FCGI_MAX_REQUESTS" => "10000"
			),
		)
	)
)

(版本1.4.26), 已经集成了spawn-fcgi, 也就是不再单独生成这个名字的可执行文件, min-procs参数也不再起作用. 启动的php-cgi进程数是
max-procs * ( PHP_FCGI_CHILDREN + 1 ), PHP_FCGI_CHILDREN默认=1.

Related posts:

  1. Nginx + PHP 配置和启动脚本
  2. Lighttpd mod_fastcgi源码分析
  3. MySQL 基本配置
  4. lighttpd配置HTTPS(SSL)
  5. MySQL binlog查看和清理
Posted by ideawu at 2009-12-29 11:32:25 Tags: ,

One Response to "Linux下编译安装Apache/Nginx/Lighttpd+PHP+MySQL"

  • OS : RHEL 5.6 x64

    PHP : 5.4.14

    APC: 3.1.9

    解决办法:使用APC 3.1.13,但这个版本的APC还是beta版本,在生产环境中是否稳定,还需要观察

    下载地址:http://pecl.php.net/package/APC/3.1.13 Reply

Leave a Comment