构建LAMP网站平台的安装全过程
原创xinerwener 博主文章分类:linux网络服务 ©著作权
©著作权归作者所有:来自51CTO博客作者xinerwener的原创作品,请联系作者获取转载授权,否则将追究法律责任
准备实验环境:
两台虚拟机:
第一台做DNS服务器解析域名。
第二台做LAMP网站服务平台。
搭建DNS服务:
1、配置IP地址
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:26:05:59
inet addr:1.1.1.1 Bcast:1.1.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe26:559/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric: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.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric: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相关软件包
[root@localhost ~]# mount -o loop /dev/cdrom /media/
[root@localhost ~]# cd /media/Server/
[root@localhost 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... ########################################### [100%]
1:bind ########################################### [100%]
[root@localhost Server]# 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... ########################################### [100%]
1:caching-nameserver ########################################### [100%]
[root@localhost Server]# 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... ########################################### [100%]
1:bind-chroot ########################################### [100%]
[root@localhost Server]# 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... ########################################### [100%]
package bind-utils-9.3.6-4.P1.el5_4.2.i386 is already installed
3、通过模板修改主配置文件
[root@localhost Server]# cd /var/named/chroot/etc/
[root@localhost etc]# cp -p named.caching-nameserver.conf named.conf
[root@localhost etc]# 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、修改区域文件
[root@localhost etc]# vim named.rfc1912.zones
zone "51cto.com" IN {
type master;
file "51cto.com.zone";
allow-update { none; };
};
zone "csdn.com" IN {
type master;
file "csdn.com.zone";
allow-update { none; };
};
5、通过模板、修改正向解析文件(反向解析不用做。)
[root@localhost etc]# cd /var/named/chroot/var/named/
[root@localhost named]# cp -p localhost.zone 51cto.com.zone
[root@localhost named]# vim 51cto.com.zone
$TTL 86400
@ IN SOA 51cto.com. root (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS ns1.51cto.com.
IN MX 10 mail.51cto.com.
ns1 IN A 1.1.1.1
mail IN A 1.1.1.1
www IN A 1.1.1.2
[root@localhost named]# cp -p 51cto.com.zone csdn.com.zone
[root@localhost named]# vim csdn.com.zone
$TTL 86400
@ IN SOA csdn.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、重新启动服务
[root@localhost named]# service named restart
停止 named: [确定]
启动 named: [确定]
7、去LAMP服务器上测试效果
[root@localhost /]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:63:9D:6B
inet addr:1.1.1.2 Bcast:1.1.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe63:9d6b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric: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.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric: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)
[root@localhost /]# vim /etc/resolv.conf
search 51cto.com
nameserver 1.1.1.1
[root@localhost /]# nslookup
> www.51cto.com
Server: 1.1.1.1
Address: 1.1.1.1#53
Name: www.51cto.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服务
[root@localhost /]# mount -o loop /dev/cdrom /media/
[root@localhost /]# cd /media/
[root@localhost media]# tar -zxf httpd-2.2.16.tar.gz -C /usr/src/
[root@localhost /]# cd /usr/src/httpd-2.2.16/
[root@localhost httpd-2.2.16]# ls
ABOUT_APACHE config.layout httpd.spec Makefile.win ROADMAP
acinclude.m4 config.log include modules server
Apache.dsw config.nice INSTALL NOTICE srclib
build configure InstallBin.dsp NWGNUmakefile support
BuildAll.dsp configure.in LAYOUT os test
BuildBin.dsp docs libhttpd.dsp README VERSIONING
buildconf emacs-style LICENSE README.platforms
CHANGES httpd.dsp Makefile.in README-win32.txt
[root@localhost httpd-2.2.16]# ./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
[root@localhost httpd-2.2.16]# 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[1]: Leaving directory `/usr/src/httpd-2.2.16'
3、开启服务、测试网站是否工作
[root@localhost httpd-2.2.16]# 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.51cto.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.
[root@localhost httpd-2.2.16]# /usr/local/apache2/bin/apachectl start
4、网站搭建完成。
二、配置Mysql:
1、rpm安装mysql到指定目录再用源码包安装。
[root@localhost httpd-2.2.16]# mount -o loop /dev/cdrom /media/
[root@localhost httpd-2.2.16]# cd /media/
[root@localhost 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.zip phpMyAdmin-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
[root@localhost media]# rpm -ivh MySQL-community-5.1.50-1.rhel5.src.rpm
error: cannot create %sourcedir /usr/src/redhat/SOURCES
[root@localhost media]# mkdir -p /usr/src/redhat/SOURCES
[root@localhost media]# cd /usr/src/redhat/
[root@localhost redhat]# chmod 777 SOURCES/
[root@localhost media]# 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
########################################### [100%]
[root@localhost media]# cd /usr/src/redhat/SOURCES/
[root@localhost SOURCES]# ls
mysql-5.1.50.tar.gz
[root@localhost SOURCES]# tar -zxf mysql-5.1.50.tar.gz -C /usr/src/
2、配置 编译 安装Mysql服务 (编译和安装都需要等待很长时间)
[root@localhost mysql-5.1.50]# ./configure --prefix=/usr/local/mysql && make && make install
Making install in win
make[1]: Entering directory `/usr/src/mysql-5.1.50/win'
make[2]: Entering directory `/usr/src/mysql-5.1.50/win'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/usr/src/mysql-5.1.50/win'
make[1]: Leaving directory `/usr/src/mysql-5.1.50/win'
编译成功
3、创建运行Mysql的系统用户和组
[root@localhost mysql-5.1.50]# useradd -M -s /sbin/nologin mysql
4、建立配置文件
[root@localhost mysql-5.1.50]# cp support-files/my-medium.cnf /etc/my.cnf
5、初始化数据库
[root@localhost mysql-5.1.50]# /usr/local/mysql/bin/mysql_install_db --user=mysql
[root@localhost mysql-5.1.50]# chown -R root.mysql /usr/local/mysql/
[root@localhost mysql-5.1.50]# chown -R mysql /usr/local/mysql/var/
6、调整lib库路径
[root@localhost mysql-5.1.50]# echo "/usr/local/mysql/lib/mysql/" >> /etc/ld.so.conf
[root@localhost mysql-5.1.50]# ldconfig
7、使用mysql_safe脚本安全启动服务
[root@localhost mysql-5.1.50]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[1] 6797
[root@localhost mysql-5.1.50]# 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添加为系统服务
[root@localhost mysql-5.1.50]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.1.50]# chmod +x /etc/init.d/mysqld
[root@localhost mysql-5.1.50]# chkconfig --add mysqld
[root@localhost mysql-5.1.50]# chkconfig mysqld on
9、设置Mysql的执行路径
[root@localhost mysql-5.1.50]# export PATH=$PATH:/usr/local/mysql/bin/
[root@localhost mysql-5.1.50]# echo "PATH=$PATH:/user/local/mysql/bin" >> /etc/profile
10、安装完成 登陆测试
[root@localhost mysql-5.1.50]# 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源码包
[root@localhost media]# tar -zxf php-5.3.3.tar.gz -C /usr/src/
[root@localhost media]# cd /usr/src/php-5.3.3/
[root@localhost 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源码包
[root@localhost php-5.3.3]# 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配置文件
[root@localhost php-5.3.3]# cp php.ini-production /usr/local/php5/php.ini
4、设置httpd.conf文件
[root@localhost php-5.3.3]# 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.php index.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
[root@localhost php-5.3.3]# /usr/local/apache2/bin/apachectl stop
[root@localhost php-5.3.3]# /usr/local/apache2/bin/apachectl start
5、安装完成 测试PHP与Apache的协同工作
[root@localhost php-5.3.3]# vim /usr/local/apache2/htdocs/test.php
<?php
phpinfo();
?>
6、安装完成 测试PHP与Mysql数据库的协同工作
[root@localhost php-5.3.3]# vim /usr/local/apache2/htdocs/tesdb.php
<?php
$link=mysql_connect("localhost","test","");
if(!$link) echo "Fail !!";
else echo "Success !!";
mysql=close();
?>
上一篇:安装php时的报错
下一篇:第六章 管理进程和计划任务
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
rocky linux mysql8.4主从环境搭建以及数据库备份全过程
mysql8.4 mysqldump 备份脚本
mysql MySQL 慢查询