Apache部署本地PHP工程虚拟地址

WBOY
Libérer: 2016-07-28 08:26:32
original
783 Les gens l'ont consulté

最近自学PHP,在这简单说下PHP工程怎么用电脑的浏览器去访问。

我用的是mac系统,开发工具是Zend Studio,Apache/2.4.18。

比如我们要设置本机的虚拟域名为my.com

一、首先找到Apache的安装目录:我的是在/private/etc/apache2

在此目录下找到文件httpd.conf,在文件内容的中间位置有下面两行:

# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf

把第二行放开,即删掉#

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

保存时,如果保存不上就复制一份到桌面,修改完之后再把文件复制过来覆盖掉之前的文件。

二、找到上一步放开的文件,位置在:/private/etc/apache2/extra/httpd-vhosts.conf

打开文件,按照文件里的提示,在最下面添加如下代码并保存:


    DocumentRoot "/Users/Xiang/Zend/workspaces/MyPHP"
    ServerName my.com
    ErrorLog "/private/var/log/apache2/bweb-com-error_log"
    CustomLog "/private/var/log/apache2/bweb-com-access_log" common
   
        # AllowOverride All        # Deprecated
        # Order Allow,Deny       # Deprecated
        # Allow from all           # Deprecated
        # --New way of doing it
        Require all granted    
   


注意:DocumentRoot "/Users/Xiang/Zend/workspaces/MyPHP"和都是项目所在的路径,ServerName my.com为要增加的本机域名,其他不需要做修改。

三、在/private/etc目录下找到hosts文件

在文件的最后增加一行并保存:

127.0.0.1       my.com

四、最后重启Apache

sudo apachectl restart

会让输密码,就是电脑开机密码。

至此,打开本机电脑的浏览器,输入http://my.com/index.php,就可以看到我在MyPHP项目里写的index.php的内容了。

以上就介绍了 Apache部署本地PHP工程虚拟地址,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!