lamp(linux+apace+mysql+php)一直都是最流行的Web构架,所有组成产品均是开源软件,是国际上成熟的架构构架。不过,最近几年有被性能更高的lnmp(linux+nginx+mysql+php)替代的趋势,lnmp的配置,可以参考Linux/Unix系统下nginx+php安装简明教程
一、安装MYSQL
下载页面:http://www.mysql.com/downloads/mirror.php?id=404683#mirrors
1. 添加mysql用户和安装mysql依赖包
groupadd mysql
useradd -r -g mysql mysql
yum install gcc gcc-c++ libtool autoconf automake imake libxml2-devel expat-devel ncurses-devel cmake bison
2. 下载、解压mysql源码包
mkdir -p /data/temp
cd /data/temp
wget ftp://ftp.fi.muni.cz/pub/mysql/Downloads/MySQL-5.5/mysql-5.5.18.tar.gz
tar -zxvf mysql-5.5.18.tar.gz
cd mysql-5.5.18
3. 使用cmake编译mysql
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql
make
make install
cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
cp support-files/my-medium.cnf /etc/my.cnf
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/mysqld
cd /usr/local/bin
ln -fs /usr/local/mysql/bin/mysql mysql
4. 把mysql添加为系统启动服务
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
cd /etc/rc.d/init.d
chkconfig --add mysqld
service mysqld start/stop
二、安装Apache
apache下载页面:http://www.apache.org/dist/httpd/
1. 安装apache:
wget http://www.apache.org/dist/httpd/httpd-2.2.21.tar.gz
tar -zxvf httpd-2.2.21.tar.gz
cd httpd-2.2.21
./configure --enable-modules=so --enable-rewrite
make && make install
2. 安装apache扩展:
cd srclib/apr
make
make install
cd ../apr-util/
./configure --with-apr=../apr
make
make install
三、安装PHP5
1. 安装php5依赖包:
libcurl:
wget http://curl.haxx.se/download/curl-7.23.1.tar.gz
tar -zxvf curl-7.23.1.tar.gz
cd curl-7.23.1/
./configure
make && make install
cd ..
libxml2:
wget ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz
tar -zxvf libxml2-2.7.6.tar.gz
cd libxml2-2.7.6
./configure
make && make install
cd ..
libxslt:
wget ftp://xmlsoft.org/libxml2/libxslt-1.1.24.tar.gz
tar -zxvf libxslt-1.1.24.tar.gz
cd libxslt-1.1.24
./configure
make && make install
cd ..
freetype:
http://download.savannah.gnu.org/releases/freetype/freetype-2.4.6.tar.gz
tar -zxvf freetype-2.4.6.tar.gz
cd freetype-2.4.6
./configure
make && make install
cd ..
libpng:
wget "http://prdownloads.sourceforge.net/libpng/libpng-1.5.6.tar.gz?download"
tar -zxvf libpng-1.5.6.tar.gz
cd libpng-1.5.6
./configure
make && make install
cd ..
libjpeg:
wget http://ijg.org/files/jpegsrc.v8c.tar.gz
tar -zxvf jpegsrc.v8c.tar.gz
cd jpeg-8c/
./configure
make && make install
cd ..
2. 安装PHP:
wget http://cn2.php.net/get/php-5.2.17.tar.bz2/from/hk.php.net/mirror
cat php-5.2.17.tar.bz2 |bunzip2 | tar xvf -
cd php-5.2.17
./configure --with-apxs2=/usr/local/apache2/bin/apxs \
--with-curl \
--enable-calendar \
--with-xsl \
--with-libxml-dir \
--enable-ftp \
--with-gd \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--enable-mbstring \
--with-zlib \
--enable-shared \
--with-mysql
make && make install
cd ..
3. 让apache加载php模块:
vim /usr/local/apache2/conf/httpd.conf
#确保下面三行在httpd.conf配置文件中存在
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
4. 启动HTTP服务及测试
/usr/local/apache2/bin/httpd -k restart
echo "<?php phpinfo(); ?>" > /usr/local/apache2/htdocs/index.php
#使用浏览器打开URL:http://ip/index.php
常见错误:
1. 现象:make install时报"dlname not found in /usr/local/apache2/modules/libphp5.la."
解答:这是由于apache与php的libtool版本不一致引起的。
/usr/local/apache2/build/libtool --version
ltmain.sh (GNU libtool) 1.5.26 (1.1220.2.492 2008/01/30 06:40:56)
./libtool --version
ltmain.sh (GNU libtool) 1.5.22 (1.1220.2.365 2005/12/18 22:14:06)
解决方法:使php安装目录下的libtool与apache的libtool版本一致,再重新安装,操作如下:
cd /data/temp/
cp /usr/local/apache2/build/libtool .
make clean
make install
lamp构架相关文件、依赖包下载地址:
libcurl: http://curl.haxx.se/download.html
libxml2: ftp://xmlsoft.org/libxml2/
libxslt: ftp://xmlsoft.org/libxml2/
libpng: http://www.libpng.org/pub/png/libpng.html
libjpeg: http://ijg.org/files/
freetype:http://download.savannah.gnu.org/releases/freetype/ apache:http://www.apache.org/dist/httpd/
PHP:http://www.php.net/downloads.php
MySQL:http://www.mysql.com/downloads/mirror.php?id=404683#mirrors
发表评论 取消回复