Apache mirroring folder - php

So I have a PHP system over an Apache Server running on a Window SO.
I want to create some kind of a mirror of it to make tests and whatever without have to copy the source code. For example: Actual scenario:
http://192.168.1.1/finantial lies on C:\EasyPHP\www\finantial
I want to create this:
http://192.168.1.1/finantial_test that points to the same source code
that the address above.
When this configs were ok, I can make the app to use different database.

on real server the configuration should be like this
test_financial.conf
<VirtualHost *:80>
DocumentRoot /var/www/financial
ServerName test.financial.com
</VirtualHost>
financial.conf
<VirtualHost *:80>
DocumentRoot /var/www/financial
ServerName financial.com
</VirtualHost>

It's so easy to do that. Just add an Alias to your VirtualHost like...
<VirtualHost *:80>
Alias /finantial_test "C:/EasyPHP/www/finantial"
</VirtualHost>

Related

Why need to create vhost for localhost and for Laravel project itself

Good day to all, I am new to Laravel and I wonder what is the reason to create vhost for localhost like
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
And then create vhost for Laravel project like
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/MyProject/public"
ServerName test.me
</VirtualHost>
Well, it is clear in terms of the creation of vhost for Laravel project but it is unclear why to create for just localhost and is it ok if I remove it(the localhost vhost)
There's no technical requirement for this. Each vhost is in fact separate entity, despite the fact the share some part of DocumentRoot path. You do not need two virtual hosts set up to make things work in your case, nor these vhosts are connected nor depend on each other in any way. The localhost vhost is simply for your (potential) convenience but you can safely get rid of it if you do not find it that useful or needed at all.
So that you don't need to open your project in your browser like this "http://localhost/MyProject/public". It is way simpler just to type: myproject.dev, right? :)
EDIT:
And this:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
Is needed so that your http://localhost is still available.

Laravel - How to share application to another stations

I developed an application with laravel and i put it in a local server and i need that other computer access it.
I think that have 2 solutions:
First: Access to laravel server (port 8000)
Second: Put the project in xampp
What is the best solution?
With the first option i can't access and with xampp it doesn't access well to routes and doesn't load the css and js files.
If i access to root folder it list the project folders and i have to go to public folder but doesn't load stylesheet files.
How can i do that?
UPDATE:
I did this steps and this not work yet.
In httpd.conf enable this line Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Next i add a host in in hosts file:
127.0.0.1 arquivo.localhost
Next i'm going to httpd-vhosts.conf and add this:
<VirtualHost *:8888>
DocumentRoot "/Applications/MAMP/htdocs/arquivo/public"
ServerAdmin arquivo.localhost
<Directory "/Applications/MAMP/htdocs/arquivo/public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Next i restart the apache and when i try to access to http://arquivo.localhost this give me This site can’t be reached
What i'm doing wrong?
Thank you
create virtualhost under xampp/apache/conf/extra/httpd-vhost.conf
like this
<VirtualHost *:80>
ServerAdmin webmaster#localhost.com
DocumentRoot "C:/xampp/htdocs/laravel/public"
ServerName laravel.localhost
ErrorLog "logs/laravel-error.log"
CustomLog "logs/laravel-access.log" common
</VirtualHost>
and access with http://laravel.localhost/
If its working fine on your localhost, other person can access your site using your Ip address, provided you both are on same local network.
For more you can see this reference : Accessing localhost (xampp) from another computer over LAN network - how to?

Apache Virtual Hosts Not Working As Expected

My Apache "httpd-vhosts.conf" looks like this::
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/"
ServerName localhost
ServerAlias *.localhost
</VirtualHost>
<VirtualHost laravel.dev:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias *.laravel.dev
</VirtualHost>
<VirtualHost learninglaravel.dev:80>
DocumentRoot "c:/wamp/www/learningLaravel/public"
ServerName learningLaravel.dev
ServerAlias *.learningLaravel.dev
</VirtualHost>
and my "...system32/drivers/etc/hosts" also looks like this::
127.0.0.1 localhost
127.0.0.1 localhost
// I added the following entries. The first two entries above was already there
127.0.0.1 laravel.dev
127.0.0.1 learninglaravel.dev
When i enter "learningLaravel.dev" and "laravel.dev" into the browser, they work fine as expected. But i have other folders in my "www" folder that i use them to learn PHP and i want to be able to access the files in those folders directly from the browser like say "localhost/test/me.php". But anytime i enter such address the browser goes to the second entry in the vhosts-conf file [which prints a laravel error meaning that it can't find the file]. It seems that the first entry in the vhosts-conf file is not working and Apache bypasses it to the second entry. The first entry is suppose to be the catch all entry. I tried to swap the second and third entries to see how it will behave but it always direct the browser to the second entry instead of the catch all (first entry) that is suppose to handle addresses likes "localhost/test/me.php"
Anytime i enter only "localhost" into the browser, it goes straight to the second entry instead of say printing the contents of the "www" folder.
How do i solve this problem? thanks.
It seems the problem comes from the way you use the VirtualHost directive.
Using a fully qualified domain name for the IP address of the virtual host is not recommended. It is misleading how it works. Name based virtual hosts determine the host through the ServerName directive, and not through the FQDN in the VirtualHost directive (<VirtualHost FQDN:80>). In fact this is seen as <VirtualHost 127.0.0.1:80>
What happens is your case is documented in the VirtualHost doc, last 2 paragraphs (just before "Security"), quoted:
When a request is received, the server first maps it to the best
matching based on the local IP address and port
combination only. Non-wildcards have a higher precedence. If no match
based on IP and port occurs at all, the "main" server configuration is
used.
If multiple virtual hosts contain the best matching IP address and
port, the server selects from these virtual hosts the best match based
on the requested hostname. If no matching name-based virtual host is
found, then the first listed virtual host that matched the IP address
will be used. As a consequence, the first listed virtual host for a
given IP address and port combination is the default virtual host for
that IP and port combination.
So when you ask for localhost/somedir, the server will try to find from the non-wildcards VHosts declarations, but do not find any with corresponding host name (ServerName), and so it chooses as "default" the first VHost with IP:Port, and not the first with *:Port.
To solve your problem, try to use <VirtualHost *:80> in all three vhost declarations :
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/"
ServerName localhost
ServerAlias *.localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias *.laravel.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/learningLaravel/public"
ServerName learningLaravel.dev
ServerAlias *.learningLaravel.dev
</VirtualHost>
And reload / restart Apache.
(My only doubt about this is why Nasreddine could make a working test case with your setup.)

Setting up subdomains for different projects/companies

I would like to have subdomains for my web app like so:
company1.mysite.com
company2.mysite.com
How do I go about doing this? Do I need a virtual host set up per company?
Or can I have a catchall like:
*.mysite.com
What's the typical approach here?
My thoughts on how to show the correct content is that I will take the prefix part of the URL, check the database for the id of that company, and then just use the id to bring back the correct content...
The problem is that i'm unsure of how to create subdomains programmatically in PHP and Apache.
I am using Windows (so locally I will be editing the windows host file)
First You've to define wildcard rule in your dns server.
For example in bind (linux and etc.) I do like this:
somedomain.com. IN A 111.222.222.222
*.somedomain. IN A 111.222.222.222
and then in virtualhost file add this:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName somedomain.com
ServerAlias *.somedomain.com
DocumentRoot /var/www/public
</VirtualHost>
this example for one big single application that get subdomain and works with it's logic.
so if every app is separate then:
<VirtualHost *:80>
ServerName somedomain.com
ServerAlias *.somedomain.com
VirtualDocumentRoot /var/www/%1/public
</VirtualHost>

change the VirtualHost file with php

I have installed apache on Debian server, and setup some example sites but I would like to make a billing system and automatically update the Virtualhost details like ServerAdmin, ServerName, ServerAlias when order is completed.
My question is: Is it possible to update them with PHP?
Example site in the sites-available directory:
<VirtualHost *:80>
ServerAdmin info#example.org
ServerName example.org
ServerAlias www.example.org
DocumentRoot /srv/www/example.org/public_html/
ErrorLog /srv/www/example.org/logs/error.log
CustomLog /srv/www/example.org/logs/access.log combined
</VirtualHost>
With the proper write permissions, you can certainly do it. It does seem like you will want some seriously paranoid validation and testing before you restart apache after a write a new one because a malformed directive in there is a quick way to 500.
Edit: I'm not sure I would recommend giving your script the 'proper' write permissions in the first place.

Categories