Hi All,
I have a problem and I am stuck since the last 10days. I have followed every tutorial published on digital ocean and not able to figure out. I am trying to run PHP file on my Nginx web server and since I am not able to execute file instead of its downloading.
My conf file looks like this:
server {
# 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/joshiviral.com/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.html index.nginx-debian.html;
server_name www.joshiviral.com joshiviral.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
#include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
#fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files if Apache's document root
# concurs with Nginx's one
#
#location ~ /\.ht {
#deny all;
#}
#listen [::]:443 ssl ipv6only=on; # managed by Certbot
#listen 443 ssl; # managed by Certbot
#ssl_certificate /etc/letsencrypt/live/joshiviral.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/joshiviral.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
server {
listen 80;
listen [::]:80;
server_name www.joshiviral.com joshiviral.com;
root /var/www/joshiviral.com/html;
index index.php index.html index.html index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
if ($host = www.joshiviral.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = joshiviral.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name www.joshiviral.com joshiviral.com;
return 404; # managed by Certbot
}
I have also uncommented CGI path=‘0’ and also tried clearing my cache but since now not working. Can anyone let me know how I can figure it out? I have also followed tutorials
But though not working. There is a weird thing I have installed php7.4.6. And while routing on the 7.4.6 folder, there is an Apache folder. Can anybody let me know how I can solve it?
Thanks in Advance.
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!
Hi there @viraljayeshjoshi94,
If you have Apache already installed this might be causing the issue for you. If you don’t need it, you could stop it by running the following commands:
- sudo systemctl stop apache2
- sudo systemctl disable apache2
After that make sure that your Nginx service is running:
- sudo systemctl status nginx
If it is not running, you can start it with:
- sudo systemctl start nginx
Let me know how it goes! Regards, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
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
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.