Laravel PHP Framework: Difference between revisions
No edit summary |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 32: | Line 32: | ||
== NGINX Setup == | == NGINX Setup == | ||
This configuration is for NGINX with PHP and | This configuration is for NGINX with PHP and FastCGI using FPM: | ||
<pre>server { | <pre>server { | ||
listen 80; | listen 80; | ||
server_name localhost; | server_name localhost; | ||
location / { | location / { | ||
Line 46: | Line 43: | ||
} | } | ||
error_page 404 /404.html; | |||
error_page 500 502 503 504 /50x.html; | error_page 500 502 503 504 /50x.html; | ||
location = /50x.html { | location = /50x.html { | ||
root /usr/share/nginx/html; | root /usr/share/nginx/html; | ||
Line 72: | Line 67: | ||
rewrite /laravel/laravel2/(.*)$ /laravel/laravel2/index.php?/$1 last; | rewrite /laravel/laravel2/(.*)$ /laravel/laravel2/index.php?/$1 last; | ||
} | } | ||
location ~ [^/]\.php(/|$) { | |||
fastcgi_pass 127.0.0.1:9000; | |||
fastcgi_index index.php; | |||
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name; | |||
include fastcgi_params; | |||
} | |||
location /prscout { | |||
alias /usr/share/nginx/html/prscout/; | |||
try_files $uri $uri/ @prscout; | |||
index index.php; | |||
location ~ \.php$ { | |||
fastcgi_pass 127.0.0.1:9000; | |||
fastcgi_param SCRIPT_FILENAME $request_filename; | |||
fastcgi_read_timeout 300; | |||
include fastcgi_params; | |||
} | |||
} | |||
location @prscout { | |||
rewrite /prscout/(.*)$ /prscout/index.php?/$1 last; | |||
} | |||
}</pre> | }</pre> |
Latest revision as of 02:21, 19 March 2022
Making Subdirectories Accessible without a Public folder
Technically there is some risk to this since it could potentially expose configuration files in the root directory. I negate this somewhat by adding a DENY rule to .env files. I still wouldn't recommend it for a production site, but I find it useful for development and preventing the need to create apache config files for every Laravel project.
- Create a Laravel project
laravel create newproject
- Rename the 'server.php' file to 'index.php' in the root directory
- Add a .htaccess file to the root directory:
<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On RewriteRule ^(.*)/$ /hello/index.php/$1 [L] </IfModule> <Files .env> Order Allow,Deny Deny from all </Files>
Note: Customize the RewriteRule line to match your subdirectory.
NGINX Setup
This configuration is for NGINX with PHP and FastCGI using FPM:
server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.php index.html index.htm; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location /laravel/laravel2 { alias /usr/share/nginx/html/laravel/laravel2/public; try_files $uri $uri/ @laravel2; index index.php; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params; } } location @laravel2 { rewrite /laravel/laravel2/(.*)$ /laravel/laravel2/index.php?/$1 last; } location ~ [^/]\.php(/|$) { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name; include fastcgi_params; } location /prscout { alias /usr/share/nginx/html/prscout/; try_files $uri $uri/ @prscout; index index.php; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_read_timeout 300; include fastcgi_params; } } location @prscout { rewrite /prscout/(.*)$ /prscout/index.php?/$1 last; } }