软件版本:
apache 2.2.31版本下载:http://mirrors.sohu.com/apache/httpd-2.2.31.tar.gz
mysql 5.1.72版本下载:http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-x86_64-glibc23.tar.gz
php 5.3.28版本下载:http://mirrors.sohu.com/php/php-5.3.28.tar.gz
安装LAMP之前必备安装包
yum install wget gcc gcc-c++ make re2c curl curl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses ncurses-devel bison bison-devel libtool gettext gettext-devel cmake bzip2 bzip2-devel pcre pcre-devel
编译安装mysql
解压并移动;
# tar zxvf mysql-5.1.40-linux-i686-icc-glibc23.tar.gz # mv mysql-5.1.40-linux-x86_64-icc-glibc23 /usr/local/mysql
创建数据库用户、目录、更改属主;
# useradd -s /sbin/nologin mysql # mkdir -p /data/mysql # chown -R mysql:mysql /data/mysql
初始化数据库;
# cd /usr/local/mysql # ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
拷贝配置文件,修改my.cnf;
# cp support-files/my-large.cnf /etc/my.cnf # vim /etc/init.d/mysqld [mysqld] user=mysql datadir=/data/mysql
编辑mysqld启动脚本,找到basedir和datadir添加路径;
# vi /etc/init.d/mysqld basedir=/usr/local/mysql datadir=/data/mysql
拷贝启动文件、添加开机启动;
# cp support-files/mysql.server /etc/init.d/mysqld # chmod 755 /etc/init.d/mysqld # chkconfig --add mysqld # chkconfig mysqld on
启动mysql;
service mysqld start
编译安装apache
·/usr/local/apache2/bin/apachectl -M:查看安装了哪些模块 ·/usr/local/apache2/bin/apachectl -t:检查语法错误 ·/usr/local/apache2/bin/apachectl -l:查看安装的库文件 ·/usr/local/apache2/bin/apachectl graceful:重新加载配置 ·/usr/local/apache2/htcocs 主页存放目录 ·/usr/local/apache2/bin/apachectl 启动文件目录 ·/usr/local/apache2/conf 配置文件路径
Centos6 yum安装的apr版本已经不适用httpd-2.4版本了。所以,需要源码编译安装apr以及apr-util
# cd /usr/local/src/ # wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.gz # wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz
编译apr
[root@localhost src]# tar zxf apr-1.5.2.tar.gz [root@localhost src]# cd apr-1.5.2 [root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr [root@localhost apr-1.5.2]# make && make install
编译apr-util
[root@localhost src]# tar zxf apr-util-1.5.4.tar.gz [root@localhost src]# cd apr-util-1.5.4 [root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [root@localhost apr-util-1.5.4]# make && make install
编译安装apache
[root@localhost src]# tar zxf httpd-2.4.12.tar.gz [root@localhost src]# cd httpd-2.4.12 [root@localhost httpd-2.4.12]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre --enable-mods-shared=most --enable-so
编译安装php
[root@localhost src]# tar zxvf php-5.3.28.tar.gz [root@localhost src]# cd php-5.3.28 [root@localhost php-5.6.8]# ./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-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6 [root@localhost php-5.6.8]# make && make install
拷贝php配置文件
[root@localhost php-5.3.28]# cp /usr/local/src/php-5.3.28/php.ini-production /usr/local/php/etc/php.ini
配置apache解析php
找到:AddType application/x-gzip .gz .tgz 在该行下面添加:AddType application/x-httpd-php .php 找到:DirectoryIndex index.html 将该行改为:DirectoryIndex index.html index.htm index.php 找到:#ServerName www.example.com:80 修改为:ServerName localhost:80
测试apache解析php
[root@localhost ]# cat /usr/local/apache2/htdocs/test.php [root@localhost htdocs]# /usr/local/apache2/bin/apachectl start [root@localhost htdocs]# curl localhost/test.php 出现:PHP解析正常