在 DocumentRoot 的子文件夹中安装 Symfony 4
Install Symfony 4 in a subfolder of DocumentRoot
我希望这个问题不是重复的,但我只找到了关于旧版本 Symfony 的文章或问题。我是 Symfony 4 的新手,我想用它创建一个新应用程序并将其安装为现有网站的一部分(domain
下面)。 Sf 4 应用程序进入下面层次结构中显示的 admin/
子目录。 domain
使用 TYPO3 CMS,但我不确定它对这个问题是否重要。
首先,这是目录结构:
/home/webuser/domain/
public/ (this is the document root for "domain.localhost")
admin/ (the Symfony app goes here)
public/
…
…
typo3/
.htaccess
index.php
…
composer.json
我目前正在本地机器上的网站上工作,我想从 domain.localhost/admin
访问 Symfony 应用程序根目录。我正在使用 Apache 虚拟主机,domain/public
文件夹是 domain
的文档根目录:
<VirtualHost *:80>
ServerName domain.localhost
DocumentRoot "/home/webuser/www/domain/public"
</VirtualHost>
我尝试将以下重写规则添加到我的 VirtualHost 中:
<VirtualHost *:80>
ServerName domain.localhost
DocumentRoot "/home/webuser/www/domain/public"
RewriteEngine On
RewriteRule "^/admin/(.*)$" "/admin/public/"
LogLevel trace1
</VirtualHost>
但这似乎只有在我访问 http://domain.localhost/admin/
时才有效:然后我看到了 "Welcome to Symfony 4.2.7" 页面。我一尝试访问子页面,就会收到 404 错误。我尝试按照文档 here 中的说明在 lucky/number
创建我的第一个页面,并查看 Apache 错误日志,我有如下行:
[Mon Apr 29 18:52:09.472043 2019] [rewrite:trace1] [pid 22250:tid 140404453660416] mod_rewrite.c(483): [client ::1:43084] ::1 - - [domain.localhost/sid#55a33c704bf8][rid#7fb260002bd0/initial] [perdir /home/webuser/www/domain/public/] pass through /home/webuser/www/domain/public/admin/public/lucky
[Mon Apr 29 18:52:09.472087 2019] [core:info] [pid 22250:tid 140404453660416] [client ::1:43084] AH00128: File does not exist: /home/webuser/www/domain/public/admin/public/lucky/number
现在,TYPO3 有一个包含 URL 重写的 .htaccess
文件,但我不认为它们在干扰。下面,我只是在"Stop rewrite processing"开头的注释后面的规则中添加了自己的admin/
文件夹,这样我们就不会在文件被重定向到domain
网站的主页时未找到:
<IfModule mod_rewrite.c>
# Enable URL rewriting
RewriteEngine On
# Store the current location in an environment variable CWD to use
# mod_rewrite in .htaccess files without knowing the RewriteBase
RewriteCond [=14=]#%{REQUEST_URI} ([^#]*)#(.*)$
RewriteRule ^.*$ - [E=CWD:%2]
# Rule for versioned static files, configured through:
# - $GLOBALS['TYPO3_CONF_VARS']['BE']['versionNumberInFilename']
# - $GLOBALS['TYPO3_CONF_VARS']['FE']['versionNumberInFilename']
# IMPORTANT: This rule has to be the very first RewriteCond in order to work!
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ %{ENV:CWD}. [L]
# Access block for folders
RewriteRule _(?:recycler|temp)_/ - [F]
RewriteRule fileadmin/templates/.*\.(?:txt|ts)$ - [F]
RewriteRule ^(?:vendor|typo3_src|typo3temp/var) - [F]
RewriteRule (?:typo3conf/ext|typo3/sysext|typo3/ext)/[^/]+/(?:Configuration|Resources/Private|Tests?|Documentation|docs?)/ - [F]
# Block access to all hidden files and directories with the exception of
# the visible content from within the `/.well-known/` hidden directory (RFC 5785).
RewriteCond %{REQUEST_URI} "!(^|/)\.well-known/([^./]+./?)+$" [NC]
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule (?:^|/)\. - [F]
# Stop rewrite processing, if we are in the typo3/ directory or any other known directory
# NOTE: Add your additional local storages here
RewriteRule ^(?:typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico|admin/) - [L]
# If the file/symlink/directory does not exist => Redirect to index.php.
# For httpd.conf, you need to prefix each '%{REQUEST_FILENAME}' with '%{DOCUMENT_ROOT}'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L]
</IfModule>
生产服务器将是一个专用系统,所以我可以修改任何我想要的东西。
事实证明,我只需要安装 Apache 包,如 this answer
我希望这个问题不是重复的,但我只找到了关于旧版本 Symfony 的文章或问题。我是 Symfony 4 的新手,我想用它创建一个新应用程序并将其安装为现有网站的一部分(domain
下面)。 Sf 4 应用程序进入下面层次结构中显示的 admin/
子目录。 domain
使用 TYPO3 CMS,但我不确定它对这个问题是否重要。
首先,这是目录结构:
/home/webuser/domain/
public/ (this is the document root for "domain.localhost")
admin/ (the Symfony app goes here)
public/
…
…
typo3/
.htaccess
index.php
…
composer.json
我目前正在本地机器上的网站上工作,我想从 domain.localhost/admin
访问 Symfony 应用程序根目录。我正在使用 Apache 虚拟主机,domain/public
文件夹是 domain
的文档根目录:
<VirtualHost *:80>
ServerName domain.localhost
DocumentRoot "/home/webuser/www/domain/public"
</VirtualHost>
我尝试将以下重写规则添加到我的 VirtualHost 中:
<VirtualHost *:80>
ServerName domain.localhost
DocumentRoot "/home/webuser/www/domain/public"
RewriteEngine On
RewriteRule "^/admin/(.*)$" "/admin/public/"
LogLevel trace1
</VirtualHost>
但这似乎只有在我访问 http://domain.localhost/admin/
时才有效:然后我看到了 "Welcome to Symfony 4.2.7" 页面。我一尝试访问子页面,就会收到 404 错误。我尝试按照文档 here 中的说明在 lucky/number
创建我的第一个页面,并查看 Apache 错误日志,我有如下行:
[Mon Apr 29 18:52:09.472043 2019] [rewrite:trace1] [pid 22250:tid 140404453660416] mod_rewrite.c(483): [client ::1:43084] ::1 - - [domain.localhost/sid#55a33c704bf8][rid#7fb260002bd0/initial] [perdir /home/webuser/www/domain/public/] pass through /home/webuser/www/domain/public/admin/public/lucky
[Mon Apr 29 18:52:09.472087 2019] [core:info] [pid 22250:tid 140404453660416] [client ::1:43084] AH00128: File does not exist: /home/webuser/www/domain/public/admin/public/lucky/number
现在,TYPO3 有一个包含 URL 重写的 .htaccess
文件,但我不认为它们在干扰。下面,我只是在"Stop rewrite processing"开头的注释后面的规则中添加了自己的admin/
文件夹,这样我们就不会在文件被重定向到domain
网站的主页时未找到:
<IfModule mod_rewrite.c>
# Enable URL rewriting
RewriteEngine On
# Store the current location in an environment variable CWD to use
# mod_rewrite in .htaccess files without knowing the RewriteBase
RewriteCond [=14=]#%{REQUEST_URI} ([^#]*)#(.*)$
RewriteRule ^.*$ - [E=CWD:%2]
# Rule for versioned static files, configured through:
# - $GLOBALS['TYPO3_CONF_VARS']['BE']['versionNumberInFilename']
# - $GLOBALS['TYPO3_CONF_VARS']['FE']['versionNumberInFilename']
# IMPORTANT: This rule has to be the very first RewriteCond in order to work!
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ %{ENV:CWD}. [L]
# Access block for folders
RewriteRule _(?:recycler|temp)_/ - [F]
RewriteRule fileadmin/templates/.*\.(?:txt|ts)$ - [F]
RewriteRule ^(?:vendor|typo3_src|typo3temp/var) - [F]
RewriteRule (?:typo3conf/ext|typo3/sysext|typo3/ext)/[^/]+/(?:Configuration|Resources/Private|Tests?|Documentation|docs?)/ - [F]
# Block access to all hidden files and directories with the exception of
# the visible content from within the `/.well-known/` hidden directory (RFC 5785).
RewriteCond %{REQUEST_URI} "!(^|/)\.well-known/([^./]+./?)+$" [NC]
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule (?:^|/)\. - [F]
# Stop rewrite processing, if we are in the typo3/ directory or any other known directory
# NOTE: Add your additional local storages here
RewriteRule ^(?:typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico|admin/) - [L]
# If the file/symlink/directory does not exist => Redirect to index.php.
# For httpd.conf, you need to prefix each '%{REQUEST_FILENAME}' with '%{DOCUMENT_ROOT}'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L]
</IfModule>
生产服务器将是一个专用系统,所以我可以修改任何我想要的东西。
事实证明,我只需要安装 Apache 包,如 this answer