Rewrite with multiple symfony projects under same directory - apache

I'm trying to make some personal projects in my development server, like some sort of intranet.
If I divide each project in a different virtualhost, I set in each computer the host file to each server name and I don't have problems with the rewrite rule and the app.php. But the problem is that I can't modify the host file in an android device so I can't access those webs.
What I have in mind is something like this:
I have three symfony projects under my home folder
/home/user/projects/project1
/home/user/projects/project2
/home/user/projects/project3
Then, under the default folder of apache I make soft links to the web folder to every project:
ln -s /home/user/projects/project1/web /var/www/html/project1
ln -s /home/user/projects/project2/web /var/www/html/project2
ln -s /home/user/projects/project3/web /var/www/html/project3
So I can access them this way:
http://server-ip/project1
http://server-ip/project2
http://server-ip/project3
The problem is that I use those url I need to add the default app.php. I've been trying to modify the .htaccess file of each project, but I don't what to modify. I'm using the default virtualhost configuration and the default .htaccess file of each project.
I think that I need to modify the RewriteCond line, but I don't know what to do.
Thanks

I've got a local development environment (it's actually running on a linux server, under my desk, but the same setup would apply to any other configuration of server).
The webserver has a local IP address, reachable from elsewhere on the local network, including from my phone over WiFi.
All the development sites have their own Vhost configured on the server, with a common DNS prefix - something like *.devserver.domain.com.
The DNS is configured so that devserver.domain.com and the wildcard *.devserver.domain.com return 192.168.1.75 (or whatever the internal, static IP address is). This is a public domain name that has an A record to a local-range IP address, but it's entirely valid.
If you don't have a domain name that you can add wildcard DNSs to, you can use a service such as http://nip.io/ - and so the vhost Servername would be something like:
project1.192.168.1.75.nip.io
project2.192.168.1.75.nip.io
... etc
You may end up regularly editing the apache vhost if you internal IP changes at all, and maybe finding alternate wildcard DNS servers (my go-to was xip.io, but that isn't diffcult to do).
You may also be able to use an internal wildcard for an Apache ServerName/serverAlias: ServerAlias mysite.*.xip.io.

Related

Multiple Apache Virtual Host Files with one Document root?

I've set up a single VPS running Apache, with an application installed in /var/www/html/. I have a domain [example-1.com] to the server IP.
I'd also like the same application to be served on [example-2.com]. Something similar to creating an 'Alias' domain.
Is it possible to have two Virtual Host Files configured at one document root?
Yes, no problem. The document roots can point wherever you want them to. If the configuration of the second virtualhost is the same, you could also use the ServerAlias directive.

Change virtual host directory based on IP address

Is it possible in Apache to change the Directory parameter based on the users IP address (i.e. in htaccess)? The logic is that if I'm building a test site it would be great to see it in a test mode for my IP but keep it live and unaffected for public users. That way effectively one domain can appear differently without changing the site root path. Thanks.
You will need 2 virtual hosts, that way you can set a different document root and path for the hostnames. You can restrict acces to your test environment using htpasswd, or put your ip adres in your test virtualhost on the allowfrom list and deny acces to everyone else.
This way you can create urls like test.domain.com and domain.com resolving to the correct environment.

Host multiple domains with apache

I'm trying to set up an ubuntu server to act as a dns server and host a simple webpage, some git repos, and some software for issue tracking, code review, and the like. I settled on Phabricator as the issue tracking/ code review software of choice, since it seemed to be a good all-in-one solution. I've got my server hosting my webpage and git repos, so that part seems to be working ok. Now here's the issue I've run into (from Phabricator configuration instructions):
If you haven't already, set up a domain name to point to the host you're installing on. You can either install Phabricator on a subdomain (like phabricator.example.com) or an entire domain, but you can not install it in some subdirectory of an existing website
I have no idea where to even begin setting up another domain name on my server. How do I set up a second domain name for Phabricator to use?
I see a lot of guides online that say to modify resolv.conf to add a dns entry, however mine looks like this:
Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.1.1
and I'm not sure what I should change to get dns entries to show up here.
I'm assuming you have only one IP address, which means you should be using virtual name-based hosting. There are a number of tutorials for doing this, but in short:
Create a virtual host configuration file in:
/etc/apache2/sites-available
For example:
nano /etc/apache2/sites-available/phabricator
Run:
a2ensite phabricator (in this example, but use the configuration file name you used above)
apache2ctl restart
The configuration file (which can be named whatever you'd like) needs to contain a number of items. A simple example would look like this:
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example.com
</VirtualHost>
DocumentRoot is the full path to the root of your site, usually where index.html, index.php, or the like is located. The default is /var/www. You could put somethig like /home/phabricator or /var/www/phabricator, but make sure you install Phabricator in the directory you specify.
ServerName is the full FQDN of your site, such as "www.google.com" or "phabricator.yourdomain.com" or even "phabricator.local". Basically it's the same value as you have set in your DNS for your A record, or in your /etc/hosts file. If you don't know about /etc/hosts, then disregard that part.
You'll probably need a few more directives in your configuration file, but you can find what's available on Google. I would suggest following some tutorials to get your configuraiton right.
But overall, you just need to create a virtual host config file, enable it, then restart the server, which is what the above instructions do. Apache will respond to the web request based on the site you put into your address bar.
P.S. Just noticed your DNS part of the question. Do you have DNS set up publicly to point a domain (example.com) or subdomain (something.example.com) to your server's IP address?

Apache2 virtualhost configuration trouble

This is my situation:
I have Redmine and Gitlab in my server which does not have a domain associated, because I will use the server IP address.
I want to configure two virtualhosts in apache2 with SSL in order to serve the above web applications, so I can access them like this:
https://x.y.z/redmine
which is located in /var/www/
https://x.y.z/gitlab
located in /home/git/github/public
I have configured apache by enabling two files in site-enabled: github.vhost and gitlab.vhost. The problem is that I cannot set gitlab to be accessible with
https://x.y.z/github
but only in
https://x.y.z
probably beacuse I do not use a domain but only the IP address of the server, and I don't know exactly how to manage it.
I would need some suggestion on how to correctly set the two vhost files.
Any suggestion?

How to setup sub-domains like blogspot

What should do to setup a sub-domain for the users when they sign-up into my site.
What are the infrastructure required? I am using Linux servers.
You can either use a specific DNS (CNAME or A/AAAA) entry for each known subdomain, or a wild-card DNS entry that'll accept *.example.com:
$ORIGIN example.com
foo IN A 12.34.6.78
bar IN A 12.34.6.78
or
$ORIGIN example.com
* IN A 12.34.6.78
The advantage of this latter is that no changes are required to either DNS or Apache configuration once the service is running. The disadvantage is that all such wildcard lookups must (by definition) end up returning the same IP address.
The Apache configuration will depend on your requirements, both for end-user control and security. Note that if the users have permission to run CGI scripts on the server then additional setup will be needed to ensure that that's done securely.
Depending on whether content is static or dynamic this will also affect your configuration:
Use mod_vhost_alias to map individual virtual hosts into their individual directories on the server.
If you really want, create a separate <VirtualHost> section for each known site, but then you'll have to restart Apache each time a new user signs up
Use a single <VirtualHost> and then look at the hostname part of the requested URL (from the $SERVER_NAME environment variable) in the scripts that render the output to figure out which user's content to display.
You can make a CNAME entry/ A Record in your DNS settings, for each subdomain
A CNAME record is a record in your
Domain Management Settings that allows
you to control a subdomain of your
domain.
To automate it along with registration, you can write a script which is executed for each user, when s/he registers.
You can refer to this link, as well, for a step-by-step process for Apache:
How to setup subdomains in apache
(since you mentioned Linux, I assume it must be APache. Please mention if it is otherwise)
Alternate Solution
You can also refer to the wildcard solution, given by Alnitak, in the same thread. I find his is an easier way. :)
infrastructure includes access the the dns server to add a wildcard entry, and rewrite rules in Apache.
Try these answers:
How to let PHP to create subdomain automatically for each user?
How to make subdomain user accounts in a webapp
or this link:
http://jam.jrox.com/docs/index.php?article=76
If your using Linux server's I'm assuming your using Apache as your webserver.
You'll have to setup proper DNS routing for the sub domain as well as a virtual host.
Virtual Hosts are fairly easy to setup but I'm not sure how easy it is to do them on the fly progmatically.
Most of the time it's as easy as editing your apache config file and adding the following:
Port 80
ServerName www.mydomain.com
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/user-bob
ServerName bob.mydomain.com
...
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/user-sally
ServerName sally.mydomain.com
...
</VirtualHost>
The VirtualHost Documention will probably of some use to you.
Apache allows you to specify any number of 'sites' based on subdomains on a single server. Creating a new 'site definition' file with the appropriate subdomain information in it, along with proper DNS wildcards, will do what you want.
In other words, the process is like this:
Setup wildcards so that *.mysite.com directs to the proper server.
When a new user signs up, create the proper Apache site definition file - you'll probably have a base template that you put the right subdomain information into and save.
Make Apache re-read its configuration.
Profit.
IMPORTANT This is based on a Debian-style Apache configuration, where the config files are included in a directory, and the main configuration reads all the config files in that directory. This will simplify things a great deal, because adding/removing subdomains will mean adding/removing files, rather than editing a single file, and so the process will be much easier to automate.