在Ubuntu上安装Apache国内linux主机,有两种形式:1使用开发包的打包服务linux apache 安装,比如使用apt-get命令;2从源码建立Apache。本文章将详尽描述这两种不同的安装方法。
方式一:使用开发包的打包服务——apt-get
安装apache,在命令行终端中输入一下命令:
$sudoapt-getinstallapache2
安装完成后linux apache 安装,重启apache服务,在命令行终端中输入一下命令:
$sudo/etc/init.d/apache2restart
可能会出现的问题1:NameVirtualHost*:80hasnoVirtualHostslinux命令vi,如下截图
出现上述问题的缘由:定义了多个NameVirtualHost,故将/etc/apache2/ports.conf中的NameVirtualHost*:80注释掉即可。
可能会出现的问题2:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,using127.0.1.1forServerName
缘由:
按照提示,难以可靠的确定服务器的有效域名,使用127.0.1.1作为服务器域名。应此,在下边的测试中,应当使用127.0.1.1,而不是127.0.0.1!
解决:
$vim/etc/apache2/httpd.conf,在文件中添加:
ServerNamelocalhost:80,再度重启apache2,就可以使用127.0.0.1来访问web服务器啦!
测试:
在浏览器里输入或则是,假如见到了Itworks!,那就说明Apache就成功的安装了,Apache的默认安装,会在/var下构建一个名为www的目录,这个就是Web目录了,所有要能过浏览器访问的Web文件都要放在这个目录里。
测试过程中可能碰到问题:
缘由:apache2使用的服务器地址不是127.0.0.1,按照在后面的剖析,可能的ip为127.0.1.1,访问http://127.0.1.1即可。
假如认为不再须要apache了,可以将它卸载:
1.删掉apache
在命令行中输入:
$sudoapt-get--purgeremoveapache-common
$sudoapt-get--purgeremoveapache
2.找到没有删掉掉的配置文件,一并删掉
代码:
$sudofind/etc-name"*apache*"|xargsrm-rf
$sudorm-rf/var/www
$sudorm-rf/etc/libapache2-mod-jk
3.删掉关联,这样就可以再度用apt-getinstallapache2重装了
#dpkg-l|grepapache2|awk'{print$2}'|xargsdpkg-P
方式二:从源建立Apache
参考资料:
Ubuntu下安装Apache+PHP+MySQL:
Ubuntu下彻底卸载Apache2:
Apache问题解决:httpd:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname链接:
--------------------------------------分割线--------------------------------------
apache2[warn]NameVirtualHost*:80hasnoVirtualHosts的解决方式
错误:[warn]NameVirtualHost*:80hasnoVirtualHosts
缘由:定义了多个NameVirtualHost
解决:Ubuntu之前的版本定义在/etc/apache2/sites-available/default,8.04后在/etc/apache2/ports.conf
故可以将/etc/apache2/ports.conf中的NameVirtualHost*:80注释掉
这个问题的本质是在没有定义域名是一个端口只能对应一个虚拟主机,将NameVirtualHost*:80改为其他端口也可以解决
倘若有多个不同的域名的话,用同样的端口也可以
更多Ubuntu相关信息见Ubuntu专题页面