LAMP源码包搭建

来源:互联网 发布:golang 1.8.3 编辑:程序博客网 时间:2024/06/10 15:14

一、LAMP大纲

第一步:装入apache

第二步:装入mysql

第三步:装入php

顺序不可乱

LAMP原理

                                                                         

Clients                                                    Html静态

-------------------àapache自己处理

                            -------à apache

                                                                   PHP动态

------------------à加载PHP模块进行处理

调用mysql,从mysql中拿取用户名和密码

二、apache安装步骤

2.1、安装APR主程序

##download apache source code

wget http://apache.etoak.com/httpd/httpd-2.4.3.tar.gz

wget http://apache.dataguru.cn/apr/apr-1.4.6.tar.bz2

wget http://labs.mop.com/apache-mirror/apr/apr-util-1.5.1.tar.bz2

 

APR(Apache portable Run-time librariesApache可移植运行库)的目的如其名称一样主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。

安装源码包的apache,APR必须装入,APR为apache的运行环境

 

tar fvxj apr-1.4.6.tar.bz2

./configure --prefix=/usr/local/apr

make

make install

 

2.2、安装APR-until库环境

tar fvxj apr-util-1.5.1.tar.bz2

./configure --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr/

make

make install

2.3、安装apache软件

##configure

tar fvxz httpd-2.4.3.tar.gz

yum install zlib-devel gcc gcc-c++ openssl-develpcre-devel -y

 

./configure--prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/--enable-module=so --enable-deflate=shared --enable-expires=shared--enable-rewrite=shared --enable-cache --enable-file-cache --enable-mem-cache--enable-disk-cache --enable-static-support --enable-static-ab--disable-userdir --with-mpm=prefork --enable-nonportable-atomics--disable-ipv6  --with-sendfile

指定apache运行的库环境,并禁用家目录

Make && make install

 

/usr/local/apache2/bin/apachectl-k start--------------启动apache

 

 

三、安装mysql

3.1、装mysql

install mysql

 

rpm -ivh /tmp/cmake-2.6.4-7.el5.i386.rpm

groupadd mysql

useradd -g mysql mysql

 

 

yum remove mysql-server mysql mysql-devel -y

yum install gcc gcc-c++ ncurses-devel libtoolopenssl-devel -y

 

cmake -H

mkdir -pv /usr/local/mysql/data

 

mysql souce code

1 mysql client

2 mysql server (disable) ??

3 mysql devel

cmake . \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/usr/local/mysql/data/ \

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \

-DWITH_INNODBBASE_STORAGE_ENGINE=1 \

-DENABLE_LOCAL_INFILE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DMYSQL_USER=mysql \

-DWITH_DEBUG=0 \

-DWITH_EMBEDED_SERVER=0

 

 

make

 

make install

 

cp support-files/my-innodb-heavy-4G.cnf /etc/my.cnf

 

跳过域名解析

vim /etc/my.cnf

skip-name-resolve=1

 

把二进制脚本程序复制到/etc/init.d/

cp support-files/mysql.server /etc/init.d/mysqlsource

修改二进制脚本权限

chmod 755 /etc/init.d/mysqlsource

修改二进制脚本的属主和属组为mysql

chown mysql.mysql /usr/local/mysql/ -R

#######################初始化mysql

sh scripts/mysql_install_db --user=mysql--basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

##error logmysql的错误日志

/usr/local/mysql/data/localhost.localdomain.err

 

##client login test--客户端登陆测试

ln -s /usr/local/mysql/bin/* /usr/bin/

ln -s /usr/local/mysql/lib/* /usr/lib/

ln -s /usr/local/mysql/libexec/*  /usr/local/libexec

ln -s /usr/local/mysql/share/man/man1/*  /usr/share/man/man1

ln -s /usr/local/mysql/share/man/man8/*  /usr/share/man/man8

 

##secure after install mysql的管理小工具

mysql_secure_installation

 

四、安装php

装入php运行所需环境库及其工具

yum install libxml2-devel bzip2-devel net-snmp-develcurl-devel libpng-devel freetype-devel libjpeg-devel zlib-devel -y

 

wgethttp://lnamp-web-server.googlecode.com/files/libiconv-1.14.tar.gz

此为文件转格式的工具

tar fvxz libiconv-1.14.tar.gz

./configure --prefix=/usr/local/--with-apr=/usr/local/apr

make

make install

 

 

wgethttp://lcmp.googlecode.com/files/libmcrypt-2.5.8.tar.gz

wgethttp://lcmp.googlecode.com/files/mhash-0.9.9.9.tar.gz

wget http://lcmp.googlecode.com/files/mcrypt-2.6.8.tar.gz

此为加密的一些工具,经测试,可正常安装

tar fvxz libmcrypt-2.5.8.tar.gz

yum -y install gcc-c++

./configure && make && make install&& /sbin/ldconfig

cd libltdl/

./configure --enable-ltdl-install && make&& make install

 

 

 

 

tar fvxz mhash-0.9.9.9.tar.gz

./configure && make && make install

ln -s /usr/local/lib/* /usr/lib/

ln -s /usr/local/bin/libmcrypt-config /usr/bin/

 

 

tar  fvxzmcrypt-2.6.8.tar.gz

./configure && make && make install

 

安装php

tar fvxj php-5.4.11.tar.bz2

 

./configure --prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql/--with-mysqli=/usr/local/mysql/bin/mysql_config--with-pdo-mysql=/usr/local/mysql --with-iconv-dir=/usr/local/ --enable-fpm--with-fpm-user=apache --with-fpm-group=apache --with-pcre-regex --with-zlib--with-bz2 --enable-calendar --disable-phar --with-curl --enable-dba--with-libxml-dir --enable-ftp --with-gd --with-jpeg-dir --with-png-dir--with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv--with-mhash --enable-mbstring --with-mcrypt --enable-pcntl --enable-xml--disable-rpath --enable-shmop --enable-sockets --enable-zip --enable-bcmath--with-snmp --disable-ipv6 --disable-rpath --disable-debug  --with-apxs2=/usr/local/apache2/bin/apxs

如果有Apache时,一定要加上这句,相当于把模块做到apache

#if bind to apache

--with-apxs2=/usr/local/apache2/bin/apxs

#if no mysql

./configure --with-mysql=mysqlnd --with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd

make ZEND_EXTRA_LIBS='-liconv'

 

make install

复制php的配置文件到/usr/local/php/etc/php.ini

cp php.ini-production /usr/local/php/etc/php.ini

 

安装完成后,还有两步:

第一:检测apache配置文件中是否自动生成php5模块,并添加一行php服务

vim /usr/local/apache2/conf/httpd.conf

本地图片,请重新上传

 

AddType application/x-httpd-php .php

第二:把首页文件给改成index.php

本地图片,请重新上传

cp php.ini-production /usr/local/php/etc/php.ini

 

重新启动apache mysql

Killall httpd

/etc/init.d/mysqlsource restart

客户端访问:

本地图片,请重新上传

五、apache报错大全

如果启动apache报错:

[root@localhost lib]#/usr/local/apache2/bin/apachectl restart

httpd: Syntax error on line 61 of/usr/local/apache2/conf/httpd.conf: Cannot load/usr/local/apache2/modules/mod_encoding.so into server: libiconv_hook.so.1:cannot open shared object file: No such file or directory

就要

    shell> vi /etc/ld.so.conf

加入

/usr/local/lib

    shell> ldconfig  //让路径起作用

如果重新起动APACHE出现:

Syntax error . line 232 of/usr/local/apache2/conf/httpd.conf: Cannot load/usr/local/apache2/modules/libphp5.so into server:

/usr/local/apache2/modules/libphp4.so:cannot restore segment prot after reloc: Permission denied

那就要按照下面的方法解决:

1.chcon -t texrel_shlib_t/usr/local/apache2/modules/*.so   

------------------------------

 

如果启动apache报错:

[root@localhost httpd]# cd/usr/local/apache2/bin/

[root@localhost bin]# ./apachectlstart

httpd: Syntax error on line 55 of/usr/local/apache2/conf/httpd.conf: Cannot load/usr/local/apache2/modules/libphp5.so into server: libmysqlclient.so.15: cannotopen shared object file: No such file or directory

 

解决办法让所有库自动给连5.0.84client lib

 

cd /usr/lib

ln -s /usr/local/mysql/lib/libmysqlclient.so.15libmysqlclient.so.15

ll | grep mysqls

 

 

1

启动 apachectl时出错,httpd.conf53行有语法错误.libphp5.so模块无法载入.

错误信息如下:

Syntax error on line 53 of/usr/local/apache2/conf/httpd.conf:

Can not load/usr/local/apache2/modules/libphp5.so  into server:

/usr/local/apache2/modules/libphp5.so:

Can't   restore  segment prot after reloc :  Permission   denied

解决: apache不能加载外挂php模块这是由SELinux的安全策略配置不当引起的.Fedora Core 的官方网站上有相关的Apache/SELinux的策略调整文档.如果嫌麻烦,可以直接修改/etc/selinux/configSELinux禁用.

(2)

 Syntax error on line 79 of/usr/local/httpd/conf/httpd.conf:

AddType requires at least   two arguments,a mime type followed by one ormore file extensions

解决要加空格

(3)

启动 httpdhttpd: Syntaxerror on line 210 of /etc/httpd/conf/httpd.conf: Syntax error on line 6 of/etc/httpd/conf.d/auth_mysql.conf: Cannot load/etc/httpd/modules/mod_auth_mysql.so into server: libmysqlclient.so.15: cannotopen shared object file: No such file or directory

[失败]

解决:看见上面的原因可能是我之前卸载rhel自带的mysql的过程中,强制卸载了一些依赖包,解决办法如下:

vi/etc/httpd/conf.d/auth_mysql.conf //进入相关文件,注释掉出错的第六行,解决OK

 

在设置的DocumentRoot目录下,添加一个phpinfo.php的文件来测试系统,程序代码如下:

<?

//filename: phpinfo.php

phpinfo();

?>

这时候在客户端浏览器中访问http://localhost/phpinfo.php应该出现php的参数表至此所有系统安装完毕。

 

4 测试时发现不能解析php,具体表现为页面空白,但可以解析html(就是能出来apache刚安装好后的提示那个)

解决:<?php

phpinfo();

?>

?后少加了后缀php。这是php.ini没有设置好的原因

; Allow the <? tag. Otherwise,only <?php and <script> tags are recognized.

; NOTE: Using short tags shouldbe avoided when developing applications or

; libraries that are meant forredistribution, or deployment on PHP

; servers which are not underyour control, because short tags may not

; be supported on the targetserver. For portable, redistributable code,

; be sure not to use short tags.

short_open_tag = Off

把这个设置为ON也可以解决。。。。。。

 

***************************************************************************

 

再个问题就是浏览器显示错误信息如下

 

Warning: Unknown: failed to openstream: Permission denied in Unknown on line 0 Fatal error: Unknown: Failedopening required '/usr/local/httpd/htdocs/phpinfo.php'(include_path='.:/usr/local/lib/php') in Unknown on line 0

 

 

问题的原因是 : 你的phpinfo.php文件在这个用户下不具有 可读的权限 通过 ls -l 查看 文件的权限 然后更改权限(添加读权限 chmod +r phpinfo.php)就不会出现这个问题了...

如果看到如图1的信息即表示成功了

-----------------------------------------------

/usr/local/apache2/bin/apachectlrestart

  如果碰到

     httpd:Syntax error on line 55 of /usr/local/apache2/conf/httpd.conf: Cannot load/usr/local/apache2/modules/libphp5.so into server:/usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc:Permission denied

  则需要运行

chcon -t textrel_shlib_t/usr/local/apache2/modules/*.so

  或者干脆关闭SELinux:

vi /etc/selinux/config

  把文件中的SELINUX="enforcing"改为disabled

setenforce 0   selinux生效

-----------------------------------------------------

如果出错::::::

------------------------------------------------

 

启动 apachectl时出错,httpd.conf53行有语法错误.libphp5.so模块无法载入.

 

错误信息如下:

 

Syntax error on line 53 of/usr/local/apache2/conf/httpd.conf:

 

Can not load/usr/local/apache2/modules/libphp5.so  into server:

 

/usr/local/apache2/modules/libphp5.so:

 

Can't   restore  segment prot after reloc :  Permission   denied

 

解决: apache不能加载外挂php模块这是由SELinux的安全策略配置不当引起的.Fedora Core 的官方网站上有相关的Apache/SELinux的策略调整文档.如果嫌麻烦,可以直接修改/etc/selinux/configSELinux禁用.

 

-------------------------------------------------------------------

 

 Syntax error on line 79 of/usr/local/httpd/conf/httpd.conf:

 

AddType requires at least   two arguments,a mime type followed by one ormore file extensions

解决要加空格

 

----------------------------------------------------------------------

 

启动 httpdhttpd: Syntaxerror on line 210 of /etc/httpd/conf/httpd.conf: Syntax error on line 6 of/etc/httpd/conf.d/auth_mysql.conf: Cannot load/etc/httpd/modules/mod_auth_mysql.so into server: libmysqlclient.so.15: cannotopen shared object file: No such file or directory

 

[失败]

解决:看见上面的原因可能是我之前卸载rhel自带的mysql的过程中,强制卸载了一些依赖包,解决办法如下:

 

vi/etc/httpd/conf.d/auth_mysql.conf //进入相关文件,注释掉出错的第六行,解决OK

 

在设置的DocumentRoot目录下,添加一个phpinfo.php的文件来测试系统,程序代码如下:

 

<?

 

//filename: phpinfo.php

 

phpinfo();

 

?>

这时候在客户端浏览器中访问http://localhost/phpinfo.php应该出现php的参数表至此所有系统安装完毕。

 

-----------------------------------------------------------

打开php测试页报错显示空白

测试时发现不能解析php,具体表现为页面空白,但可以解析html(就是能出来apache刚安装好后的提示那个)

 

解决:<?php

 

phpinfo();

 

?>

?后少加了后缀php。这是php.ini没有设置好的原因

 

; Allow the <? tag. Otherwise,only <?php and <script> tags are recognized.

 

; NOTE: Using short tags shouldbe avoided when developing applications or

 

; libraries that are meant forredistribution, or deployment on PHP

 

; servers which are not underyour control, because short tags may not

 

; be supported on the targetserver. For portable, redistributable code,

 

; be sure not to use short tags.

 

short_open_tag = Off

把这个设置为ON也可以解决。。。。。。

 

 

********************************************************************************************

 

再个问题就是浏览器显示错误信息如下

 

 

Warning: Unknown: failed to openstream: Permission denied in Unknown on line 0 Fatal error: Unknown: Failedopening required '/usr/local/httpd/htdocs/phpinfo.php'(include_path='.:/usr/local/lib/php') in Unknown on line 0

 

 

 

问题的原因是 : 你的phpinfo.php文件在这个用户下不具有 可读的权限 通过 ls -l 查看 文件的权限 然后更改权限(添加读权限 chmod +r phpinfo.php)就不会出现这个问题了...

 

0 0
原创粉丝点击