php - 如何在ubuntu 14.04中创建虚拟主机

标签 php apache ubuntu

我使用的是 ubuntu 14.04 操作系统,我想在启动我的 php 项目之前创建一个虚拟主机。如果有人能给我终端命令,我将不胜感激。

我已经安装了必要的安装,并且正在使用 Symfony php 框架。

最佳答案

打开终端或控制台并编写以下命令

转到您的站点可用的 apache2 文件夹:

cd /etc/apache2/sites-available/

将您的 000-default.conf 复制到另一个文件(最好使用您的站点或虚拟主机的名称)

sudo cp 000-default.conf example.conf

使用您最好的文本编辑器打开该新文件(example.conf)或使用:

sudo nano example.conf

更改 example.conf 的内容(忽略注释):

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.

    ServerAdmin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="90e7f5f2fdf1e3e4f5e2d0fdf1f9fcbef3fffd" rel="noreferrer noopener nofollow">[email protected]</a>
    ServerName  example.com
    ServerAlias www.example.com

    # example.com is the folder where you have to put your site's code.
    # Obviously, its name can be whatever you want
    DocumentRoot /var/www/html/example.com

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    # Include conf-available/serve-cgi-bin.conf
</VirtualHost>

按如下方式启用站点:

sudo a2ensite example.com

重新启动 apache2 Web 服务器

sudo /etc/init.d/apache2 restart

编辑您的 /etc/host 文件:

sudo nano /etc/hosts

在文件末尾添加域 example.comwww.example.com。它必须看起来像:

127.0.0.1    localhost
...
# you can replace with your IP
127.0.0.1   example.com
127.0.0.1   www.example.com
...

打开您最好的网络浏览器并在地址栏中写入:www.example.comexample.com

关于php - 如何在ubuntu 14.04中创建虚拟主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28750039/

相关文章:

php - Codeigniter 事件记录查询已缓存 - 查找旧表名而不是新表名

php - Laravel 5 如何使用链接检索相关表数据

apache - 忘记 Apache OFBIZ 管理员密码

python - 在 Windows 7 上的 wamp apache 中安装 python cgi

python - 无法在 CentOS v8 上通过 yum 安装 mod_wsgi

ubuntu - 如何连接2个单独的文件夹

php - 循环通过 MySQL 左加入 php 与 2 个单独的查询

php - 从目录中获取文件并将内容插入 SQL

linux - 自动将输入提供给 Linux 命令行

ruby - 在 Ubuntu 中为 open() 方法指定一个非标准的临时目录