Ubuntu 14 - Nginx - PHP5-fpm : installed phpmyadmin but 403 forbidden access - nginx

Nginx and PHP5-FPM are installed and running well ...
# I can access both http://www.example.com and http://www.example.com/info.php
$ ls -la /var/www/html
-rw-r--r-- 1 root root 868 Nov 1 08:16 index.html
-rw-r--r-- 1 root root 21 Nov 1 08:13 info.php
I installed phpmyadmin and created a symlink to phpmyadmin files
lrwxrwxrwx 1 root root 21 Nov 1 08:37 phpmyadmin -> /usr/share/phpmyadmin
but trying to get http://www.example.com/phpmyadmin => I get a 403 Forbidden
using a symlink, I should not have to add anything related to phpmyadmin into my nginx.conf ... what could be missing ?
Update 1 : adding index.php to the uri brings the login panel
http://www.example.com/phpmyadmin/index.php
what should I add to my default con file to get it directly ... I guess my try file is not valid ..
here is my default nginx site con file
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php, index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ index.html index.php =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

it's running fine after adding the following location :
location /phpmyadmin {
index index.php;
}

That's my solution for this issue:
Step 1: You should SSH and run command
sudo nano /etc/nginx/sites-available/default
Step 2: find block code
server {
....
}
and then insert before "}" of server block
location /phpmyadmin {
index index.php;
}
It look like this
server{
...(your default)...
location /phpmyadmin {
index index.php;
}
}
Hope this is your!

I have added:
location /pma/ {
alias /usr/share/phpmyadmin/;
index index.html index.htm index.php;
location ~ ^/pma(.+\.php)$ {
alias /usr/share/phpmyadmin$1;
fastcgi_pass unix:/var/run/php5-fpm.sock; #OR fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$1;
include fastcgi_params;
fastcgi_intercept_errors on;
}
}
So that when the user access the directory /pma/ they get directed to the /usr/share/phpmyadmin which is a slightly 'safer' option too! As previously I was having the 403 error too!
But the main fix for the 403 error is actually implementing the line:
index index.html index.htm index.php;

to nginx.conf file or default ( ../sites-available/default )
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}

Here are a couple things you could try. One is the disable_symlinks directive:
location /phpmyadmin {
disable_symlinks off;
}
Another option would be to use an alias instead of a symlink:
location /phpmyadmin {
alias /usr/share/phpmyadmin;
}

Lose the comma and you're fine
index index.php, index.html index.htm;

Related

NGINX 404 all pages

So I have two issues that I am trying to do. First I am trying to understand NGINX and use it for redirects and everything as well; however, if I try to remove the extensions from the php / html files it just downloads the file. If I use another thing to just try (without the file extension try) it just gives me 404s. I am not sure what the issue is nor what I am doing wrong.
First I'll show my remove php file extension issue:
server {
listen 443;
server_name XXX.XX.XX.XX;
root /var/www/html;
location / {
try_files $uri $uri.html $uri/ #extensionless-php;
index index.html index.htm index.php;
}
location ~ \.php$ {
try_files $uri =404;
}
location #extensionless-php {
rewrite ^(.*)$ $1.php last;
}
}
Here is my other code to fix the problem above (but just gives me 404s)
server {
listen 443;
server_name XXX.XX.XX.XX;
root /var/www/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 /var/www/html;
}
location ~ \.php$ {
try_files $uri =404;
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;
}
}
XXX.XX.XX.XX is my the servers ip.
PS: I have read that I need the bottom section first to get the top section working.
Sources include:
How to remove both .php and .html extensions from url using NGINX?
https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04
Ty for your help.
UPDATES:
Kuldeep KD - 770 /var/www/html (not solution but thanks)
Jignesh Joisar - Trying port 80 (failed but per usual thanks)
Check for necessary permissions on /var/www/html
you can change the permissions using
chmod -R 770 /var/www/html/
also check for the owner of directory you may have to change that as well, depends on user your nginx is using.
chown -R user:group /var/www/html
try to this one in 80 port
server {
listen 80 default_server;
root /var/www/html/;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm;
server_name localhost;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php$is_args$args;
}
# pass PHP scripts to FastCGI server
#
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;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}

Whats the correct way to write nginx configuration for wordpress?

I have a problem with configuring my wordpress nginx settings.
This is my nginx configuraton
server {
listen 80;
server_name wordpress.project;
access_log /var/log/nginx/wordpress.project/access.log;
error_log /var/log/nginx/wordpress.project/error.log;
root /var/www/wordpress.project;
location / {
index app_dev.php;
if (-f $request_filename) {
break;
}
rewrite ^(.*)$ /app_dev.php last;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
Hosts file is set as 127.0.0.1 wordpress.project
Permissions of folders are set
sudo chmod -R a+rw /var/www/wordpress.project
sudo chown -R www-data:www-data /var/www/wordpress.project
And symbolic link is set
sudo ln -s /etc/nginx/sites-available/wordpess.project /etc/nginx/sites-enabled/wordpess.project
And there is still an error when i try accessing wordpress.project saying
File not found
Project has classic wordpress structure of files
Is this correct configuration for wordpress in nginx and if its not what is the best way?
Try this
server
{
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/wordpress.project;
index index.php index.html index.htm;
server_name your_domain.com;
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
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/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Please restart Nginx after changing the configuration (sudo service nginx restart)

phpMyAdmin 404 error on Digital Ocean hosting

I'm getting a 404 error after install phpMyAdmin using Digital Ocean's guide. I have multiple domains setup on Ubuntu running nginx. There is a phpmyadmin directory within /var/www/. The only difference from the guide was the following command:
sudo ln -s /usr/share/phpmyadmin/ /var/www
Do I need to add server block possibly? Since I have multiple domains, each of them has a separate configuration file.
Sample config file:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/domain1.com/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name MY_IP_ADDRESS;
location / {
try_files $uri $uri/ =404;
}
location /phpmyadmin {
root /var/www/;
index index.php index.html;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
try_files $uri /index.php;
}
location ~ /\.ht {
deny all;
}
}
I'm not great at server administration. Any suggestions?
Define this server block it worked for me.
A basic configuration for phpmyadmin in you case.As you have created a symbolic link in /var/www.
sudo ln -s /usr/share/phpmyadmin/ /var/www
server {
listen 80;
server_name website.in www.website.in;
autoindex on;
location /phpmyadmin {
root /var/www/;
index index.php index.html;
location ~ \.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;
try_files $uri $uri/ /index.php;
}
}
location / {
root /var/www/your/path;
index index.php index.html;
location ~ \.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;
try_files $uri $uri/ /index.php;
}
}
}

Laravel5 and PhpMyadmin on Digital Ocean LEMP stack

I tried to install phpMyadmin on my LEMP server using following tutorial
https://www.digitalocean.com/community/tutorials/how-to-install-phpmyadmin-on-a-lemp-server
but when I try to access myip/phpmyadmin I get page cannot be found
before this I installed laravel5 so anything i am typing after ip/anystring its being accessed by my laravel route page ,
So can you tell me how I can access the phpMyadmin
my ip is http://xxxxxxxx//phpmyadmin .
and my default page for nginx looks like this
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/laravel/public;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name xxxxxxx;
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$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Please hlp me out
Thanks
I am also stuck in the same kind of situation. Paste this code before location ~ .php$ function and it's work perfectly fine.
Source : Laravel routes overwriting phpmyadmin path with nginx
location /phpmyadmin {
root /usr/share/nginx/html;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/nginx/html;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/nginx/html;
}
}

nginx: [emerg] unknown directive " " in example.com: 3

I have followed this website http://raspberrypihelp.net/tutorials/24-raspberry-pi-webserver to setup the HTTP server nginx on my Raspberry Pi and try to setup a site call example.com. But when I run sudo service nginx restart, it said
Restarting nginx: nginx: [emerg] unknown directive " " in /etc/nginx/sites-enabled/example.com:3
Here is the code in example.com.
server {
server_name example.com 192.168.1.88;
access_log /srv/www/example.com/logs/access.log;
error_log /srv/www/example.com/logs/error.log;
root /srv/www/example.com/public/;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/example.com/public$fastcgi_script_name;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
}
I've used /usr/sbin/nginx -t -v to checked that I 'm using nginx/1.2.1. I can go to http:/127.0.0.1 see the default site (/usr/share/nginx/www/index.html) that means it can run the file /etc/nginx/sites-enabled/default. I am just following the steps but it can't run successfully.
Try to add this line:
server {
listen 192.168.1.88:80; // Add this "listen" with port 80
server_name example.com www.example.com;
# Rest of code
}

Resources