sh 为本地站点创建Apache虚拟主机
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 为本地站点创建Apache虚拟主机相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env bash
repo_loc="$1"
site_name="$2"
usage() {
printf "Usage:
\tcreate-vhost <web_root> <local_url>
Options:
\tweb_root:\tweb root of the application, usually {repo}/public or {repo}/web
\tlocal_url:\tURL to use, usually dev.{real-url.com}
Example for Craft 3:
\tcd <repo>
\tcreate-vhost \${PWD}/web dev.sitename.com\n"
}
if [[ -z "$1" ]]; then usage; exit; fi
if [[ -z "$2" ]]; then usage; exit; fi
vhost() {
printf "
<VirtualHost *:80>
DocumentRoot \"%s\"
ServerName %s
ErrorLog \"/usr/local/var/log/httpd/%s-error_log\"
CustomLog \"/usr/local/var/log/httpd/%s-access_log\" common
<Directory \"%s\">
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
" "$1" "$2" "$2" "$2" "$1"
}
echo "Writing default config to /usr/local/etc/httpd/extra/vhosts/${site_name}.conf ..."
vhost "$repo_loc" "$site_name" > "/usr/local/etc/httpd/extra/vhosts/${site_name}.conf"
echo "Updating /etc/hosts..."
echo "127.0.0.1 ${site_name}" | sudo tee -a /etc/hosts >/dev/null
echo "Restarting Apache..."
sudo apachectl restart
echo "Complete"
#!/usr/bin/env bash
repo_loc="$1"
site_name="$2"
fpm="$3"
usage() {
printf "Usage:
\tcreate-vhost <web_root> <local_url> <fpm_version>
\texample: create-vhost \${PWD}/web dev.site.com 72
Options:
\tweb_root:\tweb root of the application, usually {repo}/public or {repo}/web
\tlocal_url:\tURL to use, usually dev.{real-url.com}
\tfpm_version:\tPHP FPM version to use
Example for Craft 3:
\tcd <repo>
\tcreate-vhost \${PWD}/web dev.sitename.com 72\n"
}
if [[ -z "$1" ]]; then usage; exit; fi
if [[ -z "$2" ]]; then usage; exit; fi
if [[ -z "$3" ]]; then fpm="72"; fi
vhost() {
printf "<VirtualHost *:80>
DocumentRoot \"%s\"
ServerName %s
ErrorLog \"/usr/local/var/log/httpd/%s-error_log\"
CustomLog \"/usr/local/var/log/httpd/%s-access_log\" common
ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/usr/local/var/run/php-%s.sock|fcgi://127.0.0.1/%s
<Directory \"%s\">
AllowOverride all
Require all granted
</Directory>
</VirtualHost>" "$1" "$2" "$2" "$2" "$fpm" "$1" "$1"
}
echo "Writing default config to /usr/local/etc/httpd/extra/vhosts/${site_name}.conf ..."
vhost "$repo_loc" "$site_name" > "/usr/local/etc/httpd/extra/vhosts/${site_name}.conf"
echo "Updating /etc/hosts..."
echo "127.0.0.1 ${site_name}" | sudo tee -a /etc/hosts >/dev/null
echo "Restarting Apache..."
sudo apachectl restart
echo "Complete"
以上是关于sh 为本地站点创建Apache虚拟主机的主要内容,如果未能解决你的问题,请参考以下文章
启用对 WAMP 服务器上站点的本地网络访问
在 Apache 中定义本地站点 - 使用 80 以外的端口
通过PHP工具箱-站点域名管理(创建本地虚拟主机)
通过PHP工具箱-站点域名管理(创建本地虚拟主机)
在一台Apache服务器上创建多个站点(不同域名)
apache的虚拟主机配置