ubuntu下设置apache虚拟站点及hosts开发PHP
来源:互联网 发布:php封装继承多态 编辑:程序博客网 时间:2024/05/18 00:59
ubuntu 下设置apache的配置文件与windows有所不同。
windows下设置apache只需要修改httpd.conf或是conf/extra/httpd-vhosts.conf都可以。
但是在ubuntu下, apache的配置文件httpd.conf是空的,里面竟然没有内容!!!
在/etc/apache2/apache2.conf里可以看到有很多include,而这些才是真正的配置文件。关于这个解释,网上有更详细的说明,请自行查阅。
下面,开始真正的操作实习。
一、建立站点目录文件夹。
1、首先创建 /home/username/mysite/ 目录做为网站的虚拟目录。
*username即您的用户名;mysite即虚拟目录的名称;(以下含意相同),根据实际情况修改。
2、在目录下建立相应的index.php、erro.log、access.log等基本文件(也可以只建立最简单的index.php打印一条语句)。
二、修改系统hosts
修改hosts需要root权限
username@userhost:~$ sudo gedit /etc/hosts[sudo] password for username:输入密码(如果您设置了的话,并且建议为root权限设置密码)
添加下面这段地址转向:
127.0.1.1www.yoursite.com*www.yoursite.com代表您要设置的转向的域名(下同)。
三、精简设置apache虚拟站点配置文件
1、创建站点配置文件内容
#在终端输入下列命令创建配置文件(other为配置文件名称)username@userhost:~$ sudo gedit /etc/apache2/sites-available/other
#配置文件内容示例如下:<VirtualHost *># 在ServerName后加上你的网站名称ServerName www.yoursite.com# 如果你想多个网站名称都取得相同的网站,可以加在ServerAlias后加上其他网站别名。# 别名间以空格隔开。ServerAlias ftp.yoursite.com mail.yoursite.com# 在ServerAdmin后加上网站管理员的电邮地址,方便别人有问题是可以联络网站管理员。ServerAdmin webmaster@yoursite.com# 在DocumentRoot后加上存放网站内容的目录路径(用户的个人目录)DocumentRoot /home/username/mysite/ <Directory /home/username/mysite/ >Options Indexes FollowSymLinks MultiViewsAllowOverride NoneOrder allow,denyallow from all</Directory>ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/<Directory "/usr/lib/cgi-bin">AllowOverride NoneOptions ExecCGI -MultiViews +SymLinksIfOwnerMatchAllow from all</Directory>ErrorLog /home/username/mysite/error.log# Possible values include: debug, info, notice, warn, error, crit,# alert, emerg.LogLevel warnCustomLog /home/username/mysite/access.log combinedServerSignature On</VirtualHost>#如果你的服务器有多个IP,而不同的IP又有着不一样的虚拟用户的话,可以修改成:#<VirtualHost IP地址[:端口]>#...#</VirtualHost>
2、创建站点启用文件
#终端下输入命令,创建配置文件(other为配置文件名称)
username@userhost:~$ sudo gedit /etc/apache2/sites-enabled/other
#配置文件内容示例如下:
<VirtualHost *:80> ServerName www.yoursite.com DocumentRoot /home/username/mysite/ <Directory /home/username/mysite/> Options ExecCGI FollowSymLinks AllowOverride all allow from all Order allow,deny </Directory> ErrorLog /var/log/apache2/error-鍩熷悕.log #此处因编码问题而出错,可以根据您个人的机器修正它。</VirtualHost>
3、连接文件
sudo ln -s /etc/apache2/sites-available/other /etc/apache2/sites-enabled/other
4、检测apache配置文件是否正确
sudo apache2ctl configtest#如果出现: Syntax OK 表示语法正确,
5、重启apache2
sudo /etc/init.d/apache2 restart
OK,全部完成,现在在浏览器测试站点是否配置成功,因为一遍做,一边记录输入该笔记,可能有些疏漏,请大家多多提出宝贵意见。
关于apache配置里
<Directory /home/username/mysite/>一段,是否要在路径上加" ",请参考下面5L的评论,感谢 ff781778304指出的问题。
- ubuntu下设置apache虚拟站点及hosts开发PHP
- Apache设置虚拟站点
- apache 设置 多个虚拟站点
- php 用apache配置虚拟站点
- ubuntu 下设置apache、php,mysql server
- ubuntu apache下设置隐藏index.php
- 设置 Apache & hosts 本地开发环境
- ubuntu 下用xampp配置虚拟站点
- Ubuntu+apache 单IP多站点设置
- php继承环境多站点apache设置
- Ubuntu Apache 2.4 配置-虚拟站点、禁止IP访问
- 简单 apache php环境 虚拟多站点配置
- ubuntu下配置多站点Apache笔记
- Apache,php关于站点配置及访问
- apache下设置多站点(windows)
- windows 下apache多站点支持 [PHP]
- ubuntu 设置hosts
- LINUX下PHP+ORACLE+APACHE的安装及设置
- C++基本功和 Design Pattern系列(2)
- Dom4j生成xml
- matlab的vectorize:将标量转化成向量
- TabActivity探索
- Linux下查看Tomcat的控制台输出信息
- ubuntu下设置apache虚拟站点及hosts开发PHP
- poj 1389 Area of Simple Polygons(线段树做法)
- 解析Cocos2d项目整体框架和启动流程
- 带email认证的用户注册网站
- 在虚拟机中安装WIN CE
- HTTP报文解析及其状态码
- 自己用JavaScript写的一个很简单的骰子大小赌博模拟
- this指针及const成员函数
- 如何快速学习flex