By jaredomano
I’m sure this is kind of a duplicate question, but I’ve tried googling this to no avail. I’m trying to make a site that will just run a php script on a button press. I’m trying to get php to work right, so I have an info.php file here:
<?php
phpinfo();
?>
Now, whenever I try to go to this file in my webpage: jarofmilk.com/info.php it just tries to download it instead of render it. I feel like I’ve tried everything under the sun to fix this, but I have no clue whats going wrong with it.
Here’s my default nginx conf:
server {
listen 8000 default_server;
listen [::]:8000 default_server;
server_name jarofmilk.com www.jarofmilk.com;
root /var/www/jarofmilk.com/public_html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.html;
}
location ~ \.php$ {
try_files $uri =404;
include snippets/fastcgi-php.conf;
# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
#fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
PHP Version:
php --version
PHP 7.0.33-0ubuntu0.16.04.16 (cli) ( NTS )
Nginx Version:
$ nginx -v
nginx version: nginx/1.10.3 (Ubuntu)
Ubuntu Version:
Ubuntu 16.04.6 LTS
I appreciate any insight. I’ve already uninstalled and reinstalled php. I’m sure this is a repeat question, but I’ve looked over most of the other stackoverflow results, and nothing worked for me.
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,
The configuration looks good actually. I could suggest a couple of things:
systemctl status php7.0-fpm.service
listen address is set to the socket file that you’ve specified in your Nginx config. You can do that by viewing the following file:/etc/php/7.0/fpm/pool.d/www.conf
And search for the following line
listen = /run/php/php7.0-fpm.sock
If those things are all good, I would recommend clearing your browser’s cache and also checking your Nginx error log:
tail -100 /var/log/nginx/error.log
Regards, Bobby
Because your php configuration should be inside your main site’s server block, not in the default server block.
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
server {
listen 80;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name foo.com www.foo.com;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php;
#try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
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.