Question

laravel 5 application download file instead of execute on LEMP

hello now I try to deploy two project in one droplet one for front end ( angular js application) and each other for api (laravel application) and this point to sub-domin i followed this tutorial for do this 1- create sup domain here 2- deploy to project in one deoplet here 3- delopy larave on LEMP here

the front end app work fine but backend in laravel when I access to it file in public download instead of execute

this is my web site config this for front end

server {
	listen 80;
	listen [::]:80;

	root /var/www/panakeis_front/html;
	index index.php index.html index.htm;

	# Make site accessible from http://localhost/
	server_name panakeias.con www.panakeias.com;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
                  try_files $uri $uri/ /index.php?$query_string;
		# Uncomment to enable naxsi on this location
		# include /etc/nginx/naxsi.rules
	}

	error_page 404 /404.html;
	error_page 500 502 503 504 /50x.html;
	location = /50x.html {
		root /usr/share/nginx/html;
	}

	location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}

	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	#location ~ /\.ht {
	#	deny all;
	#}
}

this for backe end ( project contain issue )

server {
	listen 80;
	listen [::]:80 ;

	# SSL configuration
	#
	# listen 443 ssl default_server;
	# listen [::]:443 ssl default_server;
	#
	# Note: You should disable gzip for SSL traffic.
	# See: https://bugs.debian.org/773332
	#
	# Read up on ssl_ciphers to ensure a secure configuration.
	# See: https://bugs.debian.org/765782
	#
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	#
	# include snippets/snakeoil.conf;

	root /var/www/panakeis_project/html;
	# Add index.php to the list if you are using PHP
	index index.php index.html index.htm index.nginx-debian.html;

	server_name api.panakeias.com www.api.panakeias.com;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ /index.php?$query_string;

	}

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Jonathan Tittle
DigitalOcean Employee
DigitalOcean Employee badge
August 9, 2017
Accepted Answer

@engamr

If the backend (API) is using PHP, you’d need to set a location block for PHP as you did in the first. All location blocks are specific to the server block they’re contained within – they’re not global or shared across other server blocks.

You’ll need to copy:

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

And paste that below:

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.php?$query_string;

    }

… on the second server block and then run:

nginx -t

… to test the configuration (always recommended before doing a restart). If all looks good, then you’d restart NGINX:

service nginx restart

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.