I have a project running under php, but I have a third party subfolder(download folder) that I want to add into the current project.
Meaning, root folder = testlaravel =>www.testlaravel.com
with sub folder = testlaravel/download => www.testlaravel.com/download
Is there anyway I can do this?
Are you using Apache or Nginx ? If Apache, you need to config your vhost file to serve Laravel from a sub-folder. Particularly, you need to configure that when testlaravel.com/download URI is requested, it should be served using /home/testlaravel/download/public directory (basically different root/home location).
You also need to use mod_rewrite to rewrite your URL requests to the sub-folder be served from index.php from above location (and also prettify URLs).
Similarly, your configuration in vhost for your main website will be different (so there will be 2 configurations, one for your main website and one for laravel requests)
The above should work just fine since its done same way in Nginx, for which I have included a full example of how its conf file should look
Here is how I setup-ed my location block which is working for me perfectly:
location ^~ /facebookschedule {
alias /home/netcans/facebookschedule/public;
try_files $uri $uri/ #foobar;
location ~ \.php {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/wwww/facebookschedule/public/index.php;
}
}
location #foobar {
rewrite /facebookschedule/(.*)$ /facebookschedule/index.php?/$1 last;
}
Source: http://shubhank.gaur.io/setup-laravel-5-in-subfolder-with-nginx/
I am using the following configuration, which is simpler than most other published solutions, and which does not require any paths/folders to be hard-coded.
We simply prefix all requests with public/ and then remove it from SCRIPT_NAME so that the application can autodetect its environment correctly.
location ~ /myproject/(.*) {
rewrite /myproject(.*) /myproject/public/$1 break;
try_files $uri /myproject/public/index.php$is_args$args;
location ~ /index\.php$ {
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_NAME /myproject/index.php;
}
}
Related
I have been stucked with this for a while. We have a Symfony 2.8 project and I want to deploy it to the cloud. I have properly created the ElasticBeanstalk environment and it works! But I still need to access http://domain/app.php in order to make it work. I managed to delete web/ changing documentDirectory part from URL but app.php is still there.
I have also tried with a new brand project following this:
https://docs.aws.amazon.com/es_es/elasticbeanstalk/latest/dg/php-symfony-tutorial.html
But when I change it to public/ happens to me the same I need to use index.php in the URL
I have modified NGINX conf following:
https://community.bitnami.com/t/how-to-change-default-root/65639/9
https://symfony.com/doc/current/setup/web_server_configuration.html
This is what I added to /etc/nginx/nginx.conf.default
location / {
try_files $uri $uri/ /app.php$is_args$args;
}
location ~ \.php$ {
try_files $uri $uri/ =404;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index app.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
I have restart nginx service using
sudo service nginx restart
but it remains the same.
I have also tried renaming app.php to index.php just in case. But I need to add /index.php to the URL then.
Any idea?
Use the index nginx directive to make app.php the default handler of http://domain/ requests:
server {
...
index app.php;
# your locations here
}
There are some things you can try.
https://symfony.com/doc/2.8/setup/web_server_configuration.html#nginx
Here you can find a configuration for your project. There you can see that the location is rewritten to the app.php.
location ~ ^/(app_dev|config)\.php(/|$) {
so i would suggest to take the configuration and test it.
Some PHP URLs are being downloaded instead of executed by Nginx. I have an existing web application which is functioning fine. I'm tasked with adding additional mounted applications within folders of the primary application. Each of these applications has its own front controller index.php script.
For this setup, I've created symlinks inside $document_root/app, and the symlinks point to a folder containing an index.php front controller.
When I navigate to most URLs, everything works fine, the primary application front controller is executed, and I get expected results. When I navigate to a non-existent app, I get 404 Not Found from nginx, which is expected. But when I navigate to one of the applications, the browser downloads the application front controller.
root /my/web/root;
location / {
try_files $uri
/$server_name$uri
/shared$uri
/index.php$is_args$args;
}
location ~ [^/]\.php(/|$) {
disable_symlinks off;
fastcgi_split_path_info ^(.+\.php\b)(.*)$;
fastcgi_param SERVER_NAME $host;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_pass php-fpm;
}
location ~ ^/app/([a-z-]+)(/.*)?$ {
try_files $uri
/app/$1/index.php$is_args$args
=404;
}
URL which triggers download: /app/my-app/ (exists)
URL which 404s: /app/foo/ (does not exist)
URL which executes: /foo
The .php file needs to be processed by the location ~ [^/]\.php(/|$) block. You have a common document root which makes things simpler.
However, look at this document regarding the location directive.
You will see that the regex locations are considered in order and the first matching location will be used to process the request.
In short, you need to place the location ~ [^/]\.php(/|$) block before any other conflicting regex location, if you want your .php files to be processed correctly.
I am using Symfony2 (PHP) framework for my project and is having a small problem with regards to configuring my NGINX to catch request going to a 3rd party library I placed under "web" directory.
This is my configuration
server {
listen 80;
server_name test.com;
root /var/www/my-symfony-project/web;
rewrite ^/app\.php/?(.*)$ /$1 permanent;
location / {
index app.php;
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
As you may have noticed that the root is pointed in "/var/www/my-symfony-project/web" directory.
Now, the problem is that I have this "some-plugin" folder inside the "web" directory and there are PHP files from there that are not handled by the Symfony2 routing.
I actually made it work when I have the following "location" block inside the "server" block illustrated above.
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
}
It seems okay having this type of configuration at first but we realized that it accepts request to any "*.php" file to which we evaluated as a security breach.
Any suggestions?
Allowing access to .php files is usually not considered dangerous or a security breach, as long as the PHP files are executed and not served in their source form and, of course, don't print any sensitive information.
If either of the former are not the case, you should probably change your setup or your code.
Anyway, you should be able to restrict the .php file handling to /var/www/my-symfony-project/web/some-plugin by using the following as location:
location ~ ^/var/www/my-symfony-project/web/some-plugin/.*\.php$ {
# your rules here
}
This should match all files whose path starts with /var/www/my-symfony-project/web/some-plugin/ and end with .php in upper or lower case.
I tried to learn and configure phalcon by testing INVO sample application
It appears that the tutorial doesn't include nginx config for the testing so that I got some difficulty to test the sample application.
I used nginx as the web server, I took nginx configuration from here
Here is my nginx config:
server {
listen 80;
server_name local.phalcon.dev;
access_log /Users/mylocal/www/log/phalcon.access.log;
error_log /Users/mylocal/www/log/phalcon.error.log;
index index.php index.html index.htm;
set $root_path '/Users/mylocal/www/phalcon/current';
root $root_path;
try_files $uri $uri/ #rewrite;
location #rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;
include /usr/local/etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /\.ht {
deny all;
}
}
Looking at the tutorial, I believe the structure is like this:
webroot
invo
app
...
public
index.php
...
...
which means, webroot is my /Users/mylocal/www/phalcon/current
and I should be able to access it with this url http://local.phalcon.dev/invo
It lead to 403 forbidden which is understandable because it appears that we should rewrite path from webroot/invo to webroot/invo/public
I did some trial and error changing the configuration but found no luck, can somebody help me to configure the nginx config for that tutorial? (which means accessing it from http://local.phalcon.dev/invo)
PS:
I was able to access it by changing the $root_path into /Users/mylocal/www/phalcon/current/invoice/public
and changing the $url->setBaseUri($config->application->baseUri); into $url->setBaseUri('/'); in invo/public/index.php
but that means I accessed it from url http://local.phalcon.dev NOT http://local.phalcon.dev/invo
To access it via http://local.phalcon.dev/invo instead of http://local.phalcon.dev all you need to do now is to configure the routing. I think in your case you simply need to set the base uri as per this example:
//Setup a base URI so that all generated URIs include the "tutorial" folder
$di->set('url', function(){
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri('/tutorial/');
return $url;
});
I'm also getting a feeling that you also want to use http://local.phalcon.dev for other Phalcon apps? If that's the case then it will not work. All requests are forwarded to index.php, which rules out what to do. You can create multi-module app, but you can't have different apps sittings on the same domain (without serious pain).
the only directory which should be available via url is public. You home direcotry must end with public something like:
/Users/mylocal/www/phalcon/public
and you will be able to use base dir of /:
$di->set('url', function(){
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri('/');
return $url;
});
of course you can use whatever name for your public dir, but not recommended, because if you will want to use phalcon's devtools, they are working with home dir called "public"
Please check app/config/config.ini file. There is a "baseUri" section.
1. nginx root_path should be "webroot/invo/public.
2. phalcon code: app/config/config.ini -> baseUri = /
3. url: local.phalcon.dev
I have a Slicehost slice for a dev server, with nginx and PHP.
I'm trying to get drupal running on localhost/drupal and a codeigniter app running on localhost/codeigniter.
I can get one or the other to work, but not both -- the rewrite and fastcgi seem to be interfering with one another.
Does anyone know how to have /drupal and /codeigniter both working, with rewrite rules (for SEF URLs), in separate folders in my /var/www?
Cheers.
Ok, you have to create a file (no extension needed) in /etc/nginx/sites-available that represents the name of your folder/domain (ex: drupal, yoursite.com).
Here's a sample file:
server {
server_name yourdomain.com;
root /var/www/yourdomain;
index index.php;
location / {
autoindex on;
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
In the sample above it will actually send url rewrites to $_SERVER['REQUEST_URI']. For more nginx rewrites, you can take a look at http://wiki.nginx.org/HttpRewriteModule for more reference.
Then you want to enable it by creating a symlink of this file in your /etc/nginx/sites-enabled folder
Example: # ln -s /etc/nginx/sites-available/yoursite /etc/nginx/sites-enabled/yoursite
Then restart/reload nginx
# services nginx reload