apache on windows virtual directory config help - windows

I'm running Apache on Windows XP via Xampplite, and could use help configuring my virtual directory. Here's what I'm hoping to do on my dev box:
I want my source files to live outside of the xampp htdocs dir
on my local machine I can access the project at http://myproject
others on my local network can access the project at my.ip.address/myproject
keep localhost pointing to the xampp's htdocs folder so I can easily add other projects.
I've got 1 & 2 working by editing the windows hosts file, and adding a virtual directory in xampp's apache\conf\extra\httpd-vhosts.conf file. I don't immediately see how to do 3 without messing up 4.

Figured it out: use Alias for #3, instead of VirtualHost, thus:
Alias /myproject "C:/path/to/my/project"
<Directory "C:/path/to/my/project">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>

To accomplish your list of needs.
1) Make the directory:
mkdir c:\xampp\sites\myproject
2) Edit c:\windows\system32\drivers\etc\hosts so it contains this line:
127.0.0.1 myproject
and add the following to c:\xampp\apache\conf\extra\httpd-vhosts.conf:
NameVirtualHost myproject:80
<VirtualHost myproject:80>
DocumentRoot c:/xampp/sites/myproject
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
3) Add the following lines to the end of c:\xampp\apache\conf\httpd.conf:
Alias /myproject/ "/xampp/sites/myproject/"
<Directory "/xampp/sites/myproject">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
4) Leave DocumentRoot, Directory, etc in c:\xampp\apache\conf\httpd.conf alone to accomplish this. For reference these lines would be:
DocumentRoot "/xampp/htdocs"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>

First enable: LoadModule alias_module modules/mod_alias.so
<IfModule alias_module>
Alias /ddd "D:/prj/customer/www"
<Directory "D:/prj/customer/www">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</IfModule>
Tested on WAMP 2.2 and its working: http:// localhost/ddd

In httpd.conf add the following lines, mutatis mutandis:
<IfModule alias_module>
Alias /angular-phonecat "C:/DEV/git-workspace/angular-phonecat"
</IfModule>
<Directory "C:/DEV/git-workspace/angular-phonecat">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
This worked great on my (Windows) XAMPP installation after restarting the Apache server. I had to add the "Require all granted", but otherwise it is pretty much the same as the above answers.

NameVirtualHost myproject:80
< VirtualHost myproject:80 >
< /Directory >
Must be:
NameVirtualHost myproject:80
< VirtualHost myproject:80 >
< /VirtualHost >
greets ;)

resolved the issue. it was missing the directory tag.
NameVirtualHost myproject:80
<VirtualHost myproject:80>
DocumentRoot "D:/Solution"
<Directory "D:/Solution">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Problem resolved in a simplest way and less steps
No Need of creating virtual host just change the location of target directory.
Here's what i have done for configuration:
I've done it by editing the C:/xampp/apache/conf/httpd.conf file
Changings that I have done in httpd.conf file
Added this script right after
ScriptAlias /cgi-bin/ "C:/xampp/apache)/"
Alias /projectXYZ "C:/pathtomyproject"
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Pathtomyproject = Complete path of project
And changed the url of Document Root
DocumentRoot " C:/pathtomyproject "
Now restart the Apache Server by stopping the server.
I have stopped Apache server, and then again started the Apache Server.
Source: http://bytespedia.blogspot.com/2013/12/creating-virtual-directory-in-apache.html

Related

URL not found on server when uploading Laravel project

I have a Laravel project that is on a live server and I have made a copy to place in a development server. When I try to login, it says The requested URL /xxxx/login was not found on this server..
I am not quite sure what to do, as I changed my httpd.conf to
<Directory "/var/www">
AllowOverride All
Require all granted
</Directory>
and
<Directory "/var/www/html">
AllowOverride All
Require all granted
</Directory>
but I am still getting the same error after restarting apache. Is there any way to solve this?
I think you didn't config for the virtual host or you config it wrong.
You can find that config file under folder /etc/httpd/conf.d/vhosts/ Below are a sample file config:
$ cat /etc/httpd/conf.d/vhosts/yoursife.conf
<VirtualHost *:80>
ServerName yourdomain.com
ServerAdmin youradmin_server_mail
DocumentRoot /your_src_path/public/
<Directory "/your_src_path/public/" >
Options FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /your_src_path/public/logs/error_log
CustomLog /your_src_path/public/logs/access_log combined
</VirtualHost>
You can create a new file if you want.

deploy multiple laravel projects in apache virtual hosts

I have two laravel projects, I deploy on VPS, then I configure the apache virtual host for each project in my /etc/apache2/sites-available.
example:
project1.conf:
Listen 8999
NameVirtualHost *:8999
<VirtualHost *:8999>
ServerName project1.test
ServerAlias www.project1.test
DocumentRoot "C:/laragon/www/data/project1/public"
DirectoryIndex index.php
<Directory "C:/laragon/www/data/project1/public/">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
project2.conf
Listen 8998
NameVirtualHost *:8998
<VirtualHost *:8998>
ServerName project2.test
ServerAlias www.project2.test
DocumentRoot "C:/laragon/www/data/project2/public"
DirectoryIndex index.php
<Directory "C:/laragon/www/data/project2/public/">
#Options Indexes FollowSymLinks MultiViews
AllowOverride All
#Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
in my /windows/system32/drivers/etc/host, I have already made a host for each project.
but I have a problem, which is when I open the first project in the browser and log in, then at the same time I open the second project and login too, when the first project is refreshed, it returns to the login page. Why did it happen ?
Instead of doing it the hard way, you can try to use Laravel Valet, which allows you to link your site to a domain like localhost.test and localhost2.test. It takes care of all virtual host configuration.

How to serve different web apps using one domain name in Apache?

I'm currently trying to deploy my Django 2.0 App on an Apache Web Server. However I'm experiencing difficulties in configuring it because my Virtual Host configuration overrides other Virtual Hosts which is used by other projects (Ruby and PHP WebApps). We only have one domain name at the moment so I cannot use other domain names to host my app.
Is it possible to serve different kind of apps with one domain name using Apache Virtual Hosts?
Since you can only have 1 VirtualHost (one domain, one port, one IP), you cannot create additionnal VH. You need to "split" the paths to the different applications some other way.
Let assume www.example.com:
ServerRoot "/some/path/apache"
[...] OTHER LoadModule directives [...]
LoadModule alias_module modules/mod_alias.so
Listen *:80
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
# Logs
LogLevel warn
CustomLog "logs/www.example.com_access-log" combined
ErrorLog "logs/www.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This VirtualHost is a basic configuration for the www.example.com domain. Now you want to have Ruby, PHP WebApps and Django 2.0 App under that single domain. You have 3 choices:
Get 1 domain per application, not applicable here, that is your question.
Make a sub-directory in htdocs, and a path in the URI for each application.
Put each application in some directory, not under DocumentRoot and use Alias.
Use sub-domains.
Not applicable.
Sub-directory and path
Create /some/path/apache/htdocs/Ruby, put your Ruby app. here.
Will be accessed via http://www.example.com/Ruby
Create /some/path/apache/htdocs/PHPWebApps, put your PHP app. here.
Will be accessed via http://www.example.com/PHPWebApps
Create /some/path/apache/htdocs/Django, put your Django app. here.
Will be accessed via http://www.example.com/Django
The URI value must match the directory value.
In some directory, use Alias
If you do not need, or want the URI to match the directory name (like in 2.), use Alias.
Create /SOME_DIR_FOR_Ruby, put your Ruby app. here.
Add Alias "/Ruby" "/SOME-DIR-FOR-Ruby"
Will be accessed via http://www.example.com/Ruby
Create /SOME_DIR_FOR_PHPWebApps, put your PHP app. here.
Add Alias "/PHPWebApps" "/SOME_DIR_FOR_PHPWebApps"
Will be accessed via http://www.example.com/PHPWebApps
Create /SOME_DIR_FOR_Django, put your Django app. here.
Add Alias "/Django" "/SOME_DIR_FOR_Django"
Will be accessed via http://www.example.com/Django
Use sub-domains
This is where you could use multiple VirtualHosts. But you have to be able to create sub-domains. This is done either via a DNS configuration, or through your hosting provider.
You could setup http://ruby.example.com, http://php.example.com, http://django.example.com. Each of these will have 1 VirtualHost, but will all be mapped to the same IP in the DNS.
Then setup 3 VH:
<VirtualHost *:80>
ServerName ruby.example.com
# Logs
LogLevel warn
CustomLog "logs/ruby.example.com_access-log" combined
ErrorLog "logs/ruby.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/Ruby"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/Ruby">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName php.example.com
# Logs
LogLevel warn
CustomLog "logs/php.example.com_access-log" combined
ErrorLog "logs/php.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/php"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/php">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName django.example.com
# Logs
LogLevel warn
CustomLog "logs/django.example.com_access-log" combined
ErrorLog "logs/django.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/django"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/django">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
On Apache 2.2, you have to add NameVirtualHost *:80, in Apache 2.4, nothing, it is always "on".
All these values can be changed as you like, this is just an example to explain the concept.

.htaccess <VirtualHost not allowed Mac

I am trying to setup crud app using http://crud-admin-generator.com/ on my Mac
So I followed the steps on the above link to get all the entities generated.
While running the server I needed to setup the .htaccess file on my mac throws the following error when I run localhost on my mac machine.
/.htaccess: <VirtualHost not allowed here
My configurations are as follows
/etc/apache2/httpd.conf
DocumentRoot "/Users/akshat/Sites"
<Directory "/Users/akshat/Sites">
/etc/apache2/users/akshat.conf
<Directory "/Users/akshat/Sites/">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And /Users/akshat/Sites/.htaccess
<VirtualHost *:80>
DocumentRoot /Users/akshat/Sites/admingenerator/web
DirectoryIndex index.php
<Directory "/Users/akshat/Sites/admingenerator/web">
Options Indexes FollowSymLinks
Order Allow,Deny
Allow from all
AllowOverride all
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode off
php_admin_value open_basedir none
</ifModule>
</Directory>
</VirtualHost>

How to run apache webpage from multiple directories in the home folder?

Web Directory Structure
~/Sites/
./subdomain1.site.com/
./cgi-bin/
./subdomain2.site.com/
./cgi-bin/
~/Remote/
./subdomain1.remote.com/
./cgi-bin/
./subdomain2.remote.com/
./cgi-bin/
/private/etc/apache2/users/< username >.httpd:
<Directory ~ "/Users/<username>/Remote/.*">
Options Indexes Includes SymLinksIfOwnerMatch MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory ~ "/Users/<username>/Remote/.*/cgi-bin">
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
## Same thing as above, but using "Sites" instead of "Remote"
<Directory ~ "/Users/<username>/Sites/.*">
Options Indexes Includes SymLinksIfOwnerMatch MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory ~ "/Users/<username>/Sites/.*/cgi-bin">
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
I copied Sites into Remote and restarted apache (sudo apachectl restart) -- also, tried stopping, then starting to be thorough.
Directories contain the same permissions
index.html loads for the Sites directory, but not Remote, despite being the same file
URL looks like: http://localhost/~<username>/<directory in Sites or Remote>/index.html
There's nothing in httpd.conf that enables /apache2/users/<username>.httpd config, it just seems to work for Sites/, but not Remote/
In OSX-Mavericks, httpd.conf includes /extra/httpd-userdir.conf by default. This is where the "Sites" directory is being set.
Inside your setup, edit https-userdir.conf and add the line UserDir Remote. This should enable both directories in your home folder.

Resources