nhenbei 发表于 2013-5-3 09:30:15

WEB服务器linux+apache+mysql+php LAMP源码环境搭建

本帖最后由 nhenbei 于 2013-5-3 09:31 编辑

WEB服务器linux+apache+mysql+php LAMP源码环境搭建Linux+Apache+Mysql+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度共同组成了一个强大的web应用程序平台。而从网站的流量上来说,70%以上的访问流量是LAMP来提供的,LAMP是最强大的网站解决方案。下面来看一下LAMP环境搭建的步骤。准备工具:apr-1.4.6.tar.gz apr-util-1.5.1.tar.gzhttpd-2.4.4.tar.bz2mysql-5.6.10.tar.gz cmake-2.8.10.2.tar.gzphp-5.4.3.tar.gz一.准备环境:我用的是Red Hat Enterprise Linux 5.4   eth0 192.168.126.129# mount /dev/cdrom/mnt/cdrom挂载光盘用yum检测开发环境# vim /etc/yum.repos.d/rhel-debuginfo.repo编辑yum客户端# yum grouplist检查开发环境说明:这里需要有这几个开发环境,我这里,环境已经具备了,要是没有这几个开发环境,       可以用yum groupinstall “开发环境名”即可,注意:yum安装软件包组时,多个单词的一定要加””二.安装按照httpdmysql   php的顺序依次安装1.安装apache其实关于apache的安装,本人前边的博客已有介绍# tar -zxvf apr-1.4.6.tar.gz -C /usr/local/src/# tar -zxvf apr-util-1.5.1.tar.gz -C /usr/local/src/# cd /usr/local/src/apr-1.4.6/# ./configure   --prefix=/usr/local/apr把apr安装到/usr/local/apr目录下#make#make install# cd ..# cd apr-util-1.5.1/# ./configure --with-apr=/usr/local/apr/bin/apr-1-config# make# cd# tar -jxvf httpd-2.4.4.tar.bz2 -C /usr/local/src/# cd /usr/local/src/httpd-2.4.4/# ./configure --prefix=/usr/local/apache--sysconfdir=/etc/httpd--enable-so   --enable-ssl--enable-rewrite--with-apr=/usr/local/apr/bin/apr-1-config   --with-apr-util=/usr/local/apr/bin/apu-1-config --with-pcre-with-z --enable-mpms-shared=all# make# make install#/usr/local/apache/man# vim /etc/man.config把apache的man手册添加到man路径方便查看apache的man手册为了防止系统调用apache的头文件include时找不到路径,可以做一个连接# ln -s /usr/local/apache/include/   /usr/include/apache为了更好的管理httpd,为其编辑一个启动脚本# cd /etc/init.d/# vim httpd脚本如下#!/bin/sh#set -xHTTPD='/usr/local/apache/bin/httpd'CONFFILE='/etc/httpd/httpd.conf'            #description: http server#chkconfig: 2345 88 60start(){      [ -f /var/lock/subsys/httpd ]&& echo "apache is started" && exit   echo -n"starting apache......"      sleep1}stop(){   [ ! -f/var/lock/subsys/httpd ] && echo "httpd is stoped..." && exit   echo -n "stoping httpd........"      sleep1   /bin/rm -rf /var/lock/subsys/httpd   $HTTPD -kstop&& RETVAL=0 ||RETVAL=1}case $1 instop(){   [ ! -f/var/lock/subsys/httpd ] && echo "httpd is stoped..." && exit   echo -n "stoping httpd........"      sleep1   /bin/rm -rf /var/lock/subsys/httpd   $HTTPD -kstop&& RETVAL=0 ||RETVAL=1   [ $RETVAL -eq 0 ] && rm -rf /var/lock/subsys/httpd && echo "ok" || echo "fail"}case $1 instart)      start      ;;stop)      stop      ;;restart)       stop       start      ;;*)      echo "start|stop|restart"      ;;esac# chmod a+x /etc/init.d/httpd# service httpd start# netstat -tupln |grep httptcp      0      0 :::80                     :::*# chkconfig --add httpd添加自启动# chkconfig --list|grep httphttpd         0:off 1:off 2:on 3:on 4:on 5:on 6:off2.安装mysql   cmake# tar zxvf mysql-5.6.10.tar.gz -C /usr/local/src/# cd /usr/local/src/mysql-5.6.10/# less INSTALL-SOURCEmysql的使用说明安装mysql的时候需要用到cmake工具安装cmake# tar -zxvf cmake-2.8.10.2.tar.gz -C /usr/local/src/# cd /usr/local/src/cmake-2.8.10.2/# ./configure   --prefix=/usr/local/cmake# make&& make installWaiting.......................# cd /usr/local/cmake/为了日后能快速访问cmake下的bin,把cmke下的bin添加路径# vim /etc/profile注意:只有下次进入之后路径才会添加成功# cd /usr/local/src/mysql-5.6.10/86:36# cmake .# make&&make installPleasewaitingforalong time。。。。。。。。。。。。。。。。。。。。。。。。。。# cd /usr/local/src/mysql-5.6.10/# less INSTALL-SOURCEMysql安装说明中的配置的步骤# cd /usr/local/mysql/创建帐号信息# groupadd mysql# useradd -r -g mysql mysql# chown -R mysql .进行初始化# scripts/mysql_install_db--user=mysql# chown -R root .# chown -R mysql data# cd support-files/# cp my-default.cnf   /etc/my.cnf# cp mysql.server   /etc/init.d/mysqld# chmod a+x/etc/init.d/mysqld# service mysqld startStarting MySQL.....                                        mysqld 服务成功启动# netstat -tupln |grep mysqldtcp      0      0 :::3306                     :::*      # cd ..# pwd/usr/local/mysql# vim /etc/profile重新登录一次# mysqlmysql> show databases;+--------------------+| Database         |+--------------------+| information_schema || mysql            || performance_schema || test               |+--------------------+4 rows in set (0.00 sec)# mysqladmin -u root -p password '123'设置一个管理员帐号密码123# mysql -u root -p以后就可以以此帐号登陆了mysql生成的/usr/local/mysql/lib库文件不是标准路径系统无法识别(/lib 或者/usr/lib为标准路径)所以需做如下配置# vim /etc/ld.so.conf.d/mysql.conf写入/usr/local/mysql/lib刷新ld.so.cache# ll /etc/ld.so.cache-rw-r--r-- 1 root root 81871 Apr 13 08:17 /etc/ld.so.cache# ldconfig# ll /etc/ld.so.cache-rw-r--r-- 1 root root 82128 Apr 13 15:46 /etc/ld.so.cache对mysql的头文件include做一个连接# ln -s /usr/local/mysql/include/   /usr/include/mysql3.安装php# tar -zxvf php-5.4.3.tar.gz -C /usr/local/src/# cd /usr/local/src/php-5.4.3/# ./configure --prefix=/usr/local/php--sysconfdir=/etc--with-apxs2=/usr/local/apache/bin/apxs --with-zlib   --with-gd--with-jpeg-dir--with-png-dir--enable-mbstring--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--enable-xml--with-freetype-dir# make&& make install# cd /usr/local/php/# vim /etc/profile# vim /etc/ld.so.conf.d/php.conf写入/usr/local/mysql/lib# ldconfig# ln -s include/usr/include/php# vim /etc/httpd/httpd.conf在apache的配置文件中会自动添加modules/libphp5.so模块# service httpd restart重启apache注意:若出现如下错误,可能是是Linux有一个SELinux保护模式引起的starting apache......httpd: Syntax error on line 147 of /etc/httpd/httpd.conf: Cannot load modules/libphp5.so into server: /usr/local/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission deniedFail可以进行如下操作1关闭SELINUX的方法:
vi /etc/selinux/config 将SELINUX=enforcing 改成SELINUX=disabled需要重启
这个方法可能会对服务器带来风险。2不关闭SELINUX的方法:
# 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# cd /usr/local/apache/htdocs      apache的默认站点目录三.测试1.测试apache浏览器输入http://192.168.126.1292.测试php# mv index.htmlindex.php把apache的测试页改为php# vim index.php刷新浏览器出现如下界面至此,apache和php完美结合了。。。3.测试php和mysql的结合是否成功# vim index.php刷新浏览器# service mysqld stop关闭mysqld服务时也显示正常到这里 apache 和mysql、php已经完美结合在了一起。linux+apache+mysql+php的web环境架构已经形成了

spell 发表于 2013-5-3 09:33:14

路过,支持一下啦

xy123321 发表于 2013-5-17 02:19:27

不在课堂上沉睡,就在酒桌上埋醉。

liyao20060101 发表于 2013-5-18 07:43:12

我是个凑数的。。。

trzxycx 发表于 2013-5-19 16:44:19

这是什么东东啊

buhong 发表于 2013-5-21 01:08:51

做爱做的事,交配交的人。

常青树 发表于 2013-5-22 07:50:58

我身在江湖,江湖里却没有我得传说。
页: [1]
查看完整版本: WEB服务器linux+apache+mysql+php LAMP源码环境搭建