首先说明下我使用的lamp版本
centos 6.7的linux版本 、 mysql-5.1.73 httpd-2.2.31 php-5.4.45
下面是下载链接
http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz
http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.31.tar.gz
http://cn2.php.net/distributions/php-5.4.45.tar.bz2
首先安装mysql
1.解压
[root@localhost src]# tar zxvf http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz
[root@localhost src]# mv mysql-5.1.73-linux-x86_64-glibc23.tar.gz /usr/local/mysql
[root@localhost src]# useradd -s /sbin/nologin mysql
3.初始化数据库
[root@localhost src]# cd /usr/local/mysql [root@localhost mysql]# mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql [root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
4.拷贝配置文件
[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf
5.拷贝启动脚本文件并修改其属性
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@localhost mysql]# chmod 755 /etc/init.d/mysqld
6.修改启动脚本
[root@localhost mysql]# vim /etc/init.d/mysqld
需要修改的地方有“basedir=/usr/local/mysql" “datadir=/data/mysql” (前面初始化数据库时定义的目录)
7.把启动脚本加入系统服务项,并设定开机启动,启动mysql
[root@localhost mysql]# chkconfig --add mysqld [root@localhost mysql]# chkconfig mysqld on [root@localhost mysql]# service mysqld start
查看是否启动
[root@localhost mysql]# ps aux |grep mysqld
安装httpd
解压 [root@localhost src]# tar zxvf httpd-2.3.1.tar.gz
安装前先安装需要的支持的库,不然会报错
yum install -y zlib-devel
yum install -y pcre pcre-devel apr apr-devel
开始安装 [root@localhost src]# cd httpd-2.2.16 [root@localhost httpd-2.2.16]# ./configure \ --prefix=/usr/local/apache2 \ --with-included-apr \ --enable-so \ --enable-deflate=shared \ --enable-expires=shared \ --enable-rewrite=shared \ --with-pcre
编译 [root@localhost httpd-2.2.16]# make
安装:
[root@localhost httpd-2.2.16]# make install
这两个步骤都可以是用 echo $? 查看是否报错
安装PHP
先安装需要的库避免报错
yum install -y libxml2-devel openssl openssl-devel bzip2 bzip2-devel libpng libpng-devel freetype freetype-devel bjpeg libjpeg-devel
cd /usr/local/src
tar zxvf php-5.4.45.tar.bz2
cd php-5.4.45
执行configure
./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
echo $?检查是否有错误
拷贝php.ini配置
[root@bogon php-5.4.45]# cp php.ini-production /usr/local/php/etc/php.ini
Apache 和PHP 结合
Apache主配置文件为:/usr/local/apache2/conf/httpd.conf
vim /usr/local/apache2/conf/httpd.conf
找到:
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
接下来测试php功能
curl localhost 提示it works
我们也可以在 /usr/local/apache2/htdocs 目录下创建1.php
<?php
phpinfo();
?>
编辑保存
那么在网页上输入http://ip/1.php就可以查看安装的 php.in 的配置环境
到此LAMP环境安装结束