参考网站:
1 搭建前准备工作
1.1 软件安装包的获取
由于本文搭建LAMP环境使用的是源码安装,在安装过程中需要使用到许多的软件安装包,因此在安装过程中应该首先把需要用到的安装包进行下载,需要使用的软件安装包以及下载地址如下所示:
httpd-2.4.9.tar.gz
mysql-5.7.4.tar.gz
http://dev.mysql.com/downloads/
php-5.5.14.tar.gz
http://cn2.php.net/downloads.php
phpMyAdmin-4.2.5-all-languages.tar.gz
http://www.phpmyadmin.net/home_page/downloads.php
libxml2-2.9.0.tar.gz
libmcrypt-2.5.8.tar.gz
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/
libgd-2.1.0.tar.gz
https://bitbucket.org/libgd/gd-libgd/downloads
zlib-1.2.8.tar.gz
autoconf-2.69.tar.gz
http://ftp.gnu.org/gnu/autoconf/
freetype-2.5.3.tar.gz
http://download.savannah.gnu.org/releases/freetype/
libpng-1.6.12.tar.gz
ftp://ftp.simplesystems.org/pub/libpng/png/src/
jpegsrc.v9a.tar.gz
ZendGuard-5_5_0.tar.gz
http://www.zend.com/en/products/guard/thank-you-zend-guard?package=415
apr-1.5.1.tar.gz
http://apr.apache.org/download.cgi
apr-util-1.5.3.tar.gz
http://apr.apache.org/download.cgi
pcre-8.35.zip
http://sourceforge.net/projects/pcre
本文搭建的LAMP环境大致需要上述安装包,如果在搭建过程中碰到还需要其他安装版的情况可以下载对应安装包即可。
1.2 将软件包放置在Linux系统上
首先需要下载安装辅助工具XFtp来对本机上下载的软件包进行移植,下载完成后打开Xshell界面,连接需要搭建LAMP的虚拟机,点击“新建文件传输(CTRL+ALT+F)”按钮打开XFtp工具自动建立与虚拟机的连接。连接XFtp方式如下图所示:
点击“新建文件传输”按钮之后进入如下界面极为成功。
在虚拟机上的/usr/local/src目录下新建LAMP文件夹,将本机上下载的软件安装包传输到LAMP文件夹之下。
1.3 编译工具的安装以及卸载默认LAMP环境
LAMP环境搭建所需要的软件都使用C语言开发的,所以安装源代码文件最少需要配置(configure)、编译(make)、安装(make install)三个步骤,在虚拟机上输入‘gcc -v’命令,如果gcc已安装,则如下图所示:
否则应该首先安装编译工具,使用yum安装,输入命令行‘yum -y install make gcc gcc-c++ zlib-devel libaio’。
检查系统中是否存在已安装的LAMP环境,以Apache为例,输入‘rpm -qa | grep -i httd’,如果存在已安装的Apache,则应使用‘rpm –e httpd-xxx -nodeps’卸载Apache(xxx为版本号),MySql与PHP操作与Apache相同。
1.4 防火墙端口的配置以及SELINUX的关闭
编辑/etc/sysconfig/iptables文件,配置防火墙,命令如下‘vim /etc/sysconfig/iptables’
在‘-A INPUT –m state –state NEW –m tcp –p tcp –dport 22 –j ACCEPT’下添加如下命令
‘-A INPUT –m state –state NEW –m tcp –p tcp –dport 80 –j ACCEPT’
‘-A INPUT –m state –state NEW –m tcp –p tcp –dport 3306 –j ACCEPT’
保存退出。
由于SELINUX的开启可能会对MySql造成一定的影响,所以提前关闭SELINUX
输入命令‘vim /etc/selinux/config’进入编辑界面,修改如下内容:
#SELINUX=enforcing #将该行注释
#SELINUXTYPE=targeted 将该行注释
SELINUX=disabled #增加内容
完成上述操作后,重启系统‘shutdown –r now’
1.5 搭建须知
(1)解压tar.gz为后缀的压缩包软件
LAMP环境搭建所需要的每个软件的源代码文件,都是以.tar.gz提供给我们的打包压缩文件,所以我们必须将其解压再解包。可通过命令#tar zxvf xxxx.tar.gz达到目的。
(2)在linux系统中源代码包安装过程
进行解压后的目录,LAMP环境搭建所需要的软件都使用C语言开发的,所以安装源代码文件最少需要配置(configure)、编译(make)、安装(make install)三个步骤。
2 apache的安装
卸载本机上存在的apr,apr-util,命令为‘yum removed apr apr-util’
2.1 编译安装apr
命令如下
cd /usr/local/src/lamp #
tar zxvf apr-1.5.1.tar.gz #解压缩命令,tar zxvf apr-xxx.tar.gz(xxx为版本号)
cd apr-1.5.1 #
./configure --prefix=/usr/local/apr-httpd #配置,制定apr安装位置以及安装目录
make #编译
make install #安装
2.2 编译安装apr-util
命令如下
[root@centos6 LAMP]#tar zxvf apr-util-1.5.3.tar.gz
[root@centos6 LAMP]#cd apr-util-1.5.1
[root@centos6apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util-httpd/ \
>--with-apr=/usr/local/apr-httpd/
[root@centos6apr-util-1.5.3] # make
[root@centos6apr-util-1.5.3] # make install
2.3 编译安装pcre
[root@centos6 LAMP]#unzip –o pcre-8.35.zip
[root@centos6 LAMP]#cd pcre-8.35
[root@centos6 pcre-8.35]#./configure--prefix=/usr/local/pcre
[root@centos6 pcre-8.35]#make
[root@centos6 pcre-8.35]# make install
2.4 编译安装apache
[root@centos6 LAMP]# tar zxvf httpd-2.4.9.tar.gz
[root@centos6 LAMP]# cd httpd-2.4.9
[root@centos6 LAMP]#./configure --prefix=/usr/local/apache249 --enable-mods-shared=all --enable-deflate --enable-speling --enable-cache --enable-file-cache --enable-disk-cache --enable-mem-cache --enable-so --enable-expires=shared --enable-rewrite=shared --enable-static-support --sysconfdir=/etc/httpd --with-z=/usr/local/zlib/ --with-apr=/usr/local/apr-httpd/ --with-apr-util=/usr/local/apr-util-httpd/ --with-pcre=/usr/local/pcre/ --disable-userdir
[root@centos6 LAMP]# make
[root@centos6 LAMP]# make install
安装完成后进入/usr/local/apache249目录下,检查是否有如下文件
bin build cgi-bin error htdocs icons include logs man manual modules
启动Apache服务器,并查端口是否开启,启动Apache服务器的命令行如下:
[root@centos6 httpd-2.4.9]#/usr/local/apache249/bin/apachectl start
若提示信息如下:
AH00558:httpd:Could not reliably determine the server's fully qualified domain name, using::1.Set the ServerName' directive globally to suppress this message
解决方案:
[root@centos6 httpd-2.4.9]#vim/etc/httpd/httpd.conf
加上下面一行使用80端口,重启apache
ServerName localhost:80
2.5 测试安装以及设置开机启动
测试安装结果,打开浏览器,在地址栏中输入网络适配器(仅主机模式)的IP地址,本次安装为:http://192.168.78.2/如果浏览器中出现It works!则表明Apache服务器可以使用。
每种服务器软件都有必要制成开机时自动启动,Apache服务器开机自动启动,只要在“/etc/rc.d/rc.local”文件,加上Apache服务器的启动命令即可。可以直接打开“/etc/rc.d/rc.local”文件,在最后一行写入Apache启动命令,也可以用echo命令追加进去,如下命令行示:
[root@localhost apache243]#echo "/usr/local/apache243/bin/apachectl start" >> /etc/rc.d/rc.local
[root@centos6 LAMP]# /usr/local/apache/bin/apachectl start
[root@centos6 LAMP]#cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
[root@centos6 LAMP]#chmod +x /etc/init.d/httpd
[root@centos6~]# chkconfig –add httpd
3 编译安装MySql
3.1 编译安装cmake,ncurses-devel
1.下载软件cmake-3.0.0.tar.gz http://www.cmake.org/
[root@centos6~]# tar zxvf cmake-3.0.0.tar.gz
[root@centos6~]# cd cmake-3.0.0
[root@centos6~]#./bootstrap
[root@centos6~]# gmake
[root@centos6~]# make&&make install
2.安装ncurses-devel
首先需要使用yum安装了下ncurses-devel
[root@centos6~]# yum -y install ncurses-devel
3.2 安装MySql
(1)创建用户,组和目录
[root@centos6~] groupadd mysql
[root@centos6~] useradd mysql -g mysql
[root@centos6~]#mkdir /usr/local/mysql //创建安装目录
[root@centos6~]#mkdir /usr/local/mysql/data//创建数据仓库目录
(2)编译安装mysql
[root@centos6~]#tar zxvf mysql-xxxx.tar.gz
[root@centos6~]# cd mysql-VERSION
[root@centos6~]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql.sock -DMYSQL_DATADIR=/usr/local/mysql/data -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_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 .
若出现下述错误:
CMake Error at cmake/boost.cmake:81 (MESSAGE):
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
This CMake script will look for boost in <directory>. If it is not there,
it will download and unpack it (in that directory) for you.
If you are inside a firewall, you may need to use an http proxy:
export http_proxy=http://example.com:80
Call Stack (most recent call first):
cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST)
CMakeLists.txt:451 (INCLUDE)
则需先现在boost软件包,将其置于/usr/local/src/Lamp/下并解压,执行下述命令:
‘cmake –DWITH_BOOST=/usr/local/src/Lamp/boost_VERSION’
注意:若第一次的配置错误,需要先删除当前mysql源码目录中的CMakeCache.txt(不是cmake源码目录中的),然后再重新进行cmake配置。
[root@centos6~]# make
[root@centos6~]# make install
(3)配置mysql
[root@node-2~]# cd /usr/local/mysql
[root@node-2 mysql]# chown -R mysql .
[root@node-2 mysql]# chgrp -R mysql .
[root@node-2 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql
--datadir=/usr/local/mysql/data
Installing MySQL system tables...2016-08-18T23:43:37.858543Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
OK
Filling help tables...2016-08-18T23:43:39.517872Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h node-2 password 'new-password'
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
WARNING: Found existing config file /usr/local/mysql/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/local/mysql/my-new.cnf,
please compare it with your file and take the changes you need.
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
datadir参数:该参数指定了MySQL的数据库文件放在什么路径下。数据库文件即我们常说的 MySQL data文件
basedir参数:该参数指定了安装MySQL的安装路径,填写全路径可以解决相对路径所造成的问题。每次执行命令,都要注意这两个参数的路径是否正确。
[root@node-2 mysql]# bin/mysqld --initialize --datadir=/data/mysql # MySQL 5.7.6 and up
生成如下配置参数,这时会生成一个临时密码,需要使用这个密码,配置参数如下:
2016-08-18T06:51:23.713276Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-08-18T06:51:23.713328Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2016-08-18T06:51:23.713332Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2016-08-18T06:51:23.954081Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-08-18T06:51:23.992705Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-08-18T06:51:24.049838Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2d9c983a-6510-11e6-9485-005056bf19ae.
2016-08-18T06:51:24.050263Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-08-18T06:51:24.051129Z 1 [Note] A temporary password is generated for root@localhost: uqhaukpu5L&u
可能出现的问题:
2016-08-18T23:14:58.692187Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-08-18T23:14:58.692231Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2016-08-18T23:14:58.692235Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2016-08-18T23:14:58.693872Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2016-08-18T23:14:58.693896Z 0 [ERROR] Aborting
处理方法
cd /usr/local/mysql/data目录下执行rm–rf *
[root@node-2 mysql]# bin/mysql_ssl_rsa_setup # MySQL 5.7.6 and up
[root@node-2 mysql]# chown -R root .
[root@node-2 mysql]# chown -R mysql data
[root@node-2 mysql]# bin/mysqld_safe --user=mysql&
(4)设置开机启动
[root@node-2 mysql]# cp support-files/mysql.server /etc/init.d/mysql.server
[root@node-2 mysql]# cp support-files/my-default.cnf /usr/local/mysql/my.cnf //拷贝配置文件
[root@node-2 mysql]# vim my.cnf //编辑配置文件,加入下列内容。
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /usr/local/mysql/mysql.sock
user = mysql
port = 3306
[mysqld_safe]
pid-file = /usr/local/mysql/data/node-2.pid //该路径需要配置正确,如果不知道该路径,可使用命令查看
[root@node-2 mysql]# ps aux | grep mysql
root 9081 0.0 0.0 113120 1516 ? Ss 15:06 0:00 /bin/bash /usr/bin/mysql-systemd-start post
root 12296 0.0 0.0 113256 1608 pts/2 S 15:14 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/node-2.pid
mysql 12613 0.1 2.1 1822880 168616 pts/2 Sl 15:14 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --usermysql --log-error=/var/log/mysqld.log --pid-file=/usr/local/mysql/data/node-2.pid --socket=/usr/local/mysql/mysql.sock --port=3306
root 13047 0.0 0.0 112664 984 pts/2 S+ 15:16 0:00 grep --color=auto mysql
(5)配置环境变量
将mysql的bin目录加到PATH中,有利于以后管理和维护,在/etc/profile中加入myslq/bin,同时增加两个别名方便操作。
注:后面两个别名不加也可以,加上以后的操作更方便。
[root@node-2 mysql]# export PATH=/usr/local/mysql/bin:$PATH
[root@node-2 mysql]# alias mysql_start="mysqld_safe&"
[root@node-2 mysql]# alias mysql_stop="mysqladmin -u root –p shutdown"
(6)登录mysql
[root@node-2 mysql]# /etc/init.d/mysql.server start
出现Starting MySQL SUCCESS!则说明启动成功
[root@centos6~]#mysql –u root –p #输入用户名密码显示如下界面则说明登陆成功
(密码在root目录下的.mysql_secret文本中)
(7)修改密码
登陆进去之后:
Mysql>set password = password('xxxxxx');
4 编译安装php
4.1 编译安装libxml2
注:libxml2是一个xml的c语言版的解析器,不仅支持c语言,还支持c++、php、Pascal、Ruby、Tcl等语言的绑定
[root@centos6 LAMP]#pwd
/usr/local/src/LAMP
[root@centos6 LAMP]# tar –zxvf libxml2-2.7.8.tar.gz
[root@centos6 LAMP]# cd ./libxml2-2.7.8
[root@centos6 libxml2-2.7.8]# ./configure --prefix=/usr/local/libxml2/
[root@centos6 libxml2-2.7.8]#make
[root@centos6 libxml2-2.7.8]#make install
注:选项--prefix=/usr/local/libxml2作用是将软件安装到/usr/local/libxml2 目录下。
如果安装成功以后,在/usr/local/libxml2/目录下将生成bin,include,lib,share四个目录。在后面安装PHP5源代码的配置时,会通过在configure命令的选项中加上"--with-libxml-dir=/usr/local/libxml2"选项,用于指定安装libxml2库文件的位置。
4.2 编译安装libmcrypt
[root@centos6 LAMP]#pwd
/usr/local/src/LAMP
[root@centos6 LAMP]#tar –zxvf libmcrypt-2.5.8.tar.gz
[root@centos6 LAMP]# cd ./libmcrypt-2.5.8
[root@centos6 libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt/
[root@centos6 libmcrypt-2.5.8]#make
[root@centos6 libmcrypt-2.5.8]#make install
如果安装成功就会在/usr/local/libmcrypt/目录下生成bin,include,lib,man,share五个目录。然后在安 装
PHP5源代码包的配置时,就可以通过configure命令加上“--with-mcrypt-dir=/usr/local/libmcrypt”选项,指定这个libmcrypt库文件的位置。
如./configure时报错:configure:error:C++ compiler cannot create executables。
解决方案:运行下面命令,然后重新configure(配置)
Yum install gcc gcc-c++ gcc-g77
安装完成libmcrypt库以后,不同的linux系统版本有可能还要安装一下libltdl库。安装方法和前面的步骤相同,可以进入到解压缩的目录/usr/local/src/libmcrypt-2.5.8下,找到libltdl库源代码所在的目录libltdl,进入这个目录按照下面几个命令配置、编译、安装就可以了。[root@localhost libltdl]#pwd /usr/local/src/libmcrypt-2.5.8/libltdl //进入软件源代码目录
[root@localhost libltdl]#./configure –enable-ltdl-install //配置ltdl库的安装
[root@localhost libltdl]#make //编译
[root@localhost libltdl]#make install //安装
4.3 编译安装zlib
注:zlib是提供数据压缩用的函式库
[root@centos6 LAMP]#pwd
/usr/local/src/LAMP
[root@centos6 LAMP]# tar –zxvf zlib-1.2.5.tar.gz
[root@centos6 LAMP]#cd ./zlib-1.2.5
[root@centos6 zlib-1.2.5]#./configure --prefix=/usr/local/zlib/
[root@centos6 zlib-1.2.5]#make
[root@centos6 zlib-1.2.5]#Make install
如果安装成功将会在/usr/local /zlib目录下生成include,lib,share三个目录。在安装PHP5配置时,在configure命令的选项中加上“--with- zlib-dir=/usr/local/libmcrypt”选项,用于指定zlib库文件位置。
4.4 编译安装libpng
[root@centos6 LAMP]#pwd
/usr/local/src/LAMP
[root@centos6 LAMP]# tar –zxvf libpng-1.5.4.tar.gz
[root@centos6 LAMP]#cd ./libpng-1.5.4
[root@centos6 libpng-1.5.4]#
./configure --prefix=/usr/local/libpng/ --enable-shared
[root@centos6 libpng-1.5.4]#make
[root@centos6 libpng-1.5.4]#make install
在./configure --prefix=/usr/local/libpng这步最后会提示:configure:error:Zlib not installed
解决方法如下:
1)进入zlib的源文件目录,执行命令make clean,清除zlib;
2)重新配置./configure,后面不要接--prefix参数;
3)make&&make install;
4)进入libpng目录,执行命令./configure --prefix=/usr/local/libpng;
5)make&&make install;
6)安装成功.
如果安装成功将会在/usr/local/libpng目录下生成bin,include,lib和share四个目录。在安装GD2库配置时,通过在configure命令选项中加上“--with-png=/usr/local/libpng”选项,指定libpng库文件的位置。
4.5 编译安装jpeg
注:安装GD2库前所需的jpeg8库文件,需要自己手动创建安装需要的目录,它们在安装时不能自动创建。
[root@centos6 LAMP]#pwd
/usr/local/src/LAMP
[root@centos6 LAMP]# tar –zxvf jpegsrc.v8c.tar.gz
[root@centos6 LAMP]# cd ./jpeg-8c/
[root@centos6 jpeg-8c]# mkdir /usr/local/jpeg/
[root@centos6 jpeg-8c]#mkdir /usr/local/jpeg/bin/(创建存放命令的目录)
[root@centos6 jpeg-8c]#mkdir /usr/local/jpeg/lib/(创建jpeg库文件所在目录)
[root@centos6 jpeg-8c]#mkdir /usr/local/jpeg/include/(创建存放头文件目录)
[root@centos6 jpeg-8c]# mkdir –p /usr/local/jpeg/man/man1(建立存放手册的目录)
[root@centos6 jpeg-8c]#./configure --prefix=/usr/local/jpeg/ \
>--enable-shared \
>--enable-static(建立共享库使用的GNU的libtool和静态库使用的GNU的libtool)
[root@centos6 jpeg-8c]#make &&make install
在安装GD2库配置时,可以在configure命令的选项中加上“--with-jpeg=/usr/local/jpeg8”选项,指定jpeg8
库文件的位置。安装PHP时也要指定该库文件的位置。
4.6 编译安装freetype
[root@centos6 LAMP]#pwd
/usr/local/src/LAMP
[root@centos6 LAMP]#tar –zxvf freetype-2.4.6.tar.gz
[root@centos6 LAMP]# cd ./freetype-2.4.6
[root@centos6 freetype-2.4.6]#
./configure --prefix=/usr/local/freetype/ --enable-shared
[root@centos6 freetype-2.4.6]#make&&make install
如果安装成功将会在/usr/local/freetype目录下存在bin,include,lib和share四个目录。并在安装GD2库
时,通过configure命令选项中加上“--with-freetype=/usr/local/freetype/”选项,指定freetype库文件位置。
4.7 编译安装autoconf
唯一注意的地方是configure时,不用指定路径。
[root@centos6 LAMP]#pwd
/usr/local/src/LAMP
[root@centos6 LAMP]#tar –zxvf autoconf-2.68.tar.gz
[root@centos6 LAMP]# cd ./autoconf-2.68
[root@centos6 autoconf-2.68]#./configure
[root@centos6 autoconf-2.68]#make&&make install
4.8 编译安装GD
[root@centos6 LAMP]#pwd
/usr/local/src/LAMP
[root@centos6 LAMP]# tar –zxvf gd-2.0.35.tar.gz
[root@centos6 LAMP]# cd ./gd-2.0.35
[root@centos6 gd-2.0.35]# ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg/ --with-png=/usr/local/libpng/ --with-zlib=/usr/local/zlib/ --with-freetype=/usr/local/freetype/
[root@centos6 gd-2.0.35]# make&&make install
如果安装成功会在/usr/local/gd/目录下存在bin、include和lib这三个目录。在安装PHP5时,通过在
configure命令选项中加上“--with-gd=/usr/local/gd”选项,指定GD库文件的位置。如果报错:
gd_png.c中gdMalloc函数的问题
make[2]:***[gd_png.lo]Error1
make[2]:Leaving directory /tmp/gd-2.0.35'
make[1]:***[all-recursive]Error1
make[1]:Leaving directory/tmp/gd-2.0.35'
make:***[all]Error2
解决方案:vi gd_png.c
找到#include "png.h"改成#include "/usr/local/libpng/include/png.h"
如果报错:unrecognized option –with-zlib
那就重新安装一次zlib,注意,需要把原先解压出来的源码删掉,重新解压进行安装。
4.9 编译安装php
安装PHP之前,需要先安装libXpm-devel,否则在安装php的时候会出现下面的错误:/usr/local/src/LAMP/php-5.5.14/ext/gd/gd.c:57:22:error:X11/xpm.h:No such file or directory
make:***[ext/gd/gd.lo]Error1
编译安装libXpm-devel:
[root@CentOS6 php-5.5.14]#yum –y install libXpm-devel
[root@CentOS6 php-5.5.14]#rpm –ql libXpm-devel
/usr/bin/cxpm /usr/bin/sxpm /usr/include/X11/xpm.h /usr/lib64/libXpm.so /usr/lib64/pkgconfig/xpm.pc/usr/share/man/man1/cxpm.1.gz /usr/share/man/man1/sxpm.1.gz
查找到libXpm-devel的安装位置为/usr/lib64/libXpm.so,将选项--with-xpm-dir=/usr/lib64添加到php的配置选项中。
编译安装php
[root@centos6 LAMP]#pwd
/usr/local/src/LAMP
[root@centos6 LAMP]#tar –zxvf php-5.4.11.tar.gz
[root@centos6 LAMP]#cd./php-5.4.11
[root@localhost php-5.4.11]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2423/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir=/usr/local/libxml2 --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-gd=/usr/local/gd --with-zlib-dir=/usr/local/zlib --with-mcrypt=/usr/local/libmcrypt --with-xpm-dir=/usr/lib64 --enable-soap --enable-mbstring=all --enable-sockets
4.10 更改apache的配置文件,解析php文件
编辑配置文件/etc/httpd/httpd.conf,在LoadModule最后面添加以下内容
LoadModule php5_module modules/libphp5.so
##通常正确编译安装PHP后会自动增加,如果没有,需要手工添加。
接下来要检查apache目录下生成的php动态连接库文件,在目录/usr/local/apache/modules,找到是否存在libphp5.so文件。若不存在呢?则说明php安装不正确。
[root@centos6 ~]#vim /etc/httpd/httpd.conf
在/etc/httpd/conf/httpd.conf文件中添加如下内容:
AddType application/x-compress.Z
AddType application/x-gzip .gz .tgz
Addtype application/x-httpd-php .php .phtml
Addtype application/x-httpd-php-source.phps
将下面一行:
DirectoryIndex index.html修改为
DirectoryIndex index.php index.html index.htm
配置结束后重启Apache
[root@centos6 ~]#service httpd restart
4.11 验证
Apache服务器的根目录默认为:/usr/local/apache/htdocs/,此目录下面存放资源:
[root@centos6 ~]#vim /usr/local/apache/htdocs/index.php添加内容为
<?php
Echo phpinfo();
?>
在客服端验证,出现下图说明php搭建成功