How to allow phpmyadmin accessible from only ip address? - php

I have a VPS server from digitalocean. It is running on ubuntu 13.10 64 bit o with apache 2.4, PHP 5 and mysql 5.5
I've installed phpmyadmin. I want to access it through only ip address. I mean 12.34.56.789/pma
but the thing is that I've set up two virtual hosts domain and www.domain so if I go to domain/pma and www.domain/pma it allows me to access phpmyadmin which I don't want to allow. So any suggestion friends? Here is my /etc/phpmyadmin/apache.conf file's codes.
# phpMyAdmin default Apache configuration
Alias /pma /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride All
So how to allow access to phpmyadmin from only ip address?

Create a default Virtual Host directive. You can follow this link : setting a default apache virtual host
Put your alias /pma into the default virtual host. It might look like:
<VirtualHost *:80>
DocumentRoot /var/www
<Directory /var/www >
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Alias /pma /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride All
</Directory>
</VirtualHost>

Related

config apache2 for phpmyadmin behind HAproxy

I'm looking looking for solving my problem, but still I cannot solve it...
I have a firewall (pfsense) in a cloud VM on which I have a reverse proxy (HAproxy) for balancing and offload https on 2 backend servers.
These 2 servers are classic LAMP (Ubuntu Apache2 2.4.53, PHP 7.4, MySQL)
I 'm using phpmyadmin on a different port (let's say 1234), and I'm using the same domain (example.com) on the reverse proxy which balance to lamp1 or lamp2 depend which address :
example.com:1234/phpmyadmin1 => LAMP1
example.com:1234/phpmyadmin2 => LAMP2
All of that works nice, but as I'm still learning, I made mistakes that I realized after few months. I could use php-fpm instead php-mod, I would like to use php8.1 and php7.4 and big mistake my Ubuntu version was 21.04 (yes I stupidly mistake with the LTS...)
So for doing all of that, I finally decide to start a fresh install on a new VM : LAMP3
I have my new LAMP3 with phpmyadmin, I followed DigitalOcean tuto for PHP-FPM, tested with simple web page, I can switch to php8.1 or php7.4. Everything sounds good.
Now I would like to integrate the LAMP3 in the reverse proxy in order to redirect example.com:1234/phpmyadmin3 to my phpmyadmin
When I'm on the VPN I can try http://10.0.0.3:1234/phpmyadmin3 and it works.
But when I try from internet with https://example.com:1234/phpmyadmin3 , I have on error 404 Not Found .
This error 404 mean I'm on the server and not on the reverse proxy. so I'm redirected to the right place.
I changed the config for using original alias (/phpmyadmin) and update it on the reverse proxy. Guess what, it's working ! And I'm sure it's LAMP3 because I have php8.1 for phpmyadmin (that I don't on the 2 others LAMP)
I tried with include the default phpmyamin in the virtualhost, but I prefer having all in 1 place so I made a virtualhost phpmyadmin.conf with all info (see below)
I disable phpmyadmin in apache conf (a2disconf phpmyadmin)
I tried a lot of different things into this virtualhost that now I'm getting lost
I reapeat again, but when I change the alias from /phpmyadmin3 to /phpmyadmin everything works as it should.
So why, where how to solve that ?
What's wrong with my alias ?
phpmyadmin.conf
<VirtualHost *:17380>
ServerName localhost
Alias /phpmyadmin3 /usr/share/phpmyadmin
DocumentRoot /usr/share/phpmyadmin
DirectoryIndex index.php
<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
<Directory /usr/share/phpmyadmin/templates>
Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/libraries>
Require all denied
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/phpmyadmin.error.log
CustomLog ${APACHE_LOG_DIR}/phpmyadmin.access.log combined
</VirtualHost>
VirtualHost *:17380>
ServerName example.com
Alias /phpmyadmin3 /usr/share/phpmyadmin
DocumentRoot /usr/share/phpmyadmin
DirectoryIndex index.php
<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
<Directory /usr/share/phpmyadmin/templates>
Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/libraries>
Require all denied
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/phpmyadmin.error.log
CustomLog ${APACHE_LOG_DIR}/phpmyadmin.access.log combined
</VirtualHost>
Versions
Ubuntu 22.04
apache 2.4.53
mysql 5.7.38
php-fpm7.4
php-fpm8.1
I kind if solve my problem...
Instead of using the alias /phpmyadmin3 , I tried with alias /pma3 and /test
And it works !
Soooo... I guess it's something with cache on my server ?
Not with my browser as I tried from different PC with different browser in private mode.
Solve I guess

Symfony Vhost is not working?

I am using XAMPP in Windows.I want to set vhost for my symfony project so I have set the vhost in apache through (httpd-vhosts.conf) file as :
# Be sure to only have this line once in your configuration
NameVirtualHost 127.0.0.1:80
# This is the configuration for drberg.com
Listen 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
ServerName drberg.com.local
DocumentRoot "D:/xampp/htdocs/DrBerg.com/web"
DirectoryIndex index.php
<Directory "D:/xampp/htdocs/DrBerg.com/web">
AllowOverride All
Allow from All
</Directory>
Alias /sf "D:/xampp/htdocs/DrBerg.com/web/sf"
<Directory "D:/xampp/htdocs/DrBerg.com/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
So I can't access it it's not opening anything also when I access my symfony project through manual link so it redirects me to my localhost as :
http://localhost/DrBerg.com/web/
So it redirects me to :
http://localhost/xampp/
Set in your hosts (in WINDOWS/system32/drivers/etc/) your ServerName:
127.0.0.1 drberg.com.local
(it works immediately after save this file)
and point to:
http://drberg.com.local
(use http:// because sometimes chrome send the address to google.com instead go there)
and don't use localhost in the ServerName because XAMPP filter this word (local can be).

Virtual Host: LAN access, WAMP, Windows 7, Apache 2.4.4, Php 5.4.16; returns dont-have-permission-to-access-on-this-server

Before I start.. Good day to all! :)
I have problem with my WAMP virtual host.. the other computer on our LAN keeps receiving error forbidden-you-dont-have-permission-to-access-on-this-server..
Below is the current settings I have:
/httpd.conf
#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
Options FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "c:/wamp/www"
<Directory "c:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Order Deny,Allow
Allow from all
Allow from 127.0.0.1
Allow from ::1
Allow from localhost
</Directory>
/phpmyadmin.conf
Alias /phpmyadmin "c:/wamp/apps/phpmyadmin4.0.4/"
# to give access to phpmyadmin from outside
# replace the lines
#
# Order Deny,Allow
# Deny from all
# Allow from 127.0.0.1
#
# by
#
# Order Allow,Deny
# Allow from all
#
<Directory "c:/wamp/apps/phpmyadmin4.0.4/">
Options Indexes FollowSymLinks ExecCGI
AllowOverride all
Order Deny,Allow
Allow from all
Allow from 127.0.0.1
Allow from ::1
Allow from localhost
</Directory>
/httpd.vhosts.conf
Listen 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
ServerName www.ecommerce.local
ServerAlias ecommerce.local
DocumentRoot C:/wamp/www/ecommerce
ErrorLog "C:/wamp/www/ecommerce/logs/error.log"
CustomLog "C:/wamp/www/ecommerce/logs/access.log" common
<Directory />
Require all granted
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost 127.0.0.1:80>
ServerName localhost
DocumentRoot C:/wamp/www/
</VirtualHost>
Also...
tried to ping from other computer response is success
tried to turn off firewall for both computer
tried to add everyone in www's folder properties
I have tried other solutions I found but still to no avail.. I can access "http://ecommerce.local" but the other computer on our LAN recieves forbidden-you-dont-have-permission-to-access-on-this-server error..
does it have something to do with our network settings? the other computer is also in the same settings... my ip: 192.168.1.198 and the other computer is 192.168.1.192
Access to Apache has nothing to do with windows access rights on a Windows system. Its all to do with what you tell Apache to allow in.
Also you are using a mixture of Apache 2.2 and Apache 2.4 syntax in most of your access declarations.
Apache 2.2
Allow .....
Apache 2.4
Require .....
Require local - means 127.0.0.1 and localhost and ::1
Require ip - specifies a single ip (192.168.0.10) or a range of ip's (192.168.0)
Apache does not seem to complain yet, but its probably best to stick to the Apache 2.4 syntax.
This first change you made is very dangerous and should be changed to this unless you really wanted to give unlimited access to the servers C:\ drive to anyone that hacks your Apache server.
#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
Options FollowSymLinks Includes
AllowOverride All
Require all denied
</Directory>
Again here use Apache 2.4 syntax and be specific about who you want to allow in.
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "c:/wamp/www"
<Directory "c:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Require local
Require ip 192.168.0
</Directory>
Now to your Virtual Host definitions
You dont need this Listen 127.0.0.1:80
Put the localhost definition first so it becomes the default domain, so if a random or misspelt domain name is used this will load. If that comes from an internet ip then they will get an error as only ip's from within you network are allowed access. This isreally for later when you decide to open up your site to a wider audience.
Also dont specify 127.0.0.1 on the line, you want it to be listen any incoming ip not just this machine.
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/wamp/www"
<Directory "c:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Require local
## May not want to let people access the wamp page so leave this off if not.
Require ip 192.168.0
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName www.ecommerce.local
ServerAlias ecommerce.local
DocumentRoot "C:/wamp/www/ecommerce"
## not a good idea to have logs visible under the DocumentRoot folder
## should really go in C:\wamp\logs
## But I assume you want developers to have easy access during development
## ErrorLog "C:/wamp/logs/ecommerce_error.log"
## CustomLog "C:/wamp/logs/ecommerce_access.log" common
ErrorLog "C:/wamp/www/ecommerce/logs/error.log"
CustomLog "C:/wamp/www/ecommerce/logs/access.log" common
<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require local
Require ip 192.168.0
</Directory>
</VirtualHost>
Now you may want to allow your local developers access to phpMyAdmin. If so you will need to change your C:\wamp\alias\phpmyadmin.conf file as well.
<Directory "c:/wamp/apps/phpmyadmin4.0.4/">
Options Indexes FollowSymLinks ExecCGI
AllowOverride all
Require local
Require ip 192.168.0
</Directory>
Or you could be more specific here and only allow certain ip's to use phpMyAdmin by using something like this
Require ip 192.168.0.10 192.168.0.11 192.168.0.12
Just as a side note. I personally like to move my VistualHosts sites completely out of the C:\wamp\ folder structure. So I would have placed my ecommerce folder somewhere like C:\websites\ecommerce\www\. This keeps any confusion about access rights to a complete minimum and also if I need to upgrade WAMP, my website code is never in any danger when I make a silly typo.
ADDITIONAL INFO:
Now to be able to access your new site as ecommerce.local or www.ecommerce.local you will have to make a chnage to your HOSTS file.
C:\windows\system32\drivers\etc\hosts
On the PC running WAMP add this line:
127.0.0.1 ecommerce.local
On the other PC's do this
192.168.0.10 ecommerce.local
Where 192.168.0.10 is the ip address of the PC running WAMP
Then reboot the PC's or do these 2 commands from a command window started as Administrator
net stop "DNS Client"
net start "DNS Client"
I have already solved my own issue... I have not shared my folder for anyone to view... so what I did is:
Right Click the project folder
On folder options go to sharing tab
Click on advance sharing
advance sharing option will open then tick share this folder
click permissions
permissions option will open then choose whom you would like to share your folder
I chose everyone then below tick full control (*for trial purposes only; recommended tick only Read)
then click ok for all the opened options

Setup VirtualHost for Zend Application on Wamp server

I'm following this tutorial to learn how to start a project using ZendFramework
http://framework.zend.com/manual/1.12/en/learning.quickstart.create-project.html
When I get to setup a virtual host I get stuck. If I do exactly as the tutorial says, it shows me an error (in all my project, zend or not), says the file wasn't found.
Then I found this tutorial on StackOverflow very handy
Can't run zend framework MVC application on WAMP
Following what the guy on the bottom of the page says takes me to the same error when I try to access my app as zendProject.local/
This is what I got
on hosts (Windows/System32/drivers/etc/hosts) file
127.0.0.1 blog.local
on httpd-vhosts.conf file
<VirtualHost 127.0.0.1>
ServerName blog.local
DocumentRoot /blog/public
SetEnv APPLICATION_ENV "development"
<Directory /blog/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Can you tell me what I am doing wrong? The browser still says Not Found The requested URL /public was not found on this server when I go to http://blog.local/
I'm running WAMP on Windows. And this is the absolute path to the 'blog' project C:\wamp\www\blog
#Edit RiggsFolly
this is what I got now in the httpd-vhosts.conf file
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www">
AllowOverride All
# make sure this is only allowed to be accessed by the local machine
# then if/when you open one of your other sites up to the internet and somebody uses your IP
# they will get directed here as its the first VH def and then receive a 403 not allowed to access
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/websites/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/websites/blog/public">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
And I created a new directory at C:/ called 'websites' as you suggested
You need to be a little more specific with your folder locations. I guess this tutorial was written for Unix and you are using windows.
For Apache 2.2.x use this syntax:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/wamp/www/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/wamp/www/blog/public">
DirectoryIndex index.php
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
You would be better avoiding the Allow from all and using Allow from localhost 127.0.0.1 ::1 until you actually want to allow the universe to see your sites.
For Apache 2.4.x use this syntax:
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/wamp/www/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/wamp/www/blog/public">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
Note NameVirtualHost *:80 no longer required for Apache 2.4.x
Again you would be better avoiding the Require all granted and using Require local until you actually want to allow the universe to see your sites.
EDITED After comment from Questioner:
Right, that's the Apache default. If you enter a url it cannot find a Virtual Host definition for it will default to the first Virtual Host definition you gave it, the blog in your case.
Ok, so now you need to create a Virtual Host for each of your other projects, and MOST IMPORTANTLY the first one needs to be localhost and only be allowed to be accessed from the local PC for a bit of extra security.
Now personally I would take this opportunity to move my actual sites to a totally separate folder structure outside the \wamp\ folder structure so there is no confusion with rights given to the \wamp\www folder and my other sites.
So for example, create a folder c:\websites\www and in that folder create a folder for each of your projects eg
c:\websites\www\blog
c:\websites\www\project2
Then point your virtual hosts to the relevant folder containing the site code ( this can be on another disk if you like ). This allows you to specify the Apache security ( who is allowed in to this site) specifically for each of your VHOSTS. So when you want a client or friend to be able to play with one site, you just change the security on that one site while you let them play.
Like this:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www">
AllowOverride All
# make sure this is only allowed to be accessed by the local machine
# then if/when you open one of your other sites up to the internet and somebody uses your IP
# they will get directed here as its the first VH def and then receive a 403 not allowed to access
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/websites/www/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/websites/www/blog/public">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName project2.dev
DocumentRoot "C:/websites/www/project2"
Options Indexes FollowSymLinks
<Directory "C:/websites/www/project2">
DirectoryIndex index.php
AllowOverride All
Require local
# this site also available to other PC's on my internal network
Require ip 192.168.0
</Directory>
</VirtualHost>
Remember, for each new Virtual Host site you create you also need to add that ServerName (project2.dev) to the hosts file.
hosts file:
127.0.0.1 blog.local
127.0.0.1 project2.dev
I hope this helps.

install CakePHP on Mac osx: apache problems

First time cake user and I'm having real apache problems. For some reason the .htaccess is trying to find
File does not exist: /Library/WebServer/Documents/Users
but there is no such directory as Users. I have tried setting up the following also:
/etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80 >
DocumentRoot "/Users/username/Sites/mysite/app/webroot"
ServerName mysite.dev
ServerAlias www.mysite.dev mysite.dev *.mysite.dev
<Directory "/Users/username/Sites/mysite/app/webroot">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
/etc/hosts
127.0.0.1 mysite.dev
/etc/apache2/users/username.conf
<Directory "/Users/username/Sites/">
Options Indexes MultiViews FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
That also hasn't worked, but with a different error Failed opening required 'cake/libs/cache/file.php'
Although I'd rather not use virtual hosts, and just run it off localhost
Seems like the solution that worked for me was to edit /etc/apache2/users/username.conf and add this at the top:
DocumentRoot "/Users/username/Sites"
And the default cakePHP download now runs ok.
Looks like Apache is trying to find your webroot in a different location--the default location, if memory serves. If you want to use virtual hosts (which would be my recommendation, for whatever it's worth), ensure that the NameVirtualHost directive is uncommented. By default, it's commented out:
NameVirtualHost *:80
If you'd prefer not to use virtual hosts for whatever reason, ensure that the NameVirtualHost is commented out (your <VirtualHost> blocks will be ignored) and change the DocumentRoot value to the proper directory:
DocumentRoot "/Users/username/Sites/mysite/app/webroot"
That should tell Apache to look in the right place.

Categories