Don't think I have php setup right in nginx virtual host configs - magento

I'm trying to install magento php ecommerce on a virtual server that previously did not have php. When I put simple php pages into a directory they run (for example I have index.php run phpinfo). But when I try to run the magento setup scripts they bomb out without outputting an error. I have two other virtual servers through a different service (running apache) and when I drop the magento files into them the setup pages light up right away and start checking requirements. On my nginx server the only output is a small grey box, but no error output.
My best guess is that I have not configured nginx virtual hosts properly for php.
I am on php5.5 using fpm on Ubuntu 12.04. I don't run a default file in sites-enabled, just two vhost files. Here's the vhost in question (the other site is working fine, but it's python):
server {
listen 80;
listen [::]:80;
#
server_name magento.mydomain.com;
#
root /var/www/magento.mydomain.com/public_html;
index index.php index.html index.htm;
#
# location / {
# try_files $uri $uri/ /index.php =404;
# }
# location / {
# /index.php;
# }
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:8070;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/magento.mydomain.com/public_html/$fastcgi_script_name;
}
}
You can see my commented out location / directives. I have tried those is various fashion. My hunch was that magento was calling php with directory names only (instead of somedir/index.php) so I was messing with those, but it seems like that would be handled by the index directive before the locations.
I'm pretty green with nginx. Does anyone see anything obvious?

Related

Deployment of Laravel project on Debian 9 using nginx

I try to deploy my Laravel project from localhost to Debian server using nginx. First of all, i followed this tutorial LINK. Ended at the end of 5. chapter. I did not get any errors. Also I successfully connect Laravel project with server DB. I use Laravel version 6, so when i was modifying newly created config file on /etc/nginx/sites-available/myFile I used laravel's deployment tutorial LINK. As my server does not have any domain, I've got only IP available. Screenshot of my config file:
Config file
When I try to open server page using IP, i got error "This page isn't working". It's because i deleted nginx's default file from sites-enabled. Before, i deleted the default file, i got only default home page of nginx.
I tried to change server_name like server_name _;, server_name "";, server_name IP. After all changes i restarted nginx server.
Any help how to run my Laravel project please? Thank you!!
EDIT: route to project: /var/www/html/OciNaCeste/BP_final
Please use the following configuration
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /var/www/html/OciNaCeste/BP_final/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
Then restart nginx

how to change index directory of my laravel website

I want to create a website using Laravel Framework in my localhost laragon server
I uploaded the website files in a Web Hosting. and when I enter the url http://www.mywebsite.com. then I just get the files like
But when I enter the url http://www.mywebsite.com/public then it is working perfectly.
Can anyone suggest me that what's I'm doing wrong.
You need to point your domain to public folder of laravel not root since laravel has index.php inside project folder/public/index.php so you need to point project folder/public/
Let suppose you uploaded your application to /var/www/html directory. and your public folder path looks like this /var/www/html/public.
Then your site-available file code should be like this
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/public;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name www.mywebsite.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 the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
You just need to change root path. Then your site will work properly as expected.
i moved all files from public folder (project_folder/public/ )
into project folder
in index.php i changed this lines:
require DIR.'/../vendor/autoload.php';
$app = require_once DIR.'/../bootstrap/app.php';
INTO:
require DIR.'/./vendor/autoload.php';
$app = require_once DIR.'/./bootstrap/app.php';
and works fine ...
Thank you to everyone :)

Hosting Laravel Application on Ubuntu Server

I have recently developed my first Laravel application (version 5.2.).
I now want to host the application on my client's server running Ubuntu.
Their admin managed to install and run the native Laravel application on the server which works just fine, however when I come to copy and paste my own application over, the browser returns:
403 Forbidden
nginx/1.4.6 (Ubuntu)
Accessing the public folder directly (www.example.com/public/index.php) the browser returns:
The www.example.com page isn’t working
www.example.com is currently unable to handle this request.
HTTP ERROR 500
Can anybody please help me out with the proper method of hosting my application?
Seems more like an nginx-problem. Try to change your nginx virtualhost config to this.
server {
listen 80;
server_name yoursite.tld
root /var/www/yoursite/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;
}
}
First save your file inside,
var/www/html/
Then using Terminal go to your folder
cd var/www/html/your_folder
Run Laravel application
sudo php -S localhost:8888 -t public
Make sure your port number is not same as the other Laravel instance running in the server.

nginx, Magento & Cloudfront

I have inherited a website that is running Magento & nginx. I know virtually nothing about nginx and know a fair amount about Magento. The site is configured to use the Amazon Cloudfront CDN however all of the images, js & css are returning a 301 redirect to the origin site. I have a development site running Apache with the same Magento, MySQL & Cloudfront setup that is functioning correctly with this setup so I am pretty sure it is a problem with the config file for nginx. There have been some rewrites written in to the file and my assumption is that when the request for an asset at skin.mydomain.com is made it is redirecting to www.mydomain.com instead of serving the file from the CDN. I have CNAME records setup for js.mydomain.com, skin.mydomain.com and cloud.mydomain.com that all point to the same Cloudfront CDN. Here is the portion of the nginx config file that would seem to be applicable:
server {
listen 80;
##127.0.0.1:8080
server_name mydomain.com;
rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
}
server {
listen 80;
##127.0.0.1:8080 default
## SSL directives might go here
listen 443 default ssl;
ssl_certificate /etc/nginx/
ssl_certificate_key /etc/nginx/
server_name www.mydomain.com;
## *.mydomain.com; Domain is here twice so server_name_in_redirect will favour the www
root /var/www/magento;
location / {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ #handler; ## If missing pass the URI to Magento's front handler
expires 30d;
if ($request_uri ~* "\.(ico|css|js|gif|jpe?g|png)$") {
access_log off;
expires max;
}
port_in_redirect off;
}
Any help would be appreciated as I have been working on this pretty much all day and would like to stop working on it at some point.
Thanks!
It appears the first server directive is forcing a rewrite of the www.
server {
. . .
rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
. . .
}

How do I configure nginx and CodeIgniter?

I'm running nginx on my home computer for development. I also have it linked to DynDNS so I can show progress to my co-worker a bit easier. I can't seem to get nginx to rewrite to CodeIgniter properly. I have CodeIgniters uri_protocol set to REQUEST_URI.
All pages that should be showing up wtih content show up completely blank. If I phpinfo(); die(); in the index.php file of Codeigniter, it works as expected and I get the phpinfo.
Also, pages that should give a 404 give a proper CodeIgniter 404 error.
Here's what I have so far.
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
#gzip on;
#gzip_disable "MSIE [1-6]\.(?!.*SV1)";
root /home/zack/Development/public_html;
include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
server {
listen 80;
server_name zackhovatter.dyndns.info;
index index.php;
root /home/zack/Development/public_html;
location /codeigniter/ {
if (!-e $request_filename) {
rewrite ^/codeigniter/(.*)$ /codeigniter/index.php/$1 last;
}
}
#this is for the index.php in the root folder
location /index.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/zack/Development/public_html/index.php;
include fastcgi_params;
}
location /codeigniter/index.php {
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/zack/Development/public_html/codeigniter/index.php;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param PATH_INFO $document_uri;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass 127.0.0.1:9000;
}
}
}
Actually I got this working. Not sure how, but I think it was file permissions being set incorrectly or something.
Edit:
For those who are wondering, I had an older version of PHP installed it seems. Reverting back to old class constructors fixed the issue. Darnit.
I have exactly the same problem (Codeigniter gives blank pages and the error pages and php are working) and i found that the problem was from the mysql db driver which should be changed to mysqli driver .
So just we need to change the db driver in config/database.php
$db['default']['dbdriver'] = 'mysqli';
And this is due that the mysql driver is deprecated in the new versions of php.
CodeIgniter4 How To Setup NGINX Server Blocks (Virtual Hosts) on RasperyPi Debian 10.4
I am using a RasperyPi-4 as web developing server with different projects running on it.
Visual Studio Code enables editing files via Remote-SSH extension very easily.
Setting up CI4 on NGINX gives you the opportunity to run different projects on the same server.
Because it took me some days to get this configuration running I will give you a quick reference guide to setup quick and easy.
If you have not installed NGINX and composer yet please have a look here:
http://nginx.org/en/docs/beginners_guide.html
https://codeigniter4.github.io/userguide/installation/installing_composer.html
https://getcomposer.org/download/
CodeIgniter4 installation via composer
server ip: 10.0.0.10
port: 8085
project name is 'test'
Please modify to your needs!
cd /var/www/html
composer create-project codeigniter4/appstarter test
the command above will create a 'test' folder /var/www/html/test
Modify the 'env' file
sudo nano /var/www/html/test/env
app.baseURL = 'http://10.0.0.10:8085'
Important: Do NOT use 'localhost' for the server URL!!!!!
please uncomment:
# CI_ENVIRONMENT = production
and modify:
CI_ENVIRONMENT = development
Save the file as '.env' to hide the file
NGINX Server Blocks
cd /etc/nginx/sites-available
touch test
sudo nano test
Paste this into the file and save after modifying to your requirements:
server {
listen 8085;
listen [::]:8085;
server_name test;
root /var/www/html/test/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm:
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
# With php-cgi:
# fastcgi_pass 127.0.0.1:9000;
}
error_page 404 /index.php;
# deny access to hidden files such as .htaccess
location ~ /\. {
deny all;
}
}
After saving the file create a symbolic link to sites-enabled:
cd /etc/nginx/sites-enabled
sudo ln -s /etc/nginx/sites-available/test /etc/nginx/sites-enabled/test
Modify File and Group Permissions
chown -v -R pi:www-data /var/www/html/test
sudo chmod -v -R 775 /var/www/html/test
Start NGINX
sudo service nginx start
Open CI4 Welcome Page
http://10.0.0.10:8085
Here is a solution.
https://web.archive.org/web/20120504010725/http://hiteshjoshi.com/linux/secure-nginx-and-codeigniter-configuration.html
Also, I had to change $config['uri_protocol'] = “DOCUMENT_URI”; to make it work.
UPDATE: Fixed the 404 url from web archive.

Resources