LAMP环境搭建
软件包准备:
autoconf-2.68.tar.gz gettext-0.18.1.1.tar.gz libmcrypt-2.5.8.tar.gz mysql-5.1.49.tar.gz
freetype-2.4.4.tar.gz httpd-2.2.9.tar.bz2 libpng-1.5.1.tar.gz php-5.2.17.tar.gz
gd-2.0.35.tar.bz2 jpegsrc.v8c.tar.gz libxml2-2.7.2.tar.gz zlib-1.2.5.tar.gz
1.安装libxml
tar zxvf libxml2-2.7.2.tar.gz
cd libxml2-2.7.2
./configure --help
./configure --prefix=/usr/local/libxml2
make
make install
安装完成后在目录下有以下五个目录:bin include man share lib
php编译时 ./configure选项加上 --with-libxml-dir=/usr/local/libxml2
2.安装libmcrypt
cd ..
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt
make
make install
安装完成后在目录下生成以下五个目录:include lib bin man share
php编译时 ./configure选项加上 --with-libmctypt-dir=/usr/local/libcrypt
不同的LINUX版本可能需要安装libltdl库,安装方法与上同
cd libltdl/
./configure --enable-ltdl-install
make
make install
3.安装zlib
cd ../../
tar zxvf zlib-1.2.5.tar.gz
cd zlib-1.2.5
./configure --prefix=/usr/local/zlib
make
make install
安装完成后在目录下生成以下五个目录:include lib share
php编译时 ./configure选项加上 --with-zlib-dir=/usr/local/zlib
4.安装libpng
cd ..
tar zxvf libpng-1.5.1.tar.gz
cd libpng-1.5.1
./configure --prefix=/usr/local/libpng
make
make install
安装完成后在目录下生成以下五个目录:include lib bin share
php编译时 ./configure选项加上 --with-png=/usr/local/libpng
5.安装jpeg
安装GD2库前所需的jpeg库文件,需手动创建安装需要的目录,它们在安装时不能自动创建。
mkdir /usr/local/jpeg8 //jpeg软件安装目录
mkdir /usr/local/jpeg8/bin //jpeg命令存放目录
mkdir /usr/local/jpeg8/lib //jpeg库文件所在目录
mkdir /usr/local/jpeg8/include //jpeg头文件目录
mkdir -p /usr/local/jpeg8/man/man1 //jpeg帮助目录
tar zxvf jpegsrc.v8c.tar.gz
cd jpeg-8c/
./configure --prefix=/usr/local/jpeg8/ --enable-shared --enable-static
make
make install
在安装GD库时,./configure选项中加上 --with-jpeg=/usr/local/jpeg8,安装PHP时也需要指定该库文件。
6.安装freetype2
tar zxvf freetype-2.4.4.tar.gz
cd freetype-2.4.4
./configure --prefix=/usr/local/freetype2
make
make install
mkdir /usr/local/freetype2/include/freetype2/freetype/internal(如果报以下错误则执行下面步骤:rmdir: /usr/local/freetype2/include/freetype2/freetype/internal: No such file or directory)
make install
安装GD2库时 ./configure选项加上 --with-freetype=/usr/local/freetype
7.安装autoconf
tar zxvf autoconf-2.68.tar.gz
cd autoconf-2.68
./configure
make
make install
8.安装gettext
tar zxvf gettext-0.18.1.1.tar.gz
cd gettext-0.18.1.1
./configure --prefix=/usr/local/gettext
make
make install
9.安装GD
tar jxvf gd-2.0.35.tar.bz2
cd gd-2.0.35
./configure --prefix=/usr/local/gd2 --with-zlib=/usr/local/zlib/ --with-jpeg=/usr/local/jpeg8/ --with-png=/usr/local/libpng/ --with-freetype=/usr/local/freetype2/
make
make install
报以下错误处理办法:
gd_png.c:47: error: expected specifier-qualifier-list before ‘jmp_buf’
gd_png.c:54: error: expected ‘)’ before ‘png_ptr’
gd_png.c:82: error: expected ‘)’ before ‘png_ptr’
gd_png.c:92: error: expected ‘)’ before ‘png_ptr’
gd_png.c:98: error: expected ‘)’ before ‘png_ptr’
处理方法:
vi gd_png.c
#include "png.h" 修改为:#inclue "/usr/local/libpng/include/png.h" 双引号为libpng安装路径
安装成功后,目录中包含:bin include lib,安装php时,./configure选项加上 --with-gd=/usr/local/gd2
10.安装Apache
tar jxvf httpd-2.2.9.tar.bz2
cd httpd-2.2.9
./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --with-zlib-dir=/usr/local/zlib/ --with-included-apr --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support
make
make install
安装完成后检查安装的文件
cd /usr/local/apache2/
ls
bin build cgi-bin error htdocs icons include lib logs man manual modules
启动apache
/usr/local/apache2/bin/apachectl start
netstat -alnp|grep 80 //检测apache是否运行
11.mysql安装
groupadd mysql
useradd -g mysql mysql
tar zxvf mysql-5.1.49.tar.gz
cd mysql-5.1.49
./configure --prefix=/usr/local/mysql --with-extra-charsets=all
make
make install
cp support-files/my-medium.cnf /etc/my.cnf
cd /usr/local/mysql/
./bin/mysql_install_db --user=mysql
chown -R root .
chown -R mysql var/
chgrp -R mysql .
/usr/local/mysql/bin/mysqld_safe --user=mysql & //启动mysql
netstat -alnp|grep mysql
./bin/mysqladmin variables //查看mysql所有参数。
/usr/local/mysql/bin/mysql -u root -p //登陆mysql,第一次登陆数据库root密码为空。
mysql>select host,user,password from user; //查看所有用户的数据库权限
mysql>use mysql; 调用mysql数据库
mysql>update user set user="wghgreat" where user="root"; 修改root用户为wghgreat
mysql>select Host,User,Password,Select_priv,Grant_priv from user; //查询所有用户的权限含grant、select是否开启权限
mysql>delete from user where user=''; 删除空用户
mysql>delete from user where password=''; 删除空密码的用户
mysql>delete from user where host=%; 删除在任何地方可访问的用户。
mysql>drop database test; 删除test数据库
quit
/usr/local/mysql/bin/mysqladmin -uroot -p shutdown //关闭MYSQL
12.PHP安装
tar zxvf php-5.2.17.tar.gz
cd php-5.2.17
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2 --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg8 --with-freetype-dir=/usr/local/freetype2 --with-gd=/usr/local/gd2 --with-zlib-dir=/usr/local/zlib --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets
make
make install
cp php.ini-dist /usr/local/php5/etc/php.ini
vi /etc/httpd/httpd.conf
在AddType application/x-gzip .gz .tgz下添加以下两行
AddType application/x-httpd-php .php .phtml //添加PHP支持
AddType application/x-httpd-php-source .phps //将.phps作为php源文件进行语法高亮显示
/usr/local/apache2/bin/apachectl stop
/usr/local/apache2/bin/apachectl start
测试LAMP环境
vi /usr/local/apache2/htdocs/test.php
<?
phpinfo();
?>