[原]LAMP环境配置

本文已有最新版:[原]LAMP环境配置(第二版)http://www.code-life.com/?p=399

LAMP: Linux+Apache+MySQL+PHP
开源软件更新较快,请下载最新版本。测试Linux发行版本为CentOS 5.1。
CentOS官网:http://www.centos.org/
Apache官网:http://httpd.apache.org/
MySQL官网:http://www.mysql.com/
PHP官网:http://www.php.net/
__________________________________________________________________

一、下载AMP源码包并解压

下载httpd、mysql、php、ZendOptimizer和eaccelerator源码包至/usr/local/src,进入该目录:
cd /usr/local/src

解压所有源码包:
tar -zxvf httpd-2.2.8.tar.gz
tar -zxvf mysql-5.0.18.tar.gz
tar -zxvf php-5.2.5.tar.gz
tar -zxvf ZendOptimizer-3.3.0a-linux-glibc21-i386.tar.gz
tar -zxvf eaccelerator-0.9.5.2.tar.gz

二、安装并配置AMP

1.安装Apache

cd /usr/local/src/httpd-2.2.8
./configure –prefix=/usr/local/apache2 –enable-modules=most –enable-mods-shared=most
make
make install

2.安装MySQL

cd /usr/local/src/mysql-5.0.18
./configure –prefix=/usr/local/mysql –with-mysqld-user=mysql –with-extra-charsets=all
make
make install
cp support-files/my-large.cnf /etc/my.cnf
groupadd mysql
useradd -g mysql mysql
cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .
bin/mysql_install_db –user=mysql
chown -R root .
chown -R mysql var

3.安装PHP

cd /usr/local/src/php-5.2.5
./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs –with-config-file-path=/usr/local/php/etc –with-mysql=/usr/local/mysql –with-gd –with-jpeg-dir –with-png-dir –with-zlib-dir –enable-mbstring –with-mcrypt  –with-ttf –enable-gd-native-ttf –with-freetype-dir
make
make install
cp php.ini-recommended /usr/local/php/etc/php.ini

4.使Apache支持PHP文件

vim /usr/local/apache2/conf/httpd.conf
在最后添加一行:
AddType application/x-httpd-php .php
将:
DirectoryIndex index.html
改为:
DirectoryIndex index.html index.php

三、加入Apache和MySQL到随机启动

cp /usr/local/src/mysql-5.0.18/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig –add mysql
cp /usr/local/apache2/bin/apachectl /etc/init.d/apache2
vim /etc/rc.local
在最后添加一行:
/etc/init.d/apache2 start

四、测试是否安装成功

rm -f /usr/local/apache2/htdocs/*
vim /usr/local/apache2/htdocs/index.php
添加:
<?php phpinfo();?>
启动MySQL和Apache
/etc/init.d/mysql start
/etc/init.d/apache2 start
访问该Web服务器。

五、修改MySQL密码

/usr/local/mysql/bin/mysqladmin -u root password newpwd (newpwd为新密码)

六、安装ZendOptimizer和eAccelerator加速器(可选)

1.安装ZendOptimizer

cd /usr/local/src/ZendOptimizer-3.3.0a-linux-glibc21-i386
./install
在“Enter the location of your php.ini file”界面输入:
/usr/local/php/etc
其它按默认即可。

2.安装eAccelerator

cd /usr/local/src/eaccelerator-0.9.5.2
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
vim /usr/local/php/etc/php.ini
在最后加入:
[eAccelerator]
extension=”/usr/local/php/lib/php/extensions/no-debug-non-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″
创建临时文件夹:
mkdir /tmp/eaccelerator
chmod 0777 /tmp/eaccelerator

Windows下的PHP环境配置请参考我的另一篇博文:[原]WAMP环境配置

原创文章,转载请注明出处:代码人生https://www.code-life.com/
本文链接地址:https://www.code-life.com/?p=185

发表评论

电子邮件地址不会被公开。 必填项已用*标注