lamp环境搭建|LAMP 源码编译安装 (Apache MySQL5.5.21 PHP5.3.10)

时间:2019-10-13  来源:apache  阅读:


一:安装相关依赖组件

先yum安装基本的依赖组件:

yum install make apr* autoconf automake gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch --disable-fileinfo

(yum安装过后基本的组件已安好,以下编译安装可以安装最新版的组件)

1:安装zlib

zlib 官网:http://zlib.net


wget http://zlib.net/zlib-1.2.8.tar.gz
tar -xvzf zlib-1.2.8.tar.gz
cd zlib-1.2.7.tar.gz
./configure
make
make install

2:安装freetype


wget http://download.savannah.gnu.org/releases/freetype/freetype-2.5.0.1.tar.gz
cd /usr/local/src
tar -zxvf freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure --prefix=/usr/local/freetype
make
make install
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] Error 1
解决办法:
./configure –prefix=/usr/local/freetype –without-png(加上这个选项就行了)

3:安装libpng

wget http://sourceforge.net/projects/libpng/files/libpng12/older-releases/1.2.31/libpng-1.2.31.tar.gz/download
cd /usr/local/src
tar -zxvf libpng-1.2.31.tar.gz
cd libpng-1.2.31
./configure
make
make install

4:安装libxml2

wget http://xmlsoft.org/sources/old/libxml2-2.7.1.tar.gz
cd /usr/local/src
tar -xzvf libxml2-2.7.1.tar.gz
cd libxml2-2.7.1
./configure --prefix=/usr/local/libxml2 --without-zlib (记得加上后面这句,不然会出错)
make
make install

5:安装libmcypt

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
cd /usr/local/src
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5。7
./configure --prefix=/usr/local/libmcrypt
make
make install

6:安装gd2(php的gd库,压缩和处理图片会用到)

wget http://google-desktop-for-linux-mirror.googlecode.com/files/gd-2.0.35.tar.gz
cd /usr/local/src
tar -zxvf gd-2.0.35.tar.gz
mkdir -p /usr/local/gd
cd gd-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
make instal
(–with-jpeg:使其支持jpeg图片处理;–with-png:支持png图片处理)
编译过程可能出现错误:
就先编译安装下gettext


wget http://ftp.gnu.org/pub/gnu/gettext/gettext-0.18.3.1.tar.gz
tar xzf gettext-0.17.tar.gz
cd gettext-0.17
./configure
make
make install

注意: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
wget http://mirror.bit.edu.cn/apache/apr/apr-1.5.1.tar.gz
tar -zxvf  apr-1.5.1.tar.gz
cd apr-1.5.1
./configure --prefix=/usr/local/apr
make
make install

8:安装apr-util

wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.4.1.tar.gz
tar zxvf apr-util-1.4.1.tar.gz
cd apr-util-1.4.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install

9:安装openssl

wget ftp://ftp.openssl.org/source/openssl-1.0.1c.tar.gz  #openssldir 是配置文件目录,建议安装两次,shared 作用是生成动态连接库。
tar -zxf openssl-1.0.1c.tar.gz
cd openssl-1.0.1c/
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl/ssl
make && make install
./config shared --prefix=/usr/local/openssl --openssldir=/usr/local/openssl/ssl
make clean
make
make install

10:安装curl


wget http://curl.haxx.se/download/curl-7.17.1.tar.gz
tar -zxvf curl-7.17.1.tar.gz
cd curl-7.17.1
./configure --prefix=/usr/local/curl
make
make install
如果出现错误:
curl.so -lz -lrt -Wl,-rpath -Wl,/usr/local/curl/lib
../lib/.libs/libcurl.so: undefined reference to `ERR_remove_thread_state’
collect2: ld returned 1 exit status
make[2]: *** [curl] Error 1
make[2]: Leaving directory `/usr/local/src/curl-7.32.0/src’
make[1]: *** [all] Error 2
make[1]: Leaving directory `/usr/local/src/curl-7.32.0/src’
make: *** [all-recursive] Error 1
建议安装旧点的版本,特别是如果openssl的版本是1.0以下

二:安装httpd

wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.9.tar.gz
tar -zxvf httpd-2.4.9.tar.gz
cd httpd-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
make install
/usr/local/apache/bin/apachectl -k start  #启动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:2345 10 90
#description:Activates/Deactivates Apache Web Server

chown daemon.daemon -R /usr/local/apache/htdocs #更改默认项目目录所有者
chmod 700 /usr/local/apache/htdocs -R #更改apache默认网站目录权限
chkconfig httpd on #设置开机自动启动httpd
/etc/init.d/httpd start #启动httpd
service httpd restart #重启httpd

编译或者配置时可能会出现以下错误:

1:错误信息:

httpd-2.4.4/support/ab.c:2271: undefined reference to `TLSv1_1_client_method’

解决办法:

这个是openssl的版本问题,版本低于1.0建议编译安装高版本的1.0.0c,然后编译安装apache时候加上–with-ssl=/usr/local/openssl 这个参数,问题解决

2:错误信息:

/usr/local/ssl/lib/libssl.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[4]: *** [mod_ssl.la] Error 1
make[4]: Leaving directory `/usr/local/src/httpd-2.4.9/modules/ssl’
make[3]: *** [shared-build-recursive] Error 1
make[3]: Leaving directory `/usr/local/src/httpd-2.4.9/modules/ssl’
make[2]: *** [shared-build-recursive] Error 1
make[2]: Leaving directory `/usr/local/src/httpd-2.4.9/modules’
make[1]: *** [shared-build-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/httpd-2.4.9′
make: *** [all-recursive] Error 1

解决办法:

这段错误说明ssl方面的错误,需要重新编译
a:编译时候没带上–with-ssl=/usr/local/openssl
b:带上了–with-ssl的参数,但是openssl编译的时候没有带上:fPIC这个参数
Position Independent Code is necessary for a module like mod_ssl which may get placed anywhere in memory at runtime. It is not necessary for the standalone OpenSSL test program, which is why make test worked OK without -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 -rf apr-1.4.4 httpd-2.4.9/srclib/apr
cp -rf apr-util-1.5.3 httpd-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数据存放目录
tar zxvf mysql-5.5.21.tar.gz
cd mysql-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
make install

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加入系统启动
chmod 755 /etc/init.d/mysqld #增加执行权限
chkconfig mysqld on #加入开机启动
vim /etc/rc.d/init.d/mysqld #编辑
basedir = /usr/local/mysql #MySQL程序安装路径
datadir = /usr/lcoal/mysql/data #MySQl数据库存放目录
service mysqld start #启动
/usr/local/mysql/bin/mysql -u root –p # 登录mysql

#安装成功后进行root用户密码修改:
/usr/local/mysql/bin/mysqladmin -u root -p password "新密码" #回车后提示输入旧密码,输入成功后密码修稿成功
/etc/init.d/mysqld restart #重启mysql,安装成功!

四:安装php

wget http://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
make install
(–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这个参数,重新编译


cp php.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配置文件

添加下面两行

LoadModule php5_module        modules/libphp5.so
AddHandler application/x-httpd-php .php  (注意:php .php这个点前面有一个空格)
service httpd restart    #重启apache
service mysqld restart   #重启mysql
cd  /usr/local/apache/htdocsvi  index.php   #输入下面内容
:wq! #保存
[cc lang="php"]
在客户端浏览器输入服务器IP地址,可以看到php等相关配置信息!

lamp环境搭建|LAMP 源码编译安装 (Apache MySQL5.5.21 PHP5.3.10)

http://m.bbyears.com/jiaocheng/72917.html

推荐访问:lamp一键安装包 lampp lamp法 lamp1 lamp架构 lampo lamp是什么意思
相关阅读 猜你喜欢
本类排行 本类最新