Centos5下LAMP环境安装

                  Centos5下LAMP环境安装

日期:2011年12月

 

 

作者:吴启超

 

 

联系方式:407802734

 

 

版本:2.0

 

 

 

文档更新记录

日期

作者

版本

备注说明

2012-03-22

韩军现

2. 1

增加安装过程中出现的问题和解决方案

 

 

 

 

 

 

 

 

注意:安装前请检查rpm包的mysql、php、apache是否存在

例如:rpm -qa | grep php 检查是否存在,如果存在请删除原来的服务,否则会安装后会出现我们安装的服务默认不起作用(删除 rpm –e php)

 

一.安装mysql5.1

Mysql5以上用cmake编译器,请保证系统cmake、 gcc 、gcc-c++可用

1.1将文件下载到本地

[root@localhost src]# cd /usr/local/src/

[root@localhost src]# wget http://down1.chinaunix.net/distfiles/mysql-5.1.59.tar.gz

 

 

2解压,安装

[root@localhost src]# tar zxvf mysql-5.1.59.tar.gz

[root@localhost mysql-5.1.59]# cd mysql-5.1.59

[root@localhost mysql-5.1.59]# ./configure -prefix=/usr/local/mysql

[root@localhost mysql-5.1.59]# make

[root@localhost mysql-5.1.59]# make install

[root@localhost mysql-5.1.59]# cp support-files/mysql.server /etc/init.d/mysql.server

[root@localhost mysql-5.1.59]# chmod a+x /etc/init.d/mysql.server

[root@localhost mysql-5.1.59]# cp support-files/my-medium.cnf /etc/my.cnf

 

3建mysql用户

[root@localhost src]# groupadd mysql

[root@localhost src]# useradd -g mysql mysql

 

我们先建立一个mysql和mysql用户来访问mysql:

建立mysql用户并且加入到mysql组中
建立用户后我们就初始化表 (注意:必须先执行本步骤后才能进行以下步骤)

安装初始化表数据库,即创建/usr/local/mysql/var 目录中权限表和测试数据表

[root@localhost ~]# /usr/local/mysql/bin/mysql_install_db --user=mysql

运行mysql

[root@localhost ~]# /usr/local/mysql/bin/mysqld_safe &

测试 是否正常运行

[root@localhost ~]# /usr/local/mysql/bin/mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.1.59-log Source distribution

修改密码并测试空密码是否还可用

[root@localhost ~]# /usr/local/mysql/bin/mysqladmin -u root password 'root'

[root@localhost ~]# /usr/local/mysql/bin/mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

写上用户密码进到mysql

[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -p

Enter password:

检测数据目录权限

检查端口:

 

查看相关设置,或者直接查看/etc/my.cnf

 

 

 

进到mysql shell添加远程用户:

mysql> grant all privileges on *.* to remote@"%" identified by 'remote';

退出mysql shell

[root@localhost mysql-5.1.59]# /etc/init.d/mysql.server restart

 

从远程连接测试,如果不能的话检查防火墙设置

 

 

 

二.安装apache2.2

 

1.1将文件下载到本地

[root@localhost src]# cd /usr/local/src/

[root@localhost src]# wget  wget http://down1.chinaunix.net/distfiles/httpd-2.2.21.tar.bz2

 

2解压,安装

[root@localhost src]# bzip2 -d httpd-2.2.21.tar.bz2

[root@localhost src]# tar xvf httpd-2.2.21.tar

[root@localhost src]# cd httpd-2.2.21

[root@localhost httpd-2.2.21]# ./configure-prefix=/usr/local/apache --enable-so --enable-rewrite --enable-dav --enable-mods-shared=all

[root@localhost httpd-2.2.21]# make

[root@localhost httpd-2.2.21]# make install clean

 

3启动

[root@localhost httpd-2.2.21]# /usr/local/apache/bin/apachectl start

打开http://192.168.56.101/ 出现it works 表示正确

 

 

三.安装php

3.1将文件下载到本地

[root@localhost src]# cd /usr/local/src/

[root@localhost src]# wget http://down1.chinaunix.net/distfiles/php-5.2.10.tar.bz2

 

图片扩展

[root@localhost src]# ./configure --prefix=/usr/local/freetype

[root@localhost src]# make && make install

 

[root@localhost src]# cd libpng-1.4.4

[root@localhost libpng-1.4.4]# cp scripts/makefile.std makefile

[root@localhost libpng-1.4.4]# make && make install

 

[root@localhost jpeg]# ./configure  --prefix=/usr/local/jpeg --enable-shared

[root@localhost jpeg]# make && make install

 

[root@localhost 2.0.35]# ./configure

--prefix=/usr/local/gd2 

--with-png

--with-freetype=/usr/local/freetype/

--with-zlib

加密扩展

[root@localhost libmcrypt-2.5.7]# ./configure --prefix=/usr/local/libmcrype

[root@localhost libmcrypt-2.5.7]# make && make install

 

[root@localhost curl-7.19.6]# ./configure --prefix=/usr/local/curl

[root@localhost curl-7.19.6]# make && make install

 

3.2解压,安装

[root@localhost src]# bzip2 -d php-5.2.10.tar.bz2

[root@localhost src]# tar vxf php-5.2.10.tar

[root@localhost src]# cd php-5.2.10

[root@localhost php-5.2.10]# ./configure

--prefix=/usr/local/php

--with-mysql=/usr/local/mysql 

--with-mysqli=/usr/local/mysql/bin/mysql_config

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

--with-curl=/usr/local/curl

--with-libxml-dir=/usr/include/libxml2

--with-gd=/usr/local/gd2/

--with-jpeg-dir=/usr/local/jpeg/

--with-zlib-dir=/usr/lib

--with-png-dir

--with-freetype-dir=/usr/local/freetype 

-with-mcrypt=/usr/local/libmcrype

--with-zlib-dir=/usr/local/zlib

--enable-soap

--enable-sockets

--enable-pcntl

--enable-mbstring

--enable-ftp

--without-pear

 

 

[root@localhost php-5.2.10]# make && make install clear

[root@localhost php-5.2.10]# cp php.ini-dist /usr/local/php/lib/php.ini

 

3.3查看是否可用

[root@localhost php-5.2.10]# /usr/local/php/bin/php  -v

[root@localhost php-5.2.10]# /usr/local/php/bin/php -r 'echo 3+4;'

[root@localhost php-5.2.10]# /usr/local/php/bin/php  --re mysql

 

.配置结合 

#[root@localhost php-5.2.10]# vi /usr/local/apache/conf/httpd.conf

*在LoadModule处添加

LoadModule php5_module module/libphp5.so

*在DirectoryIndex处添加

index.php

*在AddType application处添加
AddType application/x-httpd-php .php .phtml
# AddType applicatoin/x-httpd-php-source .phps

 

 

QA:

A安装编译安装cmake 报错

1.  [root@localhost ~]# cd /usr/local/src/

2.  [root@localhost src]# tar xzvf cmake-2.8.4.tar.gz

3.  [root@localhost src]# cd cmake-2.8.4

4.  [root@localhost cmake-2.8.4]# ./bootstrap

5.  ---------------------------------------------

6.  CMake 2.8.4, Copyright 2000-2009 Kitware, Inc.

7.  ---------------------------------------------

8.  Error when bootstrapping CMake:

9.  Cannot find appropriate C compiler on this system.

10. Please specify one using environment variable CC.

11. See cmake_bootstrap.log for compilers attempted.

12.  

13. ---------------------------------------------

14. Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log

15. ---------------------------------------------

报错:缺少C的编译器。

解决办法:安装gcc编译器

1.  yum install gcc

1.  [root@localhost cmake-2.8.4]# ./bootstrap

2.  ---------------------------------------------

3.  CMake 2.8.4, Copyright 2000-2009 Kitware, Inc.

4.  C compiler on this system is: cc

5.  ---------------------------------------------

6.  Error when bootstrapping CMake:

7.  Cannot find appropriate C++ compiler on this system.

8.  Please specify one using environment variable CXX.

9.  See cmake_bootstrap.log for compilers attempted.

10. ---------------------------------------------

11. Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log

12. ---------------------------------------------

报错:缺少C++编译器。
安装gcc-c++编译器

1.  yum install gcc-c++

B安装mysql ./configure时候报错:

checking for tgetent in -lncursesw... no
checking for tgetent in -lncurses... no
checking for tgetent in -lcurses... no
checking for tgetent in -ltermcap... no
checking for tgetent in -ltinfo... no
checking for termcap functions library... configure: error: No curses/termcap library found

 

说明 curses/termcap 库没有安装

解决办法:去下载一个ncurses-5.6.tar.gz,
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz
tar zxvf ncurses-5.6.tar.gz
cd ncurses-5.6
./configure –prefix=/usr –with-shared –without-debug
make
make install clean
然后再重新编译Mysql进行安装。

C安装编译安装cmake 报错

1.  [root@localhost ~]# cd /usr/local/src/

2.  [root@localhost src]# tar xzvf cmake-2.8.4.tar.gz

3.  [root@localhost src]# cd cmake-2.8.4

4.  [root@localhost cmake-2.8.4]# ./bootstrap

5.  ---------------------------------------------

6.  CMake 2.8.4, Copyright 2000-2009 Kitware, Inc.

7.  ---------------------------------------------

8.  Error when bootstrapping CMake:

9.  Cannot find appropriate C compiler on this system.

10. Please specify one using environment variable CC.

11. See cmake_bootstrap.log for compilers attempted.

12.  

13. ---------------------------------------------

14. Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log

15. ---------------------------------------------

复制代码

报错:缺少C的编译器。

解决办法:安装gcc编译器

1.  yum install gcc

 

安装apache可能遇到的问题:

1.

configure 错误提示:

checking whether to enable mod_deflate... configure: error: mod_deflate has been requested but can not be built due to prerequisite failures

解决办法:

zlib-devel 没装的原因

yum install gcc zlib-devel openssl-devel(装这个package会有一堆关联包装上)

====debian 中的包 apt-get install zlib1g-dev

2

no SSL-C headers found

configure: error: ...No recognized SSL/TLS toolkit detected

解决办法:

httpd-2.2.8# aptitude install python-openssl

aptitude install libssl-dev

3

configure: error: no XML parser was found: expat or libxml 2.x required

configure failed for neon

解决办法:

# aptitude install libxml2-dev

编译安装PHP5.2.10过程中出现的错误,及解决办法。

1

错误: configure: error: libevent >= 1.4.11 could not be found
解决: yum -y install libevent libevent-devel

2

错误: configure: error: xml2-config not found. Please check your libxml2 installation.

解决: yum -y install libxml2 libxml2-devel

3错误: configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决: yum install libmcrypt libmcrypt-devel

4

错误: configure: error: Please reinstall the libcurl distribution –

easy.h should be in <curl-dir>/include/curl/

解决: yum -y install curl-devel

5

错误: If configure fails try --with-jpeg-dir=

configure: error: libpng.(a|so) not found.

解决: yum -y install libpng-devel

6

错误: /usr/bin/ld: cannot find –lltdl

collect2: ld returned 1 exit status

解决: yum -y install libtool-ltdl-devel

安装PHP5.2.10后出现的错误,及解决办法。

1、[root@localhost php-5.2.10]# /usr/local/php/bin/php –v

错误: /usr/local/php/bin/php: error while loading shared libraries: /usr/local/gd2/lib/libgd.so.2: cannot restore segment prot after reloc: Permission denied

解决:

1、 chcon -t textrel_shlib_t /usr/local/gd2/lib/libgd.so.2(首选)

2、 # setenforce 0
# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache/modules/libphp5.so
# service httpd restart
# setenforce 1

3、 略

重启apache后出现的错误,及解决办法。

    1、[root@localhost php-5.2.10]#  /usr/local/php/bin/php -r 'echo 3+4;'

7[root@localhost php-5.2.10]# /usr/local/apache/bin/apachectl start

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

    解决:chcon -t textrel_shlib_t /usr/local/apache/modules/libphp5.so

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值