搭建LAMP环境
软件版本:apache 2.2.31版本下载:http://mirrors.sohu.com/apache/httpd-2.2.31.tar.gzmysql 5.1.72版本下载:http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-x86_64-glibc23.tar.gzphp5.3.28版本下载:http://mirrors.sohu.com/php/php-5.3.28.tar.gz安装LAMP之前必备安装包
1
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解压并移动;
1
2
# 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
创建数据库用户、目录、更改属主;
1
2
3
# useradd -s /sbin/nologin mysql
# mkdir -p /data/mysql
# chown -R mysql:mysql /data/mysql
初始化数据库;
1
2
# cd /usr/local/mysql
# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
拷贝配置文件,修改my.cnf;
1
2
3
4
5
# cp support-files/my-large.cnf /etc/my.cnf
# vim /etc/init.d/mysqld
user=mysql
datadir=/data/mysql
编辑mysqld启动脚本,找到basedir和datadir添加路径;
1
2
3
# vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
拷贝启动文件、添加开机启动;
1
2
3
4
# cp support-files/mysql.server /etc/init.d/mysqld
# chmod 755 /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
启动mysql;
1
service mysqldstart
编译安装apache
1
2
3
4
5
6
7
·/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
1
2
3
# 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
1
2
3
4
# tar zxf apr-1.5.2.tar.gz
# cd apr-1.5.2
# ./configure --prefix=/usr/local/apr
# make && make install
编译apr-util
1
2
3
4
# tar zxf apr-util-1.5.4.tar.gz
# cd apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
编译安装apache
1
2
3
# tar zxf httpd-2.4.12.tar.gz
# cd 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
1
2
3
4
# tar zxvf php-5.3.28.tar.gz
# cd php-5.3.28
# ./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
# make && make install
拷贝php配置文件
1
# cp /usr/local/src/php-5.3.28/php.ini-production /usr/local/php/etc/php.ini
配置apache解析php
1
2
3
4
5
6
7
8
9
10
11
12
找到:AddType application/x-gzip .gz .tgz
在该行下面添加:AddType application/x-httpd-php .php
找到:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
将该行改为:
<IfModule dir_module>
DirectoryIndex index.html index.htm index.php
</IfModule>
找到:#ServerName www.example.com:80
修改为:ServerName localhost:80
测试apache解析php
1
2
3
4
5
6
7
# cat /usr/local/apache2/htdocs/test.php
<?php
echo "PHP解析正常\n";
?>
# /usr/local/apache2/bin/apachectl start
# curl localhost/test.php
出现:PHP解析正常
页:
[1]