首页 > 代码库 > 搭建web服务二

搭建web服务二

 练习三—虚拟web主机

[root@lys conf]# cd /var/www/html/
[root@lys html]# mkdir google tfft
[root@lys html]# vim google/index.html
[root@lys html]# vim tfft/index.html
[root@lys html]# cat google/index.html
<h1> welcome to google ! </h1>
[root@lys html]# cat tfft/index.html
<h1> welcome to tfft ! </h1>
[root@lys html]# vim /etc/httpd/conf.d/vhosts.conf
[root@lys html]# cat /etc/httpd/conf.d/vhosts.conf
NameVirtualHost 192.168.102.123
<VirtualHost 192.168.102.123>
DocumentRoot /var/www/html/google
ServerName www.google.com
</VirtualHost>

<VirtualHost 192.168.102.123>
DocumentRoot /var/www/html/tfft
ServerName www.tfft.com
</VirtualHost>
[root@lys html]# /etc/init.d/httpd restart
停止 httpd: [确定]
正在启动 httpd:httpd: Could not reliably determine the server‘s fully qualified domain name, using ::1 for ServerName
[确定]

补充:Windows系统中C:\Windows\System32\drivers\etc\hosts可添加IP和域名对应关系

 

192.168.102.123 www.google.com
192.168.102.123 www.tfft.com

 

技术分享

 

 技术分享

技术分享

 

 

练习四—构建LAMP网站平台

1.安装相应软件包

[root@lys html]# rpm -qa httpd mysql-server mysql php php-mysql
httpd-2.2.15-59.el6.centos.x86_64
[root@lys html]# yum install mysql-server mysql php php-mysql

2.配置mysql

[root@lys html]# /etc/init.d/mysqld restart
停止 mysqld: [确定]
初始化 MySQL 数据库: Installing MySQL system tables...

[root@lys html]# chkconfig mysqld on
[root@lys html]# chkconfig mysqld --list
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

[root@lys html]# mysqladmin -u root password ‘Taren1‘

3.配置PHP

[root@lys html]# vim /etc/php.ini
.. ..
default_charset = "utf-8"    //设置默认字符集
file_uploads = On        //允许从PHP网页上传文件
upload_max_filesize = 2M     //允许上传的文件大小
post_max_size = 8M       //每次POST提交的数据限制

4.配置httpd

[root@lys html]# vim /etc/httpd/conf/httpd.conf
...
DirectoryIndex index.php index.html

[root@lys html]# vim /var/www/html/test1.php

<?php
phpinfo();
?>

[root@lys html]# vim /var/www/html/test2.php

<?php
$link=mysql_connect(‘localhost‘,‘root‘,‘Taren1‘);
if($link) echo "Success !!";   //成功则显示Success !!
else echo "Failure !!";      //失败则显示Failure !!
mysql_close();          //关闭数据库连接
?>

5.重启httpd服务及访问

[root@lys html]# /etc/init.d/httpd restart

停止 httpd: [确定]
正在启动 httpd:httpd: Could not reliably determine the server‘s fully qualified domain name, using ::1 for ServerName
[确定]

 技术分享

技术分享

 

 

 

 

练习五—部署PHP应用(Discuz!论坛系统)

1.建论坛库

[root@lys ~]# mysql -uroot -p
Enter password: //验证管理密码
mysql> create database bbsdb; //创建bbsdb数据库
mysql> show databases; //查看数据库
mysql> grant all on bbsdb.* to runbbs@localhost identified by ‘pwd123‘; //授权数据库
mysql> quit

2.部署论坛网页代码

[root@lys ~]# unzip Discuz_X3.2_SC_UTF8.zip -d tdir
[root@lys ~]# ls -F tdir/
[root@lys ~]# cp -rf tdir/upload/ /var/www/html/bbs
[root@lys ~]# cd /var/www/html/bbs/
[root@lys bbs]# chown -R apache template/ config/ data/ uc_client/ uc_server/

3.安装论坛系统及后续访问

http://192.168.102.123/bbs/install/

技术分享

技术分享

技术分享

技术分享

技术分享

 

搭建web服务二