9870780 发表于 2016-4-11 09:47:52

LAMP服务的搭建

LAMP平台的搭建:

    系统环境:Centos6.5

一、配置系统环境

1 ) 关闭防火墙

    关闭Selinux

2 ) 配置yum源,安装开发工具软件包组

   # yum -y groupinstall "DevelopmentLibraries" "Development Tools"

3 ) # rpm   -qgcc   gcc-c++   make

   # yum -y installgccgcc-c++   make

4 ) 移除冲突软件,卸载自带的LAMP组件,避免与编译安装版共存,易造成混淆

   # yum -y remove httpd mysql-server php

   # rm -rf /etc/my.cnf/var/lib/mysql   //清理干扰文档


二、安装相关软件

1.编译安装Apache HTTP Server

软件版本:httpd-2.2.25.tar.gz

1)安装功能依赖包

   # yum -y install openssl-devel                                                         



2)标准的编译过程

   # tar -xvfhttpd-2.2.25.tar.gz

   # cd httpd-2.2.25

   #./configure--prefix=/usr/local/http2 --enable-so--enable-rewrite--enable-cgi--enable-charset-list--enable-ssl

   #make

   #make install



3) 开启服务

   #/usr/local/apache2/bin/apachectlstart|stop


4)提供启动脚本

   # vi/etc/httpd/httpd.conf                                                                        

   PidFile "/var/run/httpd.pid"

   提供httpd 的SysV服务脚本/etc/rc.d/init.d/httpd,内容如下:

#/etc/rc.d/init.d/httpd

#!/bin/bash

# httpd Startup script for the Apache HTTP Server

# chkconfig: - 85 15

# description: Apache is a World Wide Web server. It is used to serve \

# HTML files and CGI.

# processname: httpd

# config: /etc/httpd/conf/httpd.conf

# config: /etc/sysconfig/httpd

# pidfile: /var/run/httpd.pid

# Source function library.

. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then

. /etc/sysconfig/httpd

fi

# Start httpd in the C locale by default.

HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if

# mod_ssl needs a pass-phrase from the user.

INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server

# with the thread-based "worker" MPM; BE WARNED that some modules may not

# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.

apachectl=/usr/local/apache2/bin/apachectl

httpd=${HTTPD-/usr/local/apache2/bin/httpd}

prog=httpd

pidfile=${PIDFILE-/var/run/httpd.pid}

lockfile=${LOCKFILE-/var/lock/subsys/httpd}

RETVAL=0

start() {

echo -n $"Starting $prog: "

LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS

RETVAL=$?

echo

[ $RETVAL = 0 ] && touch ${lockfile}

return $RETVAL

}

stop() {

echo -n $"Stopping $prog: "

killproc -p ${pidfile} -d 10 $httpd

RETVAL=$?

echo

[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}

}

reload() {

echo -n $"Reloading $prog: "

if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then

RETVAL=$?

echo $"not reloading due to configuration syntax error"

failure $"not reloading $httpd due to configuration syntax error"

else

killproc -p ${pidfile} $httpd -HUP

RETVAL=$?

fi

echo

}

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

status)

status -p ${pidfile} $httpd

RETVAL=$?

;;

restart)

stop

start

;;

condrestart)

if [ -f ${pidfile} ] ; then

stop

start

fi

;;

reload)

reload

;;

graceful|help|configtest|fullstatus)

$apachectl $@

RETVAL=$?

;;

*)

echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"

exit 1

esac

exit $RETVAL


# chmod +x /etc/rc.d/init.d/httpd                                                         
# chkconfig --add httpd                                                                  
# chkconfig httpd on                                                                     
# service httpd start                                                                     



5) 测试

    echo 123>/usr/local/httpd2/htdocs/a.html

    elinks--dump http://192.168.2.100/a.html


注:安装报错的可能

安装报错1:

configure: error: Cannotuse an external APR with the bundled APR-util

根据错误信息进行解决

安装apr和apr-util

cdhttpd-2.2.25/srclib/apr

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

make && makeinstall

cd ../apr-util

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

make && makeinstall

再安装apache就可以了加入参数(--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util)即可


安装报错2

noSSL-C headers found

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

#yum -y install openssl-devel


2.安装Mysql

1) 检查是否有mysql用户,检查3306端口是否被占

   #grep mysql/etc/passwd

   #useradd -M-s /sbin/nologin   mysql

   #netstat -untalp| grep   :3306

2) 安装

安装依赖包

yum -y install compat-libtermcap

yum -y install ncurses-devel



# rpm -qa| grep -i curses

ncurses-libs-5.7-3.20090208.el6.x86_64

ncurses-5.7-3.20090208.el6.x86_64

ncurses-base-5.7-3.20090208.el6.x86_64

checking for termcap functions library... configure: error:No curses/termcap library found

# yum -y install/misc/Packages/ncurses-*

# ls/misc/cd/Packages | grep curses

或者yum list | grepcurses

安装

# tar -xvfmysql-5.1.62.tar.gz

# cd mysql-5.1.62

# ./configure--prefix=/usr/local/mysql2 --sysconfdir=/etc --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312

# make

[root@localhostmysql-5.1.62]# make install



3)数据库初始化

   # cd/usr/local/mysql2/bin/

   # ./mysql_install_db--user=mysql

   # ls /usr/local/mysql2/var/mysql//数据库目录:    安装目录/var/



4)创建主配置文件

   # cdmysql-5.1.62/support-files/

   # cpmy-medium.cnf/etc/my.cnf



5)启动服务

# /usr/local/mysql2/bin/mysqld_safe   --user=mysql &



6)停止服务

#kill-9   %1

#pkill   -9mysqld

查看端口

netstat -anptul | grep :3306



7)登录数据库服务器(默认数据库管理员从数据库服务器本机登录没有密码)

/usr/local/mysql2/bin/mysql   -uroot-p

设置数据库管理员从数据库服务器本机登录的密码

# cd /usr/local/mysql2/bin/

## ./mysqladmin -uroot -ppassword "123"//重新设置密码

重新测试

/usr/local/mysql2/bin/mysql   -uroot-p

/usr/local/mysql2/bin/mysql   -uroot-p123



3.编译安装PHP,连接A、M组件

1)功能依赖包

   #yum -y install libxml2-devel

   onfigure:error: xml2-config not found. Please check your libxml2 installation.

   rpm -q libxml2

# yumlist | grep -i libxml2

# yum -yinstall libxml2-devel

主要的几个配置选项

   --enable-mbstring    //启用多字节支持

   --enable-sockets   //启用套接支持

   --with-apxs2      //指定httpd的支持模块路径

   --with-mysql      //启用MySQL驱动

2)安装

# tar -xvfphp-5.4.19.tar.gz

# cd php-5.4.19

#./configure--prefix=/usr/local/php2 --with-mysql=/usr/local/mysql2--with-apxs2=/usr/local/apache2/bin/apxs--with-config-file-path=/usr/local/php5/etc --with-gd

#make

#make install

3)建立配置文件

#cp php-5.4.19/php.ini-production /usr/local/php2/etc/php.ini      

4)调整httpd.conf配置文件

# vim vim/etc/httpd/httpd.conf

①添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
②定位至DirectoryIndexindex.html

修改为:
DirectoryIndex index.php index.html

①添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
②定位至DirectoryIndexindex.html

修改为:
DirectoryIndex index.php index.html

③测试php安装是否成功。
# cd /usr/local/apache2/htdocs                                                                                                                                    
# mv index.html index.php                                                                                                                                          
# vim index.php                                                                                                                                                         
<?php
phpinfo();
?>
   保存退出后,将httpd服务重新启动: service httpd restart或者 reload让其重新载入配置文件即可测试php是否已经可以正常使用。

6)测试php连接mysql数据库服务器

# vim htdocs/link.php

<?php

$linkdb=mysql_connect("localhost","root","123456");

if($linkdb){

    echo"1";

}else{

   echo"0";

}

?>


#elinks--dump http://192.168.2.100/link.php


页: [1]
查看完整版本: LAMP服务的搭建