LAMP 源码编译安装 (Apache MySQL5.5.21 PHP5.3.10)
LAMP环境也web服务器中的一种搭配方案了,在这里我就来为各位介绍一下Apache MySQL5.5.21 PHP5.3.10,希望下文可以给各位带来帮助.
一:安装相关依赖组件
先yum安装基本的依赖组件:
- yuminstallmakeapr*autoconfautomakegccgcc-c++zlib-developensslopenssl-develpcre-develgdkernelkeyutilspatchperlkernel-headerscompat*mpfrcppglibclibgomplibstdc++-develpplcloog-pplkeyutils-libs-devellibcom_err-devellibsepol-devellibselinux-develkrb5-develzlib-devellibXpm*freetypelibjpeg*libpng*php-commonphp-gdncurses*libtool*libxml2libxml2-develpatch--disable-fileinfo
yum安装过后基本的组件已安好,以下编译安装可以安装最新版的组件.
1:安装zlib
zlib 官网:http://zlib.net
- wgethttp://zlib.net/zlib-1.2.8.tar.gz
- tar-xvzfzlib-1.2.8.tar.gz
- cdzlib-1.2.7.tar.gz
- ./configure
- make
- makeinstall
2:安装freetype
- wgethttp://download.savannah.gnu.org/releases/freetype/freetype-2.5.0.1.tar.gz
- cd/usr/local/src
- tar-zxvffreetype-2.3.5.tar.gz
- cdfreetype-2.3.5
- ./configure--prefix=/usr/local/freetype
- make
- makeinstall
make 的时候可能出现错误:
- /usr/include/libpng12/pngconf.h:336:error:expected‘=’,‘,’,‘;’,‘asm’or‘__attribute__’before‘.’token
- /usr/include/libpng12/pngconf.h:337:error:expected‘=’,‘,’,‘;’,‘asm’or‘__attribute__’before‘include’
- make:***[/usr/local/src/freetype-2.5.0.1/objs/sfnt.lo]Error1
解决办法:
./configure –prefix=/usr/local/freetype –without-png(加上这个选项就行了)
3:安装libpng
- wgethttp://sourceforge.net/projects/libpng/files/libpng12/older-releases/1.2.31/libpng-1.2.31.tar.gz/download
- cd/usr/local/src
- tar-zxvflibpng-1.2.31.tar.gz
- cdlibpng-1.2.31
- ./configure
- make
- makeinstall
4:安装libxml2
- wgethttp://xmlsoft.org/sources/old/libxml2-2.7.1.tar.gz
- cd/usr/local/src
- tar-xzvflibxml2-2.7.1.tar.gz
- cdlibxml2-2.7.1
- ./configure--prefix=/usr/local/libxml2--without-zlib 记得加上后面这句,不然会出错
- make
- makeinstall
5:安装libmcypt
- wgetftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
- cd/usr/local/src
- tarzxvflibmcrypt-2.5.7.tar.gz
- cdlibmcrypt-2.5。7
- ./configure--prefix=/usr/local/libmcrypt
- make
- makeinstall
6:安装gd2(php的gd库,压缩和处理图片会用到).
- wgethttp://google-desktop-for-linux-mirror.googlecode.com/files/gd-2.0.35.tar.gz
- cd/usr/local/src
- tar-zxvfgd-2.0.35.tar.gz
- mkdir-p/usr/local/gd
- cdgd-2.0.35
- ./configure--prefix=/usr/local/gd--enable-m4_pattern_allow--with-jpeg--with-png--with-zlib--with-freetype=/usr/local/freetype--with-libmcrypt=/usr/local/libmcrypt
- make
- makeinstal
–with-jpeg:使其支持jpeg图片处理,–with-png:支持png图片处理.
编译过程可能出现错误,就先编译安装下gettext:
- wgethttp://ftp.gnu.org/pub/gnu/gettext/gettext-0.18.3.1.tar.gz
- tarxzfgettext-0.17.tar.gz
- cdgettext-0.17
- ./configure
- make
- makeinstall
注意:gd库版本如果是gd-2.0.35以上,则需要 ./configure –enable-m4_pattern_allow或者编译安装 gettext组件后再重新编译gd
7:安装apr(Apache可移植运行库).
在这个地址http://mirror.bit.edu.cn/apache/apr/ 下载apr和apr-util
- cd/usr/local/src
- wgethttp://mirror.bit.edu.cn/apache/apr/apr-1.5.1.tar.gz
- tar-zxvfapr-1.5.1.tar.gz
- cdapr-1.5.1
- ./configure--prefix=/usr/local/apr
- make
- makeinstall
8:安装apr-util
- wgethttp://mirror.bit.edu.cn/apache/apr/apr-util-1.4.1.tar.gz
- tarzxvfapr-util-1.4.1.tar.gz
- cdapr-util-1.4.1
- ./configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr
- make
- makeinstall
9:安装openssl
wget ftp://ftp.openssl.org/source/openssl-1.0.1c.tar.gz #openssldir 是配置文件目录,建议安装两次,shared 作用是生成动态连接库.
- tar-zxfopenssl-1.0.1c.tar.gz
- cdopenssl-1.0.1c/
- ./config--prefix=/usr/local/openssl--openssldir=/usr/local/openssl/ssl
- make&&makeinstall
- ./configshared--prefix=/usr/local/openssl--openssldir=/usr/local/openssl/ssl
- makeclean
- make
- makeinstall
10:安装curl
- wgethttp://curl.haxx.se/download/curl-7.17.1.tar.gz
- tar-zxvfcurl-7.17.1.tar.gz
- cdcurl-7.17.1
- ./configure--prefix=/usr/local/curl
- make
- makeinstall
如果出现错误:
- curl.so-lz-lrt-Wl,-rpath-Wl,/usr/local/curl/lib
- ../lib/.libs/libcurl.so:undefinedreferenceto`ERR_remove_thread_state’
- collect2:ldreturned1exitstatus
- make[2]:***[curl]Error1
- make[2]:Leavingdirectory`/usr/local/src/curl-7.32.0/src’
- make[1]:***[all]Error2
- make[1]:Leavingdirectory`/usr/local/src/curl-7.32.0/src’
- make:***[all-recursive]Error1
建议安装旧点的版本,特别是如果openssl的版本是1.0以下.
二:安装httpd
- wgethttp://mirrors.cnnic.cn/apache//httpd/httpd-2.4.9.tar.gz
- tar-zxvfhttpd-2.4.9.tar.gz
- cdhttpd-2.4.9
- ./configure--prefix=/usr/local/apache--with-apr=/usr/local/apr--with-included-apr--with-apr-util=/usr/local/apr-util--with-ssl=/usr/local/openssl--enable-ssl=static--enable-so--enable-maintainer-mode--with-mpm=prefork--enable-rewrite=shared--enable-userdir--enable-vhost-alias=shared--enable-cgi--enable-cgid--enable-expires=shared--enable-mem-cache=shared--enable-disk-cache=shared--enable-cache=shared--enable-deflate--enable-modules=all--enable-mods-shared=all
- make//phpfensi.com
- makeinstall
- /usr/local/apache/bin/apachectl-kstart#启动httpd
- vim/usr/local/apache/conf/httpd.conf#编辑配置文件
找到:#ServerName www.example.com:80
修改为:ServerName localhost:80
找到:DirectoryIndex index.html
修改为:DirectoryIndex index.html index.php
找到:Options Indexes FollowSymLinks
修改为:Options FollowSymLinks #不显示目录结构
找到AllowOverride None
修改为:AllowOverride All #开启apache支持伪静态,注意有两处都做修改.
LoadModule rewrite_module modules/mod_rewrite.so #取消前面的注释,开启apache支持伪静态.
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd #加入到系统启动
vim /etc/init.d/httpd
在#!/bin/sh下面添加以下两行:
- #chkconfig:23451090
- #description:Activates/DeactivatesApacheWebServer
- chowndaemon.daemon-R/usr/local/apache/htdocs#更改默认项目目录所有者
- chmod700/usr/local/apache/htdocs-R#更改apache默认网站目录权限
- chkconfighttpdon#设置开机自动启动httpd
- /etc/init.d/httpdstart#启动httpd
- servicehttpdrestart#重启httpd
编译或者配置时可能会出现以下错误.
1:错误信息:
- httpd-2.4.4/support/ab.c:2271:undefinedreferenceto`TLSv1_1_client_method’
解决办法:这个是openssl的版本问题,版本低于1.0建议编译安装高版本的1.0.0c,然后编译安装apache时候加上–with-ssl=/usr/local/openssl 这个参数,问题解决.
2:错误信息:
- /usr/local/ssl/lib/libssl.a:couldnotreadsymbols:Badvalue
- collect2:ldreturned1exitstatus
- make[4]:***[mod_ssl.la]Error1
- make[4]:Leavingdirectory`/usr/local/src/httpd-2.4.9/modules/ssl’
- make[3]:***[shared-build-recursive]Error1
- make[3]:Leavingdirectory`/usr/local/src/httpd-2.4.9/modules/ssl’
- make[2]:***[shared-build-recursive]Error1
- make[2]:Leavingdirectory`/usr/local/src/httpd-2.4.9/modules’
- make[1]:***[shared-build-recursive]Error1
- make[1]:Leavingdirectory`/usr/local/src/httpd-2.4.9′
- make:***[all-recursive]Error1
解决办法:这段错误说明ssl方面的错误,需要重新编译.
a:编译时候没带上–with-ssl=/usr/local/openssl
b:带上了–with-ssl的参数,但是openssl编译的时候没有带上:fPIC这个参数
- PositionIndependentCodeisnecessaryforamodulelikemod_sslwhichmaygetplacedanywhereinmemoryatruntime.ItisnotnecessaryforthestandaloneOpenSSLtestprogram,whichiswhymaketestworkedOKwithout-fPIC.
3:错误信息:
error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory
解决办法:
因为我们加载的模块是 mod_ssl.so,到openssl目录的lib下发现有这两个库,如果要让mod_ssl.so找到这两个库必须将ssl/lib添加到 LD_LIBRARY_PATH变量下.
~/.bashrc(每次登录每次打开shell读取一次) ,
修改完用户的环境变量后不会马上生效,执行 source ~/.bashrc 使其生效,这样就可以启动apache了.
4:错误信息:
chkconfig httpd on后,利用service httpd start 出现错误:error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory
原因是:启动时候找不到库文件libssl.so.1.0.0,因为/usr/lib64(64位的用户库文件)没有这个文件.
解决办法:
利用ln 软链接去共用 /usr/local/openssl/lib 的库文件.
- ln-s/usr/local/openssl/lib/libssl.so.1.0.0/usr/lib64/libssl.so.1.0.0
- ln-s/usr/local/openssl/lib/libcrypto.so.1.0.0/usr/lib64/libcrypto.so.1.0.0
service httpd start 成功.
5:错误信息:
configure时候出现错误
configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.
解决办法:
因为:apache-2.2与新出的apache-2.4安装不同的地方在于,2.4版的已经不自带apr库,所以在安装apache-2.4之前,需要下载apr.
- cp-rfapr-1.4.4httpd-2.4.9/srclib/apr
- cp-rfapr-util-1.5.3httpd-2.4.9/srclib/apr-util
再configure 即可.
三:安装mysql
mysql官网:http://dev.mysql.com/downloads/ 下载源码包
groupadd mysql #添加mysql组
useradd -g mysql mysql -s /bin/false #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统.
- mkdir-p/usr/local/mysql#创建MySQL安装目录
- mkdir-p/usr/local/mysql/data#创建MySQL数据存放目录
- tarzxvfmysql-5.5.21.tar.gz
- cdmysql-5.5.21
- cmake.-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DMYSQL_DATADIR=/usr/local/mysql/data-DSYSCONFDIR=/etc-DMYSQL_UNIX_ADDR=/tmp/mysql.sock-DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_MYISAM_STORAGE_ENGINE=1-DENABLED_LOCAL_INFILE=1-DMYSQL_TCP_PORT=3306-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci-DWITH_DEBUG=0-DWITH_READLINE=1-DWITH_SSL=yes
- #(有时候会出现找不到/usr/local/mysql/data等警告,不管他,直接继续编译)
- make
- makeinstall
- cd/usr/local/mysql
- cp./support-files/my-huge.cnf/etc/my.cnf#提示文件存在的话直接覆盖
- vim/etc/my.cnf#在[mysqld]部分增加
- datadir=/usr/local/mysql/data#数据库存放路径
- ./scripts/mysql_install_db--basedir=/usr/local/mysql--datadir=/usr/local/mysql/data--user=mysql#生成mysql系统数据库
- cp./support-files/mysql.server/etc/rc.d/init.d/mysqld#把Mysql加入系统启动
- chmod755/etc/init.d/mysqld#增加执行权限
- chkconfigmysqldon#加入开机启动
- vim/etc/rc.d/init.d/mysqld#编辑
- basedir=/usr/local/mysql#MySQL程序安装路径
- datadir=/usr/lcoal/mysql/data#MySQl数据库存放目录
- servicemysqldstart#启动
- /usr/local/mysql/bin/mysql-uroot–p#登录mysql
- #安装成功后进行root用户密码修改:
- /usr/local/mysql/bin/mysqladmin-uroot-ppassword"新密码"#回车后提示输入旧密码,输入成功后密码修稿成功
- /etc/init.d/mysqldrestart#重启mysql,安装成功!
四:安装php
- wgethttp://cn2.php.net/get/php-5.3.27.tar.gz/from/ar2.php.net/mirror
- ./configure--prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc--with-apxs2=/usr/local/apache/bin/apxs--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--with-mysql-sock=/tmp/mysql.sock--with-gd--with-iconv--with-freetype-dir=/usr/local/freetype--with-jpeg-dir=/usr/local/jpeg9--with-png-dir=/usr/local/libpng--with-zlib--with-libxml-dir=/usr/local/libxml2--enable-xml--enable-discard-path--enable-magic-quotes--enable-safe-mode--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization--with-curlwrappers--enable-mbregex--enable-fastcgi--enable-force-cgi-redirect--enable-mbstring--enable-ftp--enable-gd-native-ttf--with-openssl--enable-pcntl--enable-sockets--with-xmlrpc--enable-zip--enable-soap--without-pear--with-gettext--with-mime-magic--enable-suhosin--enable-session--with-mcrypt
- make
- makeinstall
–with-jpeg-dir 使用yum安装的默认版本
configure配置的时候可能出现的问题:
checking for cURL in default path… not found
configure: error: Please reinstall the libcurl distribution -
因为:curl的dev包没有安装
解决办法:yum -y install curl-devel
make编译的时候可能出现的问题:
virtual memory exhausted: Cannot allocate memory
原因:编译过程是一个内存消耗较大的动作,内存吃紧,无法分配
解决办法:配置项加上 –disable-fileinfo这个参数,重新编译
- cpphp.ini-production/usr/local/php/etc/php.ini#复制php配置文件到安装目录
- rm-rf/etc/php.ini#删除系统自带的配置文件
- ln-s/usr/local/php/etc/php.ini/etc/php.ini#创建配置文件软链接
- vim/usr/local/php/etc/php.ini#编辑
找到:;open_basedir =
修改为:open_basedir = .:/tmp/ #防止php木马跨站
找到:;date.timezone =
修改为:date.timezone = PRC
找到:expose_php = On
修改为:expose_php = OFF #禁止显示php版本的信息
找到:display_errors = On
修改为:display_errors = OFF #关闭错误提示
wq!#保存 php安装完成
五:配置apache支持php
- vim/usr/local/apache/conf/httpd.conf#编辑apache配置文件
- 添加下面两行
- LoadModulephp5_modulemodules/libphp5.so
- AddHandlerapplication/x-httpd-php.php(注意:php.php这个点前面有一个空格)
- servicehttpdrestart#重启apache
- servicemysqldrestart#重启mysql
- cd/usr/local/apache/htdocsviindex.php#输入下面内容
- :wq!#保存
- [cclang="php"]
在客户端浏览器输入服务器IP地址,可以看到php等相关配置信息.
热门评论