link 发表于 2013-3-15 09:21:40

构建LAMP网站平台的安装全过程

本帖最后由 link 于 2013-3-15 09:24 编辑

准备实验环境:


两台虚拟机:


第一台做DNS服务器解析域名。


第二台做LAMP网站服务平台。


搭建DNS服务:


1、配置IP地址


# ifconfig
eth0      Link encap:EthernetHWaddr 00:0C:29:26:05:59
          inet addr:1.1.1.1Bcast:1.1.1.255Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe26:559/64 Scope:Link
          UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
          RX packets:35 errors:0 dropped:0 overruns:0 frame:0
          TX packets:76 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:7326 (7.1 KiB)TX bytes:12588 (12.2 KiB)
          Interrupt:59 Base address:0x2024


lo      Link encap:Local Loopback
          inet addr:127.0.0.1Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNINGMTU:16436Metric:1
          RX packets:12 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:900 (900.0 b)TX bytes:900 (900.0 b)


2、安装BIND相关软件包


# mount -o loop /dev/cdrom /media/
# cd /media/Server/
# rpm -ivh bind-9.3.6-4.P1.el5_4.2.i386.rpm
error: failed to stat /media/RHEL_5.5 i386 DVD: 没有那个文件或目录
Preparing...                ###########################################
   1:bind                   ###########################################
# rpm -ivh caching-nameserver-9.3.6-4.P1.el5_4.2.i386.rpm
error: failed to stat /media/RHEL_5.5 i386 DVD: 没有那个文件或目录
Preparing...                ###########################################
   1:caching-nameserver   ###########################################
# rpm -ivh bind-chroot-9.3.6-4.P1.el5_4.2.i386.rpm
error: failed to stat /media/RHEL_5.5 i386 DVD: 没有那个文件或目录
Preparing...                ###########################################
   1:bind-chroot            ###########################################
# rpm -ivh bind-utils-9.3.6-4.P1.el5_4.2.i386.rpm
error: failed to stat /media/RHEL_5.5 i386 DVD: 没有那个文件或目录
Preparing...                ###########################################
      package bind-utils-9.3.6-4.P1.el5_4.2.i386 is already installed


3、通过模板修改主配置文件


# cd /var/named/chroot/etc/
# cp -p named.caching-nameserver.conf named.conf
# vim named.conf


options {
      listen-on port 53 { any; };
      listen-on-v6 port 53 { ::1; };
      directory       "/var/named";
      dump-file       "/var/named/data/cache_dump.db";
      statistics-file "/var/named/data/named_stats.txt";
      memstatistics-file "/var/named/data/named_mem_stats.txt";


      allow-query   { any; };
      allow-query-cache { any; };
};
logging {
      channel default_debug {
                file "data/named.run";
                severity dynamic;
      };
};
view localhost_resolver {
      match-clients      { any; };
      match-destinations { any; };
      recursion yes;
      include "/etc/named.rfc1912.zones";
};


4、修改区域文件


# vim named.rfc1912.zones


zone "" IN {
      type master;
      file "yunvn.com.zone";
      allow-update { none; };
};


zone "csdn.com" IN {
      type master;
      file "csdn.com.zone";
      allow-update { none; };
};


5、通过模板、修改正向解析文件(反向解析不用做。)


# cd /var/named/chroot/var/named/
# cp -p localhost.zone yunvn.com.zone
# vim yunvn.com.zone




$TTL    86400
@               IN SOAyunvn.com.       root (
                                        42            ; serial (d. adams)
                                        3H            ; refresh
                                        15M             ; retry
                                        1W            ; expiry
                                        1D )            ; minimum


                IN NS         ns1.yunvn.com.
                IN MX 10      mail.yunvn.com.
ns1             IN A            1.1.1.1
mail            IN A            1.1.1.1
www             IN A            1.1.1.2


# cp -p yunvn.com.zone csdn.com.zone
# vim csdn.com.zone




$TTL    86400
@               IN SOAcsdn.com.       root (
                                        42            ; serial (d. adams)
                                        3H            ; refresh
                                        15M             ; retry
                                        1W            ; expiry
                                        1D )            ; minimum


                IN NS         ns1.csdn.com.
                IN MX 10      mail.csdn.com.
ns1             IN A            1.1.1.1
mail            IN A            1.1.1.1
www             IN A            1.1.1.2


6、重新启动服务


# service named restart
停止 named:                                             [确定]
启动 named:                                             [确定]


7、去LAMP服务器上测试效果


# ifconfig
eth0      Link encap:EthernetHWaddr 00:0C:29:63:9D:6B
          inet addr:1.1.1.2Bcast:1.1.1.255Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe63:9d6b/64 Scope:Link
          UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
          RX packets:56 errors:0 dropped:0 overruns:0 frame:0
          TX packets:131 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:9188 (8.9 KiB)TX bytes:21947 (21.4 KiB)
          Interrupt:59 Base address:0x2024


lo      Link encap:Local Loopback
          inet addr:127.0.0.1Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNINGMTU:16436Metric:1
          RX packets:42 errors:0 dropped:0 overruns:0 frame:0
          TX packets:42 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:3760 (3.6 KiB)TX bytes:3760 (3.6 KiB)


# vim /etc/resolv.conf


search yunvn.com
nameserver 1.1.1.1


# nslookup
> www.yunvn.com
Server:         1.1.1.1
Address:      1.1.1.1#53


Name:   www.yunvn.com
Address: 1.1.1.2
> www.csdn.com
Server:         1.1.1.1
Address:      1.1.1.1#53


Name:   www.csdn.com
Address: 1.1.1.2


8、搭建完成。


搭建LAMP网站服务平台:


一、配置Apache服务:


1、查看IP地址:


2、安装Apache服务


# mount -o loop /dev/cdrom /media/
# cd /media/
# tar -zxf httpd-2.2.16.tar.gz -C /usr/src/
# cd /usr/src/httpd-2.2.16/
# ls
ABOUT_APACHEconfig.layouthttpd.spec      Makefile.win      ROADMAP
acinclude.m4config.log   include         modules         server
Apache.dsw    config.nice    INSTALL         NOTICE            srclib
build         configure      InstallBin.dspNWGNUmakefile   support
BuildAll.dspconfigure.in   LAYOUT          os                test
BuildBin.dspdocs         libhttpd.dsp    README            VERSIONING
buildconf   emacs-style    LICENSE         README.platforms
CHANGES       httpd.dsp      Makefile.in   README-win32.txt
# ./configure \
> --prefix=/usr/local/apache2 \
> --enable-so \
> --enable-rewrite \
> --enable-ssl \
> --with-ssl=/usr/lib \
> --enable-auth-digest \
> --enable-cgi \
> --enable-suexec \
> --with-suexec-caller=daemon \
> --with-suexec-docroot=/usr/local/apache2/htdocs


config.status: creating support/dbmmanage
config.status: creating support/envvars-std
config.status: creating support/log_server_status
config.status: creating support/logresolve.pl
config.status: creating support/phf_abuse_log.cgi
config.status: creating support/split-logfile
config.status: creating build/rules.mk
config.status: creating build/pkg/pkginfo
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands


# make && make install


Installing header files
Installing build system files
Installing man pages and online manual
mkdir /usr/local/apache2/man
mkdir /usr/local/apache2/man/man1
mkdir /usr/local/apache2/man/man8
mkdir /usr/local/apache2/manual
make: Leaving directory `/usr/src/httpd-2.2.16'


3、开启服务、测试网站是否工作


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


92 # This can often be determined automatically, but we recommend you specify
93 # it explicitly to prevent problems during startup.
94 #
95 # If your host doesn't have a registered DNS name, enter its IP address here    .
96 #
97 ServerName www.yunvn.com
98
99 #
100 # DocumentRoot: The directory out of which you will serve your
101 # documents. By default, all requests are taken from this directory, but
102 # symbolic links and aliases may be used to point to other locations.


# /usr/local/apache2/bin/apachectl start



4、网站搭建完成。


二、配置Mysql:


1、rpm安装mysql到指定目录再用源码包安装。


# mount -o loop /dev/cdrom /media/
# cd /media/
# ls
4discuzx15               mhash-0.9.9.9.tar.bz2
awstats-6.95.tar.gz      MySQL-community-5.1.50-1.rhel5.src.rpm
config.txt               php-5.3.3.tar.gz
Discuz_X1.5_SC_UTF8.zipphpMyAdmin-3.3.6-all-languages.tar.gz
fish                     tuzki
httpd-2.2.16.tar.gz      wuwangwo_cc_jspvz
libmcrypt-2.5.8.tar.gz   绿色表情
mcrypt-2.6.8.tar.gz


# rpm -ivh MySQL-community-5.1.50-1.rhel5.src.rpm
error: cannot create %sourcedir /usr/src/redhat/SOURCES
# mkdir -p /usr/src/redhat/SOURCES
# cd /usr/src/redhat/
# chmod 777 SOURCES/


# rpm -ivh MySQL-community-5.1.50-1.rhel5.src.rpm
   1:MySQL-community      warning: user mysqldev does not exist - using root
warning: group mysqldev does not exist - using root
warning: user mysqldev does not exist - using root
warning: group mysqldev does not exist - using root
###########################################


# cd /usr/src/redhat/SOURCES/
# ls
mysql-5.1.50.tar.gz
# tar -zxf mysql-5.1.50.tar.gz -C /usr/src/


2、配置 编译 安装Mysql服务 (编译和安装都需要等待很长时间)


# ./configure --prefix=/usr/local/mysql && make && make install


Making install in win
make: Entering directory `/usr/src/mysql-5.1.50/win'
make: Entering directory `/usr/src/mysql-5.1.50/win'
make: Nothing to be done for `install-exec-am'.
make: Nothing to be done for `install-data-am'.
make: Leaving directory `/usr/src/mysql-5.1.50/win'
make: Leaving directory `/usr/src/mysql-5.1.50/win'


编译成功


3、创建运行Mysql的系统用户和组


# useradd -M -s /sbin/nologin mysql


4、建立配置文件


# cp support-files/my-medium.cnf /etc/my.cnf


5、初始化数据库


# /usr/local/mysql/bin/mysql_install_db --user=mysql


# chown -R root.mysql /usr/local/mysql/
# chown -R mysql /usr/local/mysql/var/


6、调整lib库路径


# echo "/usr/local/mysql/lib/mysql/" >> /etc/ld.so.conf
# ldconfig


7、使用mysql_safe脚本安全启动服务


# /usr/local/mysql/bin/mysqld_safe --user=mysql &
6797
# 130314 00:31:55 mysqld_safe Logging to '/usr/local/mysql/var/localhost.localdomain.err'.
130314 00:31:55 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var


8、将mysqld添加为系统服务


# cp support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on


9、设置Mysql的执行路径


# export PATH=$PATH:/usr/local/mysql/bin/
# echo "PATH=$PATH:/user/local/mysql/bin" >> /etc/profile


10、安装完成 登陆测试


# mysql -u root
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.50-log Source distribution


Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql>


三、配置PHP


1、配置PHP源码包


# tar -zxf php-5.3.3.tar.gz -C /usr/src/
# cd /usr/src/php-5.3.3/
# ./configure \
> --prefix=/usr/local/php5 \
> --enable-mbstring \      
> --with-apxs2=/usr/local/apache2/bin/apxs \
> --with-mysql=/usr/local/mysql \
> --with-config-file-path=/usr/local/php5


+--------------------------------------------------------------------+
| License:                                                         |
| This software is subject to the PHP License, available in this   |
| distribution in the file LICENSE.By continuing this installation |
| process, you are bound by the terms of this license agreement.   |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+


Thank you for using PHP.


2、编译、安装PHP源码包


# make && make install


Wrote PEAR system config file at: /usr/local/php5/etc/pear.conf
You may want to add: /usr/local/php5/lib/php to your php.ini include_path
/usr/src/php-5.3.3/build/shtool install -c ext/phar/phar.phar /usr/local/php5/bin
ln -s -f /usr/local/php5/bin/phar.phar /usr/local/php5/bin/phar
Installing PDO headers:          /usr/local/php5/include/php/ext/pdo/


3、复制php.ini配置文件


# cp php.ini-production /usr/local/php5/php.ini


4、设置httpd.conf文件


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


50 #
51 # Example:
52 # LoadModule foo_module modules/mod_foo.so
53 LoadModule php5_module      modules/libphp5.so
54 #
55
56 <IfModule !mpm_netware_module>
57 <IfModule !mpm_winnt_module>
58 #


160 </Directory>
161
162 #
163 # DirectoryIndex: sets the file that Apache will serve if a directory
164 # is requested.
165 #
166 <IfModule dir_module>
167   DirectoryIndex index.phpindex.html
168 </IfModule>
169
170 #


301   #
302   #AddEncoding x-compress .Z
303   #AddEncoding x-gzip .gz .tgz
304   #
305   # If the AddEncoding directives above are commented-out, then you
306   # probably should define those extensions to indicate media types:
307   #
308   AddType application/x-compress .Z
309   AddType application/x-gzip .gz .tgz
310   ADDType application/x-httpd-php .php
311      


# /usr/local/apache2/bin/apachectl stop
# /usr/local/apache2/bin/apachectl start


5、安装完成 测试PHP与Apache的协同工作


# vim /usr/local/apache2/htdocs/test.php


<?php
phpinfo();
?>




6、安装完成测试PHP与Mysql数据库的协同工作


# vim /usr/local/apache2/htdocs/tesdb.php


<?php
$link=mysql_connect("localhost","test","");
if(!$link) echo "Fail !!";
else echo "Success !!";
mysql=close();
?>



0 发表于 2013-3-17 19:27:47

爱护环境,人人有病。

xxggmmxx 发表于 2013-5-16 10:18:56

沒有激情的亲吻,哪來床上的翻滾?

xiaui520 发表于 2013-5-17 18:14:56

穿别人的鞋,走自己的路,让他们找去吧。

zhangsanfeng88 发表于 2013-5-19 07:20:06

内练一口气,外练一口屁。

wangwengwu 发表于 2013-5-20 15:16:06

谢谢楼主,共同发展

座机 发表于 2013-5-21 22:13:11

生我之前谁是我,生我之后我是谁?
页: [1]
查看完整版本: 构建LAMP网站平台的安装全过程