设为首页 收藏本站
查看: 947|回复: 0

LAMP服务的搭建

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-4-11 09:47:52 | 显示全部楼层 |阅读模式
LAMP平台的搭建:

    系统环境:Centos6.5

一、配置系统环境

1 ) 关闭防火墙

    关闭Selinux

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

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

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

   # yum -y install  gcc  gcc-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)标准的编译过程

   [iyunv@localhost LAMP]# tar -xvfhttpd-2.2.25.tar.gz

   [iyunv@localhost LAMP]# cd httpd-2.2.25

   [iyunv@localhost httpd-2.2.25]#./configure--prefix=/usr/local/http2 --enable-so  --enable-rewrite  --enable-cgi  --enable-charset-list  --enable-ssl

   [iyunv@localhost httpd-2.2.25]#make

   [iyunv@localhost httpd-2.2.25]#make install

  

  3) 开启服务

   #/usr/local/apache2/bin/apachectl  start|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

  安装

  [iyunv@localhost LAMP]# tar -xvfmysql-5.1.62.tar.gz

  [iyunv@localhost LAMP]# cd mysql-5.1.62

  [iyunv@localhost mysql-5.1.62]# ./configure--prefix=/usr/local/mysql2 --sysconfdir=/etc --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312

  [iyunv@localhost mysql-5.1.62]# make

  [root@localhostmysql-5.1.62]# make install



3)数据库初始化

   [iyunv@localhost mysql2]# cd/usr/local/mysql2/bin/

   [iyunv@localhost bin]# ./mysql_install_db--user=mysql

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



4)创建主配置文件

   [iyunv@localhost LAMP]# cd  mysql-5.1.62/support-files/

   [iyunv@localhost support-files]# cp  my-medium.cnf  /etc/my.cnf



5)启动服务

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



6)停止服务

  #kill  -9   %1

  #pkill   -9  mysqld

查看端口

netstat -anptul | grep :3306



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

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

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

  # cd /usr/local/mysql2/bin/

  #[iyunv@localhost 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)安装

  [iyunv@localhost LAMP]# tar -xvfphp-5.4.19.tar.gz

  [iyunv@localhost LAMP]# cd php-5.4.19

  [iyunv@localhost 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

  [iyunv@localhost php-5.4.19]#make

  [iyunv@localhost php-5.4.19]#make install

3)建立配置文件

  [iyunv@localhostLAMP]#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、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-202447-1-1.html 上篇帖子: 基于centOS6.7搭建LAMP(httpd-2.4.18+mysql-5.5.47+php-5.6.16)环境 下篇帖子: LNMP一键安装shell脚本(v1.2)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表