在现有的Apache Web服务器上运行苗条框架 [英] Running slim framework on existing apache web server
问题描述
我是苗条框架的新手.目前,在我现有的网络服务器上(在centos 7上),我正在运行其他基于php的应用程序.所以目前我的目录结构是这样的.
I am new to slim framework. Currently on my existing webserver which is on centos 7 I have other php based application running. So currently my directory structure is like this.
var/www/html
phpapp1
phpapp2
apislim
我创建的apislim文件夹用于苗条框架.以下是我所做的确切步骤1.作曲者create-project slim/slim-skeleton
2.我将slim-skeleton文件夹重命名为apislim3.我确保所有者是apache chown -R apache:apache apislim4.在httpd.conf中,确保此AllowOverride启用为All
The folder for the apislim I created was for slim framework.
Below are the exact steps I did was
1. composer create-project slim/slim-skeleton
2. I rename the slim-skeleton folder to apislim
3. I make sure the owner is apache chown -R apache:apache apislim
4. In the httpd.conf I ensure this AllowOverride is enabled to be All
<Directory "/var/www">
AllowOverride All
# Allow open access:
Require all granted
Options -Indexes
</Directory>
下面我也启用了全部
<Directory "/var/www/html">
Options -Indexes -FollowSymLinks
AllowOverride All
</Directory>
-
在apislim/public文件夹中,我有以下.htaccess文件.
In the apislim/public folder I have this .htaccess file as below.
RewriteEngine开启
RewriteEngine On
RewriteCond%{REQUEST_URI} :: $ 1 ^(/.+)/(.):: \ 2 $RewriteRule ^(.)-[E = BASE:%1]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.)::\2$ RewriteRule ^(.) - [E=BASE:%1]
RewriteCond%{REQUEST_FILENAME}!-fRewriteRule ^(.*)$%{ENV:BASE} index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
我在公用文件夹中也有index.php文件,该文件也链接到路由的src和主文件夹apislim,我创建了另一个.htaccess文件并添加了它.
The I have also the index.php file in the public folder which also links up to the src for the routes and the main folder apislim I created another .htaccess file and added this.
RewriteEngine开启RewriteRule ^ $ public/[L]RewriteRule(.*)public/$ 1 [L]
RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L]
现在的问题是,我希望现有的应用程序可以与该基于slim框架的rest api一起使用.所以当我转到此链接
The issue now I want my existing application to work along with this rest api which is based on slim framework. So when I go to this link
http://*.*.*.*/apislim/
http://*.*.*.*/apislim/public/
http://*.*.*.*/apislim/public/index.php
它们都不起作用,都禁止我给我403.然后我检查错误日志,它显示有关FollowSymLinks的错误所以我加了选项-索引+ FollowSymLinks进入
Neither of it works all are giving me 403 forbidden. Then I check the error log it show error regarding FollowSymLinks So I added Options -Indexes +FollowSymLinks Into
所以我现在得到的下一个错误是500间隔服务器错误.
So next error I get now is 500 interval server error.
推荐答案
为使Slim 3应用程序在子目录中工作,必须执行以下步骤.
The following steps are necessary for your Slim 3 application to work within subdirectories.
目录结构:
public/
Web server files (the DocumentRoot).htaccess
Apache redirect rules for the front controllerindex.php
The front controller
文件内容:
.htaccess
:RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L]
文件内容:
public/.htaccess
:# Redirect to front controller RewriteEngine On # RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L]
将此容器条目添加到文件中:
dependencies.php
:Add this container entry to the file:
dependencies.php
:// Activating routes in a subfolder $container['environment'] = function () { $scriptName = $_SERVER['SCRIPT_NAME']; $_SERVER['SCRIPT_NAME'] = dirname(dirname($scriptName)) . '/' . basename($scriptName); return new Slim\Http\Environment($_SERVER); };
编辑:在Slim 4中,您应使用
$ app-> setBasePath($ basePath);
方法.更多详细信息Edit: In Slim 4 you should use the
$app->setBasePath($basePath);
method. More details这篇关于在现有的Apache Web服务器上运行苗条框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!