How do fix apache error "not within configured docroot" under Ubuntu - php

Greetings experts and gurus, I am looking for some help with an apache php configuration problem.
I have been running several websites from an apache2 setup on an ubuntu server for some time now without problems using the line NameVirtualHost * in my etc/apache2/conf.d/virtual.conf file. I recently updated the server version to the latest lts version and I am now unable to run php files.
I am running all my sites for the location "/home/www/[site-name]/htdocs" and I have setup and enabled all my sites in /etc/apache2/sites-available. I have also disabled the default site.
for each sites file I have specified the following:
# Indexes + Directory Root.
# DirectoryIndex index.html index.htm index.php
DocumentRoot /home/www/[site-name]/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ /home/www/[site-name]/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
ErrorLog /home/www/[site-name]/logs/error.log
CustomLog /home/www/[site-name]/logs/access.log combined
I restart apache and enter the url for a php test page on my server and I am met with an "Internal Server Error". When I check the error log I get:
Script "/home/www/[site-name]/htdocs/test.php" resolving to "/home/www/[site-name]/htdocs/test.php" not within configured docroot.

For some reason when looking into the error, suphp came up a lot. According to this link:
Don't be fooled into thiking this has anything to do with the Apche virtual host document root, this is actually another setting in the suphp config file. Including the paths which contained the RoundCube scripts fixed this one. For example:
docroot=/var/www:/usr/share/roundcube:/var/lib/roundcube:${HOME}/public_html
You need to edit your /etc/suphp/suphp.conf file and change the docroot to whatever is appropriate.

It looks you missed the virtual hosts configuration for every site name:
<VirtualHost IP:80>
ServerName yourdomainname
ServerAlias www.yourdomainname
DocumentRoot /home/www/[site-name]/htdocs/
ScriptAlias /cgi-bin/ /home/www/[site-name]/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
ErrorLog /home/www/[site-name]/logs/yourdomainname.ua-error.log
CustomLog /home/www/[site-name]/logs/yourdomainname-access.log combined
</VirtualHost>
<Directory "/home/www/[site-name]/htdocs/">
Options FollowSymLinks
AllowOverride None
Order allow,deny
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>

Thanks for all the help, I got there in the end. It seems that upgrading to Ubuntu 10.04 turned on suPHP. It has ended up being a good thing as the reason why I was getting errors was down to file management in my htdocs getting sloppy.
To fix my issues I had to do several things:
First I turned on suphp error messages in /etc/apache2/sites-available/[site-name]. This gave me the true error, which told me that some of my pages had the wrong permissions. I then set all my folder permissions in www to 755 and the files to 644. I also had to lower the min_uid and min_gid fileds in suphp.conf to 33.

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

How to run two versions of PHP for two projects on same apache server

I have 2 different virtual hosts on my apache server. One of them needs php7.x and another need php5.x.
Is it possible to use project-specific PHP versions?
I have tried the following,
Running two PHP versions on the same server
but my apache server crashed saying there's some syntactical error in one of the fpm's config file.
Also I cant follow this solution since It advices to uninstall apache and start over again and I can't do that on a live server.
Is there any way to do this without uninstalling the apache server.
Thank you for your suggestions.
for windows on file httpd-vhosta.conf
<VirtualHost *:80>
DocumentRoot "d:/server/htdocs/"
ServerName localhost
ServerAlias www.localhost
<Directory "d:/server/htdocs/">
Require all granted
<Files ~ "\.php$">
AddHandler fcgid-script .php
#FcgidWrapper "d:/server/php/php-5.6.40-Win32-VC11-x64/php-cgi.exe" .php
FcgidWrapper "d:/server/php/php-7.1.24-Win32-VC14-x64/php-cgi.exe" .php
Options +ExecCGI
</Files>
</Directory>
ErrorLog "D:/server/apache/logs/error-localhost.log"
SetEnv APP_ON_LOCAL 1
</VirtualHost>

XAMPP for Mac rewriting issue when using virtual hosts

I'm not sure what's going on here, I'm far more used to a Windows XAMPP environment, so this is all a bit new to me. Long story short, I'm having some trouble getting a virtual host on XAMPP to correctly show the document root's contents.
I set the httpd.conf in the XAMPP folder to include the extra/httpd-vhosts.conf file, and I set my virtual host as follows:
<VirtualHost 127.0.0.1>
ServerName spacexstats
DocumentRoot "/Volumes/PATRIOT 32/spacexstats”
<Directory "/Volumes/PATRIOT 32/spacexstats”>
Options Indexes FollowSymLinks Includes ExecCGI AddType text/shtml .shtml
AddOutputFilter INCLUDES .shtml
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
From here, I added this to my hosts list in etc/hosts by setting:
127.0.0.1 spacexstats
Upon restarting XAMPP, I attempt to navigate to spacexstats in my browser (have cleared the cache), but instead of being delivered my expected index.php file, I'm redirected to spacexstats/xampp which is essentially the XAMPP splash screen.
Any ideas?

ZEND Internal Server Error (WAMP)

I already install zend framework and i used wamp server to let it works then in httpconfig i inserted
NameVirtualHost 127.0.0.1
DocumentRoot "C:\Workspace\zendy\public"
ServerName zendy
<Directory "C:\Workspace\zendy\public">
Options FollowSymLinks
AllowOverride AuthConfig Limit Indexes
Order allow,deny
Allow from all
</Directory>
after restarting wamp server ... the below message appears
Internal Server Error
i know the error in virtualhost. however, i couldn't solve the problem
You can enable rewrite module directly by clicking wamp tray icon and going into Apache settings. Like example below.
If you still find some problems you may need to add zendy server name to your system C:\Windows\System32\drivers\etc\hosts file:
127.0.0.1 zendy
Also you must uncomment vhosts in Apache httpd.conf:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Hope that helps!
just look into Apache Error Log, you should see what exactly caused Internal Server Error there

Apache alias directive

I am trying to set up simpleSAML.php but I am running into an issue with the Apache Alias directory. I have successfully used Alias so that when the user visits domain.com/auth then it uses the folder /var/saml/www.
However, for some reason it just lists the contents of the folder /var/saml/www rather than running the index.php file.
I have included the relevant virtual host below.
<VirtualHost *:80>
ServerAdmin helpdesk#domain.com
DocumentRoot /var/www/html/open
ServerName open.domain.com
ErrorLog logs/open.domain.com-error_log
CustomLog logs/open.domain.com-access_log common
Alias /auth/ /var/saml/www
Alias /auth /var/saml/www
<Directory /var/saml/www>
Options All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
You can add the following line to your config:
AddType application/x-httpd-php .php
This way apache knows it has to parse the files using php.
P.S. I think you may have to restart Apache rather than a reload.
Update
As Alfabravo commented:
Agree. He also needs to check the DirectoryIndex directive and add index.php to it

Categories