CentOS环境下LAMP的完全编译安装

 

用yum安装编译所需开发包(以下为标准的rpm包名称,根据需要选择)

# yum -y install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel gettext-devel pcre-devel

 

 

一:安装mysql

cd mysql-5.1.40

./configure \

--prefix=/usr/local/mysql \

--exec-prefix=/usr/local/mysql \

--with-mysqld-user=mysql \

--with-charset=utf8 \

--with-extra-charsets=all \

--with-innodb \

--with-pthread \

--without-debug \

--without-isam \

--without-innodb \

--enable-assembler \

--enable-thread-safe-client; 

make;make install

 

groupadd mysql 

useradd -g mysql mysql 

 

/usr/local/mysql/bin/mysql_install_db --user=mysql

chown -R root:mysql /usr/local/mysql/

chown -R mysql /usr/local/mysql

chgrp -R mysql /usr/local/mysql/

cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf

cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld

chmod 755 /etc/init.d/mysqld

chkconfig --add mysqld  

chkconfig --level 3 mysqld on 

service mysqld start 

 

测试数据库服务器

/usr/local/mysql/bin/mysql -uroot

root用户的默认密码是空

如出现标识符

mysql>

说明MySQL数据库安装成功,并且已经启动了!

 

允许root用户远程登录

mysql>grant all privileges on *.* to root@'%' identified by 'a';

mysql>flush privileges;

mysql>quit

 

二:安装apache

cd ../httpd-2.2.15

cd srclib/apr

./configure --prefix=/usr/local/apr;make;make install

 

cd ../apr-util

./configure \

--prefix=/usr/local/apr-util \

--with-apr=/usr/local/apr/ \

--with-mysql=/usr/local/mysql;

make;make install

 

cd ../.. 

mkdir -p /usr/local/apache

./configure \

--prefix=/usr/local/apache \

--enable-mods-shared=all \

--with-mysql=/usr/local/mysql \

--enable-deflate \

--enable-cache \

--enable-file-cache \

--enable-mem-cache \

--enable-disk-cache \

--with-apr=/usr/local/apr/ \

--with-apr-util=/usr/local/apr-util/ \

--enable-rewrite \

--enable-expires \

--enable-authn-dbm \

--enable-vhost-alias \

--with-mpm=worker \

--with-ssl \

--disable-ipv6

make;make install 

 

启动apahce

/usr/local/apache/bin/apachectl -k start

用浏览器查看http://localhost,得到it works,说明apache已经配置成功了.

停止apache

/usr/local/apache/bin/apachectl -k stop

设为开机自动启动

cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd

vi /etc/rc.d/init.d/httpd

找到:#!/bin/sh

另起一行,增加下面两行:

#chkconfig:35 85 15

#description: Apache HTTP Server.

chkconfig --add httpd

启动httpd服务

service httpd start

 

更改网站根目录:

vi /usr/local/apache/conf/httpd.conf

查找:

DocumentRoot "/usr/local/apache/htdocs"

改为:

DocumentRoot "/www"

 

设置管理员邮箱和ServerName:

ServerAdmin [email protected]

ServerName IP:80

建立虚拟主机

 

在httpd.conf末尾加入以下内容:

 

NameVirtualHost *:80

 

<VirtualHost *:80>

    ServerName 127.0.0.1

    DocumentRoot /www/default

</VirtualHost>

 

<VirtualHost *:80>

    ServerName lonelystarcx.gicp.net

    DocumentRoot /www/gicp

</VirtualHost>

 

<VirtualHost *:80>

    ServerName lonelystarcx.ticp.net

    DocumentRoot /www/ticp

</VirtualHost>

 

<VirtualHost *:80>

    ServerName lonelystarcx.vicp.net

    DocumentRoot /www/vicp

</VirtualHost>

 

<VirtualHost *:80>

    ServerName lonelystarcx.xicp.net

    DocumentRoot /www/xicp

</VirtualHost>

 

设置语言

查找下面关键词并注释掉

AddDefaultCharset

 

找到以下内容并去掉注释:

Include conf/extra/httpd-mpm.conf

Include conf/extra/httpd-info.conf

Include conf/extra/httpd-default.conf

 

三:安装PHP及组件

1.

cd ../jpeg-7

./configure --enable-shared --enable-static;make;make install

 

2.

cd ../libpng-1.2.37

./configure;make;make install

 

3.

cd ../freetype-2.3.9

./configure;make;make install

 

4.

cd ../zlib-1.2.3

./configure;make;make install

 

5.

cd ../gd-2.0.36RC1  

./configure \

--prefix=/usr/local/gd2 \

--mandir=/usr/share/man \

--with-jpeg \

--with-png \

--with-freetype \

--with-zlib

make;make install

 

6. 

cd ../curl-7.19.4

./configure;make;make install

 

7.

cd ../libxml2-2.7.3

./configure;make;make install

 

8.

cd ../libxslt-1.1.22 

./configure --with-libxml;make;make install

 

9.

cd ../libmcrypt-2.5.8

./configure;make;make install

/sbin/ldconfig

cd libltdl/

./configure --enable-ltdl-install;make;make install

 

10.

cd ../../libiconv-1.13.1

./configure --prefix=/usr/local;make;make install

 

11.

cd ../mhash-0.9.9.9

./configure;make;make install

cp /usr/local/lib/libmcrypt.* /usr/lib

ln -sf /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la

ln -sf /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so

ln -sf /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4

ln -sf /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8

ln -sf /usr/local/lib/libmhash.a /usr/lib/libmhash.a

ln -sf /usr/local/lib/libmhash.la /usr/lib/libmhash.la

ln -sf /usr/local/lib/libmhash.so /usr/lib/libmhash.so

ln -sf /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

ln -sf /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

ldconfig

 

12.

cd ../libevent-1.4.10-stable

./configure;make;make install

 

13.

cd ../mcrypt-2.6.8

./configure;make;make install

 

 

14.

cd ../php-5.2.10 

./configure \

--prefix=/usr/local/php \

--with-apxs2=/usr/local/apache/bin/apxs \

--with-mysql=/usr/local/mysql \

--with-mysqli=/usr/local/mysql/bin/mysql_config \

--with-config-file-path=/etc \

--with-jpeg-dir \

--with-png-dir \

--with-freetype-dir \

--with-zlib \

--with-gd=/usr/local/gd2 \

--with-libxslt \

--with-libxml-dir \

--with-curl \

--with-iconv \

--with-mcrypt \

--with-ttf \

--enable-static \

--enable-maintainer-zts \

--enable-zend-multibyte \

--enable-zend-multibyte \

--enable-inline-optimization \

--enable-sockets \

--enable-wddx \

--enable-zip \

--enable-calendar \

--enable-bcmath \

--enable-ftp \

--enable-soap \

--enable-mbstring \

--disable-debug

 

make ZEND_EXTRA_LIBS='-liconv'

make install

cp php.ini-dist /etc/php.ini

 

四. 整合apache和php

vi /usr/local/apache/conf/httpd.conf

找到

LoadModule php5_module modules/libphp5.so

去掉注释符

找到

AddType application/x-gzip .gz .tgz

在下面添加2行:

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

找到

DirectoryIndex index.html

改成 

DirectoryIndex index.html index.htm index.php

 

让Apache 支持rewrite

找到下面的字段:

AllowOverride None

修改为:

AllowOverride All

 

让页面支持gzip

LoadModule php5_module        modules/libphp5.so

之后添加:

<IfModule mod_deflate.c>

DeflateCompressionLevel 6

AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php

AddOutputFilter DEFLATE css js

</IfModule>

 

五、安装ZendOptimizer-3.3.3

cd ../zendoptimizer-3.3.3

./install.sh

 

六、安装eaccelerator:

cd ../eaccelerator-0.9.5.3

export PHP_PREFIX="/usr/local/php"

$PHP_PREFIX/bin/phpize

./configure -enable-eaccelerator=shared -with-php-config=$PHP_PREFIX/bin/php-config

make && make install

编译安装后我们会看到屏幕提示的eaccelerator.so所在的目录,比如:

/usr/local/php/lib/php/extensions/no-debug-zts-20060613/

记住这个路径,待会要用到。

修改php.ini,把下面的代码放在文件最后。

(注:如果你之前安装了Zend,eaccelerator的代码必须放在Zend代码之前)

[eaccelerator]

extension="/usr/local/php/lib/php/extensions/no-debug-zts-20060613/eaccelerator.so"

eaccelerator.shm_size="16"

eaccelerator.cache_dir="/tmp/eaccelerator"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="0"

eaccelerator.shm_prune_period="0"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"

解释:

zend_extension 是安装完程序自动指示给我们的目录

eaccelerator.shm_size="32" 缓存大小单位MB

eaccelerator.cache_dir="/tmp/eaccelerator" 缓存路径

 

建立缓存目录:

mkdir /tmp/eaccelerator

chmod 0777 /tmp/eaccelerator

 

重新启动Apache

service httpd restart

 

七、测试

/usr/local/apache/bin/apachectl configtest

显示出

Syntax OK

表示正常

默认网站根目录下建立phpinfo.php文件,输入以下内容

<?php 

  phpinfo(); 

?>' 

用浏览器打开

http://127.0.0.1/phpinfo.php

如果页面上出现了PHP的版权信息及系统配置情况,说明你的PHP编译装配置确。

 

在默认网站根目录下建立dbtest.php,输入以下内容

<?php 

$link=mysql_connect ('localhost','root','a');

if(!$link) echo "fail"; 

else echo "success"; 

mysql_close(); 

?>

chmod 755 /www/default/dbtest.php

http://127.0.0.1/dbtest.php

如页面显示success说明mysql+php配置正确

 

八、安装phpmyadmin-3.1.3.1

cp phpmyadmin-3.1.3.1 /www/default/phpmyadmin

在浏览器中输入

http://127.0.0.1/phpmyadmin

如出现登录界面则说明成功。

你可能感兴趣的:(centos)