LAMP = Linux + Apache + Mysql + PHP
服务器环境:
系统: CentOS 6.2
Apache: httpd-2.4.2
wget http://labs.renren.com/apache-mirror//httpd/httpd-2.4.2.tar.gz
Mysql: Mysql-5.5.25
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.25.tar.gz/from/http://mysql.he.net/
PHP: php-5.4.0
wget http://www.php.net/get/php-5.4.0.tar.gz/from/cn.php.net/mirror
利用CentOS Linux系统自带的yum命令安装、升级所需的程序库
-------------------------------------------------------------------------
sudo -s
LANG=C
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
-------------------------------------------------------------------------
一、编译安装Apache
1、解决依赖关系
Apache 2.4 版本
对开发环境的要求不是很严格,
对一些它所依赖的开发组件apr和apr-util的要求是比较高
apr-1.4.6-1
apr-util-1.4.1,下载 源码包 ..可从
http://apache.etoak.com/apr/
下载.. apr可由apache编译脚本来一起编译。
解压httpd源码包,解压apr和apr-util源码包,然后:
mv apr-1.4.6 httpd-2.4.2/srclib/apr
mv apr-util-1.4.1 httpd-2.4.2/srclib/apr-util
以备编译的时候使用...
安装pcre-devel软件包
可使用
yum install pcre-devel 进行安装
2、编译安装httpd-2.4.2
首先是下载好http-2.4.2的源码包,然后执行下面命令:
tar zxvf httpd-2.4.2.tar.gz
tar zxvf apr-1.4.6.tar.gz
tar zxvf apr-util-1.4.1.tar.gz
mv apr-1.4.6 httpd-2.4.2/srclib/apr
mv apr-util-1.4.1 httpd-2.4.2/srclib/apr-util
cd httpd-2.4.2
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-included-apr
make
make install
3、配置Apache
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
编辑完成后,保存退出,执行下列命令:
chmod +x /etc/rc.d/init.d/httpd
#为此服务脚本赋予执行权限
chkconfig -�Cadd httpd
#将其加入到服务列表
-------------------------------------------------------------
[如果出现 service httpd does not support chkconfig ,的情况..
vi /etc/rc.d/init.d/httpd 中 加入
# chkconfig: 2345 10 90
# description: Activates/Deactivates Apache Web Server ]
-------------------------------------------------------------
chkconfig httpd on
#设置为开机启动
service httpd configtest
#对httpd的配置文件进行检查
【如果出现 Set the 'ServerName' directive globally to suppress this message .
vi /etc/httpd/httpd.conf 将 ServiceName 修改成 localhost:80 】
service httpd start
#启动httpd服务
注:每编译安装好一个软件包后最好对其进行测试,保证其正常,避免等到了编译安装好LAMP后出现错误。
二、安装Mysql
1.为mysql数据库新建用户,可以使其以安全方式运行。
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
chown -R mysql:mysql /data0/mysql/3306/data
2. 创建MySQL数据库存放目录
mkdir -p /data0/mysql/3306/data/
chown -R mysql:mysql /data0/mysql/
3.安装mysql-5.5.23
安装mysql 我们可以使用 cmake 来安装..
cmake-2.8.8 下载地址: http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
安装cmake很简单
tar zxvf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./bootstrap
gmake
gmake install
随后安装 MYSQL
tar zxvf mysql-5.5.23.tar.gz
cd mysql-5.5.23
/usr/local/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data0/mysql/data
make
make install
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
mkdir -p /data0/mysql
mkdir -p /data0/mysql/3306/data
mkdir -p /data0/mysql/log
chown -R mysql:mysql /data0/mysql
cp support-files/my-medium.cnf /data0/mysql/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/data0/mysql/my.cnf --basedir=/usr/local/mysql --datadir=/data0/mysql/3306/data --user=mysql
chmod +x /etc/init.d/mysqld
vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data0/mysql/3306/data
chkconfig --add mysqld
chkconfig --level 345 mysqld on
service mysqld start 或者 /etc/init.d/mysqld start
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
设置root密码:
/usr/local/mysql/bin/mysqladmin -u root password '111111'
检测是否正确
/usr/local/mysql/bin/mysql -uroot -p111111
编译安装php
编译安装PHP 5.4.0所需的支持库:
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"
wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"
wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0"
-------------------------------------------------------------------------
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
make
make install
cd ../
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
-------------------------------------------------------------------------
安装php-5.4.0
tar zxvf php-5.4.0.tar.gz
cd php-5.4.0
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl
【出现 configure: error: Cannot find ldap libraries in /usr/lib.
cp -frp /usr/lib64/libldap* /usr/lib/ 】
make ZEND_EXTRA_LIBS='-liconv'
make install
配置php
为php提供配置文件
cp php.ini-production /usr/local/php/etc/php.ini
编辑Apache配置文件httpd.conf,使Apache支持php
vi /etc/httpd/httpd.conf 添加
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html
找到:
Options Indexes FollowSymLinks
修改为
Options FollowSymLinks
#不显示目录结构
找到 : AllowOverride None
修改为:AllowOverride All #开启apache支持伪静态,有三处都做修改
LoadModule rewrite_module modules/mod_rewrite.so
#取消前面的注释,开启apache支持伪静态
重新启动httpd服务,或重新载入配置文件即可。
测试php是否正常工作
更改/etc/httpd/httpd.conf 中的 DocumentRoot /data1/www
mkdir -p /data1/www
vi /data1/www/index.php 添加如下内容
<?php
phpinfo();
?>
如果测试正确我们再来测试PHP跟Mysql的连同性
vi /data1/www/index.php 添加如下内容
-----------------------------------------------------
<?php
$link=mysql_connect('localhost','root','');
if ($link)
echo "successful";
else
echo "failure";
mysql_close();
?>
-------------------------------------------------------------------
显示 successful 就为正确