XAMPP for Mac rewriting issue when using virtual hosts - php

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?

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

VPS ubuntu apache server - web page

I bought a VPS server, where I installed apache, mysql, php and phpmyadmin. I created database (like in my local project).
So, now I want to migrate a local project to my server and please, tell me I am right:
Files .php has to be in folder var/www on my apache server? (here is index.html too) and from this folder connect with database?
I have to download NPM on ubuntu
I have to download GIT on ubuntu
Download repo from my github where I've got whole code (webpack dist files, node modules, src and whole config) to /var/www catalog
index.html has to be in top-level directory (just in var/www not for example var/www/src
Please help me and tell if I am thinking right.
Files .php has to be in folder var/www on my apache server? (here is index.html too) and from this folder connect with database?
It depends on what you set in /etc/apache2/sites-available/000-default.conf. I assume that you installed with default configuration from apt-get.
index.html has to be in top-level directory (just in var/www not for example var/www/src
If for example your source codes are in /var/www/src instead of /var/www, the just modify the 000-default.conf. Example:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName your_domain_name.com
DocumentRoot /var/www/src/
<Directory />
Options FollowSymLinks
AllowOverride None
Options -Indexes
</Directory>
<Directory /var/www/src>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
Options -Indexes
</Directory>
ErrorLog /var/log/your_log_file.log
LogLevel warn
CustomLog /var/log/your_access_log_file.log combined
</VirtualHost>
Restart Apache and try open in your browser to see if it works.
As for the database, since you have phpmyadmin, just export the sql data from your local machine and import it into the VPS phpmyadmin.

MySQL not working with virtualhost

I'm working locally on my Macbook Pro using XAMPP and I'm trying to setup virtualhosts so that I can work on multiple projects more easily.
Everything appears to be working fine except I can't connect to MySQL through PHPMyAdmin and on the XAMPP control panel it says MySQL isn't running. However, I can access MySQL through an application I have in my htdocs folder. When I access phpmyadmin through localhost/phpmyadmin the CSS is loaded and PHPMyAdmin appears to be located, but MySQL can't connect so I'm not quite sure where the issue lies (considering I can connect through my application)
Upon going to localhost/phpmyadmin I get the following error
#2002 - No such file or directory
The server is not responding (or the local server's socket is not correctly configured).
The thing is, I can access the database just fine through the application. I can log in, save and do any other sort of interactions with the database.
Here's what I have in my httpd-vhosts.conf file
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/test1"
ServerName localhost
<Directory /Applications/XAMPP/xamppfiles/htdocs/test1>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName pma
DocumentRoot "/Applications/XAMPP/xamppfiles/phpmyadmin"
<Directory /Applications/XAMPP/xamppfiles/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
<IfModule mod_php5.c>
AddType application/x-httpd-php .php
php_flag magic_quotes_gpc Off
php_flag track_vars On
php_flag register_globals Off
php_value include_path .
</IfModule>
</Directory>
</VirtualHost>
Now for a summary
I set up virtualhosts for apache on my Macbook
The virtualhost setup appears to be working fine for the application I have in my htodcs folder, and it can connect to the database. I can log in, save data and all that stuff.
When I browse to localhost/phpmyadmin I get a MySQL connection error. If I browse to pma/phpmyadmin (the virtualhost I tried to create) Chrome and Firefox just search google for it instead of recognizing the alias (is that the correct term?)
I ran into the same thing with a WAMP server. I solved it by putting back the original "out of the box" server settings:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/Apache2/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
And then for each project used code such as:
<VirtualHost *:80>
ServerAdmin admin#localhost
DocumentRoot "C:/wamp/projectname"
ServerName localhost
ServerAlias projectname.here
<Directory "C:/wamp/projectname">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Order allow,deny
Allow from all # <-- used for Apache 2.2
#Require all granted #<-- used for Apache 2.4+
</Directory>
</VirtualHost>
For different projects, just duplicate the last set of code for each project, renaming the DocumentRoot, ServerAlias and Directory path. You will notice the "ServerAlias" line; this is what made Apache serve up the project when entering the alias in the web browser. I found the explanation here which ironically was in the httpd-vhosts.conf file.
Also, please note that my research recommends for higher versions of Apache to use Require all granted in place of Allow from all as commented in the code above.
All of this code is in the httpd-vhosts.conf file, which on my Windows 7 installation is at c:\wamp\bin\apache\Apache2.2.21\conf\extra directory. Since you are using a Macbook and have already identified the location, I just put this in for other's reference.

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

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.

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