1,首先连接光盘建立挂载点进行光盘挂载,挂载完成后修改yum源,然后安装gcc编译环境完成安装后关闭一些服务包括httpd服务和mysqld服务另外防火墙也要关闭
[root@localhost ~]#mount /dev/sr0 /mnt/cdrom
[root@localhost ~]#cd /etc/yum .repos.d/
[root@localhost yum.repos.d]#vim CentOS-Base.repo
[centosplus]
name=CentOS-$releasever -Plus
baseurl=file:///mnt/cdrom
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[root@localhost ~]#service httpd stop
[root@localhost ~]#service mysqld stop
[root@localhost ~]#setenforce 0
[root@localhost ~]#iptables -F
这里因为之前所有相关服务都已关闭所以会出现关闭失败
将第一条路径注释掉将相应的第二个选项路径改为光盘挂载点 ,这里将秘钥检测设置为0代表不进行秘钥检测下将enable选项设为1完成相应的修改后下面进行gcc编译环境的安装
2,安装gcc编译环境:
[root@localhost ~]#yum -y install gcc*
3,安装gcc编译环境后接下来需要换光盘然后重新挂载,挂载完成后将光盘中的安装包复制到/usr/src/lamp,复制完成后需要换回原来的光盘然后进行重新挂载:
[root@localhost ~]#eject
[root@localhost ~]#mount /dev/sr0 /mnt/cdrom
[root@localhost ~]#cd /mnt/cdrom
[root@localhost cdrom]#cp -rf lamp-php5.4 /usr/src/lamp
这里的eject命令用于弹出光盘
3,完成复制操作后需要再次更换光盘重新进行挂载,进行进一步的安装:
4,换回光盘后接下来进行安装操作,要想安装接下来的服务首先要解压相应的安装包然后才能进行相应的安装,首先切换到拥有这些安装包的目录下,由于需要解压的压缩包太多,这里编写一个脚本进行解压:
[root@localhost ~]#vim 1.sh
#!/bin/bash
/bin/ls *.tar.gz >ls.list
/bin/ls *.tgz.>>ls.list
for i in $(cat ls.list)
do
tar -xvf $i
done
写好脚本文件后使用bash+脚本名进行编译,编译完成后接下来一起去看看解压出来的安装包吧!
[root@localhost ~]#bash 1.sh
5,解压完成后在安装之前还要搭建python-devel环境使用yum安装即可:
[root@localhost ~]#yum -y install python -devel
6,搭建环境完成后接下来切换到/usr/src/lamp进行安装操作
进入lamp目录中的libxml2-2.9.1目录安装libxml2
[root@localhost ~]#cd /usr/src/lamp
[root@localhost lamp]#cd libxml2-2.9.1
[root@localhost libxml2-2.9.1]# ./configure --prefix=/usr/local/libxml2/
为其指定安装路径安装完成后使用make和make install 命令进行编译,
[root@localhost libxml2-2.9.1]# make
[root@localhost libxml2-2.9.1]# make install
7,libxml安装完成后切换目录到/lamp/libmcrypt-2.5.8安装libmcrypt,提供加密算法
[root@localhost libxml2-2.9.1]# cd /usr/src/lamp/libmcrypt-2.5.8
[root@localhost libmcrypt-2.5.8]#./configure --prefix=/usr/local/libmcrypt/
同样的使用make 和make install 命令进行编译
[root@localhost libmcrypt-2.5.8]# make
[root@localhost libmcrypt-2.5.8]# make install
8,安装mhash包,提供加密方式的扩展,装该包之前需要安装libitdl包切换到/lamp/libmcrypt-2.5.8/libitdl目录下进行安装
[root@localhost libmcrypt-2.5.8]#cd libltdl
[root@localhost libltdl]#./configure --enable-ltdl-install
安装完成后使用make和make install进行编译
[root@localhost libltdl]# make
[root@localhost llibltdl]# make install
9,安装完libitdl后切换到/usr/src/lamp/mhash-0.9.9.9进行mhash安装
[root@localhost libltdl]#cd /usr/src/lamp/mhash-0.9.9.9
[root@localhost mhash-0.9.9.9]#./configure
安装后同样进行make和make install 安装
[root@localhost mhash-0.9.9.9]# make
[root@localhost mhash-0.9.9.9]# make install
10,mhash安装后切换到mcrypt-2.6.8目录下进行安装mcrypt,提供php相关的加密支持
[root@localhost mhash-0.9.9.9]#cd ../mcrypt-2.6.8
[root@localhost mcrypt-2.6.8]#LD_LIBRARY_PATH=/usr/local/libmcrypt/lib:/usr/local/lib ./configure --with-libmcrypt-prefix=/usr/local/libmcrypt
安装完成使用make和make install进行编译
[root@localhost mcrypt-2.6.8]# make
[root@localhost mcrypt-2.6.8]# make install
11,接下来切换到/lamp/zlib-1.2.3安装zlib,提供压缩的一个库
[root@localhost mcrypt-2.6.8]#cd ../zlib-1.2.3
[root@localhost zlib-1.2.3]#./configure
安装完成使用make和make install进行编译
[root@localhost zlib-1.2.3]# make
[root@localhost zlib-1.2.3]# make install
12,安装完成后切换到/lamp/libpng-1.2.31安装libpng,提供支持png图片的库
[root@localhost zlib-1.2.3]#cd ../libpng-1.2.31
[root@localhost libpng-1.2.31]#./configure --prefix=/usr/local/libpng
安装完成使用make和make install进行编译
[root@localhost libpng-1.2.31]# make
[root@localhost libpng-1.2.31]# make install
13,安装jpeg6,提供jpeg格式的库需要首先创建一些目录
[root@localhost libpng-1.2.31]#mkdir /usr/local/jpeg6
[root@localhost libpng-1.2.31]#mkdir /usr/local/jpeg6/bin
[root@localhost libpng-1.2.31]#mkdir /usr/local/jpeg6/lib
[root@localhost libpng-1.2.31]#mkdir /usr/local/jpeg6/include
[root@localhost libpng-1.2.31]#mkdir -p /usr/local/jpeg6/man/man1
14,切换到/lamp/jpeg-6b安装jpeg6
[root@localhost libpng-1.2.31]#cd ../jpeg-6b
[root@localhost jpeg-6b]#./configure --prefix=/usr/local/jpeg6 --enable-shared --enable-static
安装完成使用make和make install进行编译
[root@localhost jpeg-6b]# make
[root@localhost jpeg-6b]# make install
15,切换到/lamp/freetype-2.3.5目录安装freetype,提供相关字体支持
[root@localhost jpeg-6b]# cd ../freetype-2.3.5
[root@localhost freetype-2.3.5]# ./configure --prefix=/usr/local/freetype
安装完成使用make和make install进行编译
[root@localhost freetype-2.3.5]# make
[root@localhost freetype-2.3.5]# make install
16,创建目录切换到/lamp/gd-2.0.35目录安装GD,提供PHP图形扩库
[root@localhost freetype-2.3.5]#cd ../gd-2.0.35
[root@localhost gd-2.0.35]#./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6 --with-freetype=/usr/local/freetype --with-png=/usr/local/libpng
安装完成使用make和make install进行编译进行编译,编译会出现错误编译gd_png.c文件
[root@localhost gd-2.0.35]# make
[root@localhost gd-2.0.35]# make install
[root@localhost gd-2.0.35]#vim gd_png.c
修改完成后重新执行安装和编译命令
[root@localhost gd-2.0.35]#./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6 --with-freetype=/usr/local/freetype --with-png=/usr/local/libpng
[root@localhost gd-2.0.35]# make
[root@localhost gd-2.0.35]# make install
17,安装完成后切换目录安装apache服务首先切换到lamp目录将mcrypt-2.6.8和libmcrypt-2.6.8.这两个目录拷贝到httpd-2.4.7/srclib/apr/和httpd-2.4.7/srclib/apr-util
[root@localhost gd-2.0.35]#cd ..
[root@localhost lamp]#cp -r apr-1.4.6 httpd-2.4.7/srclib/apr
[root@localhost lamp]#cp -r apr-util-1.4.1 httpd-2.4.7/srclib/apr-util
18,拷贝完成后切换到lamp/pcre-8.34执行以下命令目录安装httpd服务并进行编译
[root@localhost lamp]#cd pcre-8.34
[root@localhost pcre-8.34]#./configure
[root@localhost pcre-8.34]#make
[root@localhost pcre-8.34]#make install
19,安装完成后切换到lamp/httpd-2.4.7目录安装apache服务
[root@localhost pcre-8.34]#cd ../httpd-2.4.7
[root@localhost httpd-2.4.7]#./configure --prefix=/usr/local/apache2 --sysconfdr=/usr/local/apache2/etc --with-include-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared
安装完成后使用make和make install命令进行编译
[root@localhost httpd-2.4.7]#make
[root@localhost httpd-2.4.7]#make install
20,安装完成,测试,开启服务
[root@localhost httpd-2.4.7]# /usr/local/apache2/bin/apachectl start
在windows的地址栏中输入服务器的地址直接访问
设置开启自启apache2
[root@localhost httpd-2.4.7]#vim /etc/rc.d/rc.local
......
/usr/local/apache2/bin/apachectl start
21,apache安装完成后接下来安装mysql在安装之前先安装cmake和bison
[root@localhost httpd-2.4.7]#yum -y install cmake
[root@localhost httpd-2.4.7]#yum -y install bison
22,安装完成后创建mysql用户然后切换到lamp/ncurses目录下安装ncurses-5.9
[root@localhost httpd-2.4.7]#useradd mysql
[root@localhost httpd-2.4.7]#cd ../ncurses-5.9
[root@localhost ncurses-5.9]# ./configure --with-shared --without-debug --with-ada --enable-overwrite
安装完成后使用make和make install命令进行编译
[root@localhost ncurses-5.9]#make
[root@localhost ncurses-5.9]#make install
23,安装完成后切换到lamp/mysql-5.5.23目录下安装mysql
[root@localhost ncurses-5.9]# cd ../mysql-5.5.23
[root@localhost mysql-5.5.23]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DEXTRA_CHARSET-all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci - DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMEORY_STORAGE_ENGINE=1 - DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306
安装完成后使用make和make install命令进行编译
[root@localhost mysql-5.5.23]#make
[root@localhost mysql-5.5.23]#make install
24,安装完成,进入mysql的安装目录中(/usr/local/mysql),更改一些权限切换目录,并设置权限,用本地用户初始化数据库
[root@localhost mysql-5.5.23]#cd /usr/local/mysql
[root@localhost mysql]#chown -R mysql:mysql
[root@localhost mysql]# /usr/ocal/mysql/scripts/mysql_install_db --user=mysql
25,接下来,授权表和库的权限生成配置文件
[root@localhost mysql]#chown -R root
[root@localhost mysql]#chown -R mysql data
[root@localhost mysql]#cp support-files/my-medium.cnf /etc/my.cnf
26,先使用ps命令查看进程中是否存在mysql进程杀死然后再开启mysql服务
开启Mysql服务
[root@localhost mysql]#/usr/local/mysql/scripts/mysql_install_db --user=mysql
[root@localhost mysql]#/usr/local/mysql/bin/mysqld_safe --safe=mysql
将mysql设置为开启自启修改/etc/rc.d/rc.local文件
[root@localhost mysql]#vim /etc/rc.d/rc.local
......
/usr/local/mysql/bin/mysqld_safe --user=mysql &
接下来为mysql设定密码首先检查是否能够连接数据库
[root@localhost mysql]#/usr/local/mysql/bin/mysqld_safe --user=mysql
检测能够连通后为mysql设定密码并登录进行验证
[root@localhost mysql]#/usr/local/mysql/bin/mysqladmin -u root password '123456'
[root@localhost mysql]#/usr/local/mysql/bin/mysql -u root -p
清空历史密码记录,否则别人登陆的话会看到刚才设定的mysql的密码
[root@localhost mysql]#history -c
[root@localhost mysql]#history
查看前面设置的mysql的内容
[root@localhost ~]# /usr/local/mysql/bin/mysql -u root -p
27,安装完Mysql接下来安装php首先需要安装libtool*
[root@localhost ~]#yum -y install libtool*
安装完成后编辑 /usr/local/gd2/include/gd_io.h文件
[root@localhost ~]#vim /usr/local/gd2/include/gd_io.h
编辑完成后开始安装php
[root@localhost ~]#cd /usr/src/lamp
[root@localhost lamp]#cd php-5.4.25
[root@localhost php-5.4.25]# ./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --withapxs2=/usr/local/apache2/bin/apxs--with-mysql=/usr/local/mysql --with-libxml-dir=/usr/local/libxml2 --with-jpegdir=/usr/local/jpeg6/ --with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ -- whit-mcrypt=/usr/local/libmcrypt/ --with-mysql=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all -- enable-sockets--with-pdo-mysql=/usr/local/mysql --without-pear
安装完成后接下来使用make和make test进行测试测试完成后继续使用make install 命令进行编译
[root@localhost php-5.4.25]#make
[root@localhost php-5.4.25]#make test
[root@localhost php-5.4.25]#make install
28,安装测试编译完成后接下来打开网站的配置文件,让网站能够与php协同工作
[root@localhost php-5.4.25]#mkdir /usr/local/php/etc
[root@localhost php-5.4.25]#cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-5.4.25]#vim /usr/local/apache2/etc/httpd.conf
修改了apache的配置文件,关闭,然后重启。一般源码安装的都是stop,然后start
[root@localhost php-5.4.25]#/usr/local/apache2/bin/apachectl stop
[root@localhost php-5.4.25]#/usr/local/apache2/bin/apachectl start
29,搭建完成后接下来进行相应的测试
[root@localhost php-5.4.25]#cd /usr/local/apache2/htdocs
创建一个测试页
保存,在windows下测试的地址栏输入:
[root@localhost htdocs]#vim index.php
phpinfo();
?>
测试数据库
[root@localhost htdocs]#vim test.php
<?php
$link=mysql_connect("127.0.0.1","root","3306");
if($link)
echo "mysql is work";
else
echo "mysql is error";
mysql_close();
?>
30,安装
# 安装phpMyAdmin
[root@localhost lamp]#cp -r phpMyAdmin-4.1.4-all-languages /usr/local
[root@localhost lamp]#cd /usr/local/apache2/htdocs/phpmyadmin
[root@localhost phpmyadmin]#cp config.sample.inc.php config.inc.php
[root@localhost phpmyadmin]#vim config.inc.php
在Windows下输入搭建lamp服务的主机ip进行验证
测试时可能会出现如上图所示的错误这是因为所生成的数据库套接字文件不在/var/lib/mysql目录下,生成的相应套接字文件在/tmp目录下将套接字文件放置/var/lib/mysql目录下即可
[root@localhost phpmyadmin]#cd /tmp
[root@localhost tmp]#mv mysql.sock /var/lib/mysql/mysql.sock
再次测试