I have just installed a fresh copy of Laravel 5 into /var/www.
When I browse to the server I get net::ERR_CONNECTION_REFUSED.
My Nginx config (default) is:
server {
listen 80;
root /var/www/public;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Any idea what I'm doing wrong?
I am also confused about sites-enabled and sites-available. Where should default actually go?
I have moved default from sites-available to sites-enabled and I am now getting a 403 with "Access denied".
You probably got net::ERR_CONNECTION_REFUSED because you hadn't told nginx what port to listen on (note the listen 80 line in your config file), so you were trying to a port that wasn't open - hence the connection refused error.
As for sites-available vs sites-enabled, that's a Debian/Ubuntu thing to make sites easier to manage - you can have many sites configured in sites-available, but only run specific ones by adding a link in sites-enabled pointing at the respective config file in sites-available.
As an example, my sites-enabled folder has
lrwxrwxrwx 1 root root 40 Feb 8 07:53 site.net -> /etc/nginx/sites-available/site.net
No copying, just a link to sites-available.
For your 403 error, look in your error log for what precisely is failing. It should be located at /var/log/nginx/error.log - look for error_log in your main conf file to get the exact location.
Related
I currently get a warning on Wordpress saying I am on an insecure version of PHP (7.3.3).
I've been trying to follow the instructions on the following page to update the version to PHP 8.1.
https://www.cloudbooklet.com/how-to-install-or-upgrade-php-8-1-on-ubuntu-20-04/
I was able to install and enable php8.1 but stuck with the remaining steps. The article tells me to update a few lines in the location block of a conf file but I can't find it.
I looked at files like wordpress_https conf but could only find lines like this:
location ~ \.php(?:$|/) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
Any pointers on where I need to update the reference to php8.1? It's nginx server on Obuntu 20.04. It's for a Wordpress application installed on Vultr. Thanks.
Try this in your site' nginx config file. Comment out everything in your file or just backup the file and try this.
upstream php {
server unix:/tmp/php-cgi.socket;
server php:9000;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl;
server_name example.test www.example.test;
ssl_certificate /etc/nginx/ssl/example.test.pem;
ssl_certificate_key /etc/nginx/ssl/example.test-key.pem;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
#The only job of this block is to redirect http to https
server {
listen 80;
listen [::]:80;
server_name example.test www.example.test;
return 301 https://$server_name$request_uri;
}
Depending on your OS, the nginx config file for your website will either be in /etc/nginx/conf.d or in /etc/nginx/sites-available/ .
The above configuration was taken from this WordPress docker dev env.
After making the edits in the correct conf file, test nginx:
sudo nginx -t
If all is well in the conf file restart nginx based on your system i.e :
sudo service nginx restart
If this works for you, ensure you search for more security details you can add in your configuration to improve it. If it does not work for you, you can generate WP specifc Nginx configurations using DigitalOcean.
I installed Nginx & PHP using this guide here:
Nginx install guide
yum install php php-mysql php-fpm
edited /etc/php-fpm.d/www.conf
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = nobody
listen.group = nobody
listen.owner = nobody
listen.group = nobody
ran:
systemctl start php-fpm
/etc/nginx/conf.d/default.conf
server {
listen 80;
server_name <my servers IP here - removed>;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;
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_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I then tested
http://<my server ip>/phpinfo.php
and it worked!
I then installed pear
yum install php-pear
but now php files don't work, the browser tries to download them instead of running them.
I've tried:
rebooting the server
restarting nginx
restarting php-fpm
checking all the config files to make sure they as the same as above.
I'm completely stuck. I don't know what to check to get php work again. This is the first time I've installed Nginx. I've looked around on the net for answers and on here.
I'm running Centos 7
help :)
UPDATE:
I've tried a much more shortened config file:
server {
listen 80;
server_name <my servers IP here - removed>;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
but that didn't work either.
I also tried:
fastcgi_pass 127.0.0.1:9000;
instead of:
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
but that didn't work too.
UPDATE 2
i found out that if I go to:
http://my ip/phpinfo.php - it works!
but if I go to:
http://domainname/phpinfo.php - it tries to download the PHP file instead of running it.
How do I make php files run while using the domain name instead of the IP?
According your second update, you have problem with Listen directive. nginx listen only IP-address or Domain name that mentioned in Listen directive. Maximillian gives you right answer. It you put listen 80 in your configuration file, you'll solve your problem, but there would be wotk only one site, with this listen. If you would like to configure PHP on your domain you could configure listen yourdomain.com:80.
Have you tried to edit
/etc/nginx/sites-enabled/default ?
Then you need to edit it as follows.
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
afterward, you have to restart php-fpm and nginx
service nginx restart && service php-fpm restart
Try with below config for location,
location ~ .php$ {
root html;
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;
}
And do clear cache beforehand.
For your 2nd update try below in server block,
listen 127.0.0.1:8000; #your ip with port
server_name example.com; #domain name
Recently I also need to setup linux and php environment, so I strictly follow your step to setup it.
I encounter this two issue when I setup the LEMP environment,
a. nginx issue, post and answer
b. php-fpm issue, post and answer
I don't encounter the issue you face, so I show the environment for you, you may compare with yours.
Centos Version
vi /etc/centos-release
CentOS Linux release 7.3.1611 (Core)
Mysql version
mysql -u root -p
//enter password
Server version: 5.5.52-MariaDB MariaDB Server
Php version
php -v
PHP 5.4.16 (cli) (built: Nov 6 2016 00:29:02)
Pear info
pear list // refer to this post
Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.11 stable
Console_Getopt 1.3.1 stable
PEAR 1.9.4 stable
Structures_Graph 1.0.4 stable
XML_Util 1.2.1 stable
Nginx config file
vi /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name 192.168.236.129;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;
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_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
info.php vi /usr/share/nginx/html/info.php
<?php phpinfo(); ?>
I believe I have set up an nginx virtual host file correctly, however, I'm not able to navigate to that URL on the host machine. I have a slight feeling that I'm misunderstanding something here.
Here's the situation.
I have a Vagrantfile that does the following:
Installation of Required Packages
Composer Update
Copies an Nginx Virtual Host file over to Nginx
Restarts all relevant services
Heres the vhost file:
server {
listen 80;
server_name vagrant;
root /usr/share/nginx/www;
index index.html index.htm index.php;
location / {
try_files $uri /index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
I can verify that when the virtual host file was called simply vagrant and the server name was set to the following server_name _; that a page was rendered when I visited localhost.
As I'm trying to set up Magento, which doesn't work well with localhost domains, I'm trying to set up a name based virtual host for it under the domain dev.magento.co.uk
If I ssh into the vagrant installation, I can verify that the dev.magento.co.uk file is in the /etc/nginx/site-enabled directory and that it's contents were copied over correctly.
What am I missing?
I've just installed Laravel 4 with nginx on my ubuntu vps following this tutorial:
https://www.digitalocean.com/community/articles/how-to-install-laravel-with-nginx-on-an-ubuntu-12-04-lts-vps
Evertything seemed to be installed fine, however when browsing it's ip adress, I still get:
It works!
This is the default web page for this server. The web server software is running but no content has been added, yet.
I thought this could have something to do with the virtual host, but that one seems to be configured correctlt aswell
server {
listen 80 default_server;
root /var/www/laravel/public/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Would anynone know what I'm doing wrong?
Thank you!
Your web server should point to the /public folder not the root of your laravel application.
That is /var/www/laravel/public not /var/www/laravel/.
Also make sure you restart your server to load up configuration files.
I'm having some trouble getting nginx to work on a subdomain. I have two conf files in /etc/nginx/conf.d/ as follows (some details in the first redacted):
mydomain.conf: the site proper, server_name of mydomain.com and www.mydomain.com:
server {
listen 80;
root /var/www/sites/mydomain;
index index.php;
server_name mydomain.com www.mydomain.com;
access_log /var/log/nginx/mydomain.access.log;
error_log /var/log/nginx/mydomain.error.log;
...
}
phpmyadmin.conf:
server {
listen 80;
root /var/www/sites/phpmyadmin;
index index.php;
server_name pma.mydomain.com;
access_log /var/log/nginx/phpmyadmin.access.log;
error_log /var/log/nginx/phpmyadmin.error.log;
location / {
index index.php;
}
location ~* \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Currently, /var/www/sites/phpmyadmin just contains an index.php with <?php phpinfo(): ?> in it and nothing else. This is on an EC2 instance and I'm trying to load the pages from another computer, wherein both mydomain.com and pma.mydomain.com are set to its IP address in my /etc/hosts.
Navigating to mydomain.com works perfectly fine, PHP works, etc. However when I navigate to the subdomain, it hangs. For any other subdomain the connection immediately fails (there are no DNS records). But for pma it simply doesn't load.
My log files for pma are empty and unhelpful. I have no idea how to debug this silent failure and it's driving me insane.
Probably an issue with the FastCGI handler (are you using php-fpm?) running at 127.0.0.1:9000 - is it running and accepting connections?
Debug it by SSHing to that machine and running:
curl -vv http://127.0.0.1:9000/
What happens?