搭建web服务二
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搭建web服务二相关的知识,希望对你有一定的参考价值。
练习三—虚拟web主机
[[email protected] conf]# cd /var/www/html/
[[email protected] html]# mkdir google tfft
[[email protected] html]# vim google/index.html
[[email protected] html]# vim tfft/index.html
[[email protected] html]# cat google/index.html
<h1> welcome to google ! </h1>
[[email protected] html]# cat tfft/index.html
<h1> welcome to tfft ! </h1>
[[email protected] html]# vim /etc/httpd/conf.d/vhosts.conf
[[email protected] 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>
[[email protected] 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.安装相应软件包
[[email protected] html]# rpm -qa httpd mysql-server mysql php php-mysql
httpd-2.2.15-59.el6.centos.x86_64
[[email protected] html]# yum install mysql-server mysql php php-mysql
2.配置mysql
[[email protected] html]# /etc/init.d/mysqld restart
停止 mysqld: [确定]
初始化 MySQL 数据库: Installing MySQL system tables...
[[email protected] html]# chkconfig mysqld on
[[email protected] html]# chkconfig mysqld --list
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[[email protected] html]# mysqladmin -u root password ‘Taren1‘
3.配置PHP
[[email protected] html]# vim /etc/php.ini
.. ..
default_charset = "utf-8" //设置默认字符集
file_uploads = On //允许从PHP网页上传文件
upload_max_filesize = 2M //允许上传的文件大小
post_max_size = 8M //每次POST提交的数据限制
4.配置httpd
[[email protected] html]# vim /etc/httpd/conf/httpd.conf
...
DirectoryIndex index.php index.html
[[email protected] html]# vim /var/www/html/test1.php
<?php
phpinfo();
?>
[[email protected] 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服务及访问
[[email protected] 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.建论坛库
[[email protected] ~]# mysql -uroot -p
Enter password: //验证管理密码
mysql> create database bbsdb; //创建bbsdb数据库
mysql> show databases; //查看数据库
mysql> grant all on bbsdb.* to [email protected] identified by ‘pwd123‘; //授权数据库
mysql> quit
2.部署论坛网页代码
[[email protected] ~]# unzip Discuz_X3.2_SC_UTF8.zip -d tdir
[[email protected] ~]# ls -F tdir/
[[email protected] ~]# cp -rf tdir/upload/ /var/www/html/bbs
[[email protected] ~]# cd /var/www/html/bbs/
[[email protected] bbs]# chown -R apache template/ config/ data/ uc_client/ uc_server/
3.安装论坛系统及后续访问
http://192.168.102.123/bbs/install/
以上是关于搭建web服务二的主要内容,如果未能解决你的问题,请参考以下文章