engamr
By:
engamr

laravel 5 application download file instead of execute on LEMP

August 8, 2017 437 views
Nginx PHP Frameworks LEMP Ubuntu 16.04

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;

    }
1 Answer
jtittle MOD 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
Have another answer? Share your knowledge.