change the VirtualHost file with php - 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.

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?

Centos Apache server doesnt seem to redirect

I am trying to set up my apache server. So far I have the following apache config:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot /var/www/system_learningbank/
ServerName www.learningbypower.dk
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
(You can try it out by going to www.learnbypower.dk)
The login screen works fine. However, when I log in it seems as if it's redirecting to another folder where my old system was.
Can anyone tell me what I can do to stop this from happening?
This is an error in your application configuration. The application is failing. Check the logs. Likely its caused by a syntax error or, maybe missing libraries like GD, etc.
Look at the log file:
logs/dummy-host.example.com-error_log

Apache mirroring folder

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>

Wamp vhost docroot always shows as c:\wamp\www not the vhost docroot

I have tried dozens of guides and read ton of information but I still can't find a fix for my problem. I have uninstalled, reinstalled and checked and double checked every possible issue.
The problem remains. No matter what change I make, document root ALWAYS show up as c:\wamp\www.
Even if I change the httpd.conf DocumentRoot to another path it still shows up as c:\wamp\www
What is strange is if the vhost was set up wrong, my index.php should not display. But in fact it does. And I have a line of code to echo the $_SERVER['DOCUMENT_ROOT'] and it ALWAYS shows as c:\wamp\www and not to ANY of the vhosts document roots I have assigned.
So the pages load, of course with errors. My pages ALL reference $_SERVER['DOCUMENT_ROOT'] and ALL work perfectly on my live sites.
So the bottom line is I have checked my configs backwards and forwards. / vs. \, hosts file is correct, document root paths are correct and point to actual folders that contain the correct files. I have played with every "standard" and non-standard possibility of config.
There must be some other element that's keeping this from working. Please help if you can.
Please don't suggest I try another config. I have tried them all.
Please tell me you know why this is happening and how to fix it. I have on script that almost did the trick but feel just short of the fix. I left a message for the poster and have not heard back from him.
I hope somebody here has a fix and not a suggestion to try yet another config. Unless you KNOW of the issue and have a fix, please don't reply. That might sound rude, but I have seen and tried all the configs.
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
DocumentRoot C:\wamp\www\itsaboutwirelessnetworks
ServerName itsaboutwirelessnetworks.localhost
ServerAlias itsaboutwirelessnetworks
</VirtualHost>
<VirtualHost 127.0.0.1:80>
DocumentRoot C:\wamp\www\computerstore
ServerName computerstore.localhost
ServerAlias computerstore
</VirtualHost>
<VirtualHost 127.0.0.1:80>
DocumentRoot C:\wamp\www
ServerName localhost
ServerAlias localhost
</VirtualHost>
Is the config. Why can't I edit with carriage returns in comments?
in C:\Windows\System32\drivers\etc\hosts add this line:
127.0.0.1 computerstore.local
in httpd.conf, make sure this line is uncommented:
Include "conf/extra/httpd-vhosts.conf"
(this should point to where your vhosts file is)
your httpd-vhosts.conf file should contain this:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot C:\wamp\www
ServerName 127.0.0.1
ServerAlias localhost
SetEnv APPLICATION_ENV development
SetEnv APPLICATION_DOMAIN localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:\wamp\www\conputerstore
ServerName computerstore.local
ServerAlias computerstore.local
SetEnv APPLICATION_ENV development
SetEnv APPLICATION_DOMAIN computerstore.local
</VirtualHost>
If WAMP refuses to load up the vhosts file, move the vhosts config to the end of httpd.conf instead.
This should enable name-based configuration instead of IP-based. If you don't set it this way, Apache will resolve your sites' paths by IP, and since you specify a single IP, identical to all virtual hosts, the last one will take precedence over the previous ones. Your last vhost's docroot is C:\wamp\www - making the behaviour you describe absolutely normal.
UPDATE:
Since the document root C:\wamp\www\computerstore is specified for the domain name computerstore.local, remember to also go to http://computerstore.local in your browser. If you try http://localhost/computerstore, the domain name will be resolved as localhost, and in the first vhost, its document root is set to C:\wamp\www. computerstore will be treated just as a subdirectory; the docroot will not be changed in this case.
Did you try placing C:\wamp\www\conputerstore between quotes?
As an example here is my vhost config:
<VirtualHost *:8082>
DocumentRoot "c:/wamp/www/test"
DirectoryIndex index.php
<Directory "c:/wamp/www/test">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>

Categories