gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:30:30 25 4
gpt4 key购买 nike

我正在使用 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 webmaster@mail.com
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 网络服务器
sudo /etc/init.d/apache2 restart

编辑您的 /etc/host 文件:
sudo nano /etc/hosts

在文件末尾添加域 示例.com www.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.com 示例.com

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com