Currently I have an Ubuntu 12.04 webserver running apache2. I have it setup to dynamically create subdomains by creating new folders under /sites/example.com/*/public /sites/example.com/www/public is reserved for my main root site.
This is working out, however I am unable to configure PHP's $_SERVER['DOCUMENT_ROOT'] to be dynamic to the newly created folder.
When I echo $_SERVER['DOCUMENT_ROOT'] I get /etc/apache2/htdocs which I assume is some sort of default path. I would like this to be: /sites/example.com/*/public instead
# Wildcards
<VirtualHost *:80>
VirtualDocumentRoot /sites/example.com/%1/public
ServerAdmin mike#example.com
ServerAlias *.example.com
</VirtualHost>
Curious why PHP doesn't pick up the the virtual document root setting above, I'm likely doing something wrong.
Solution found at : http://joshbenner.me/blog/quick-tip-get-proper-document-root-when-using-mod-vhost-alias/
The Apache module mod_vhost_alias and its VirtualDocumentRoot
directive can really be a great time saver for local development (some
googling will explain why in more deapth). Basically, my local dev is
set up so that I just have to create a directory in my aliases
directory, and I just then navigate my browser to a URL matching the
name of that new directory, and apache knows exactly what to serve
automagically.
However, there are a few evil gotchas when using mod_vhost_alias, one
of which is that the PHP global $_SERVER['DOCUMENT_ROOT'] remains set
to the apache default DOCUMENT_ROOT environment variable rather than
being re-assigned to the document root activated by the
VirtualDocumentRoot directive for the current URL. This can cause some
PHP applications (that are too trusting) to die for one reason or
another.
I found a great solution to this in the related apache bug report:
Simply add the following line to your apache configuration inside the
VirtualDocumentRoot vhost definition:
php_admin_value auto_prepend_file /path/setdocroot.php
Then, create the referenced PHP file, and put set this as its
contents:
<?php $_SERVER['DOCUMENT_ROOT'] = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['SCRIPT_FILENAME']); ?>
Now, every page load has this file executed, which properly sets
DOCUMENT_ROOT.
This has apparently (finally) been fixed in Apache 2.4. Unfortunately, Ubuntu 12.04 still runs Apache 2.2.
Having said that, Ubuntu 14.04 (the next LTS release) is out now and do-release-upgrade should now be enabled for 12.04 to 14.04 upgrades since 14.04 had its first point release last week.
Related
In a Laravel project I have to include multiple projects, so that they are accessible at /example.
These projects have the structure of
/example
- index.php
- main.css
- app.js
(Usually there are more files then that.)
I have tried to use Redirect::to("example/index.php"), however this breaks all the <link>'s & <src> (where I would need to prepend /example to all of them.
This would theoretically work, however I would rather not store these files in the Laravel project itself, since they are basically self-contained projects.
What is the best way to include such external projects?
This would theoretically work, however I would rather not store these files in the Laravel project itself, since they are basically self-contained projects.
That's an excellent approach. Rather keep Laravel as Laravel and host the stuff just outside of your Laravel project.
Since you're using Apache, here's how to create a Virtual Host for that external project.
Please note - I'm assuming that your project lives in /var/www.
Decide on a URL for that project - I would use example.mylaravelproject.com. But anything will do.
Confirm the path of your project folder. For this example, we'll assume it's /var/www/example/
Run the following command (assuming you're using Ubuntu) - sudo nano /etc/apache2/sites-available/example.mylaravelproject.com.conf
Ensure the new file has the following contents:
<VirtualHost *:80>
ServerAdmin <your email address here>
ServerName example.mylaravelproject.com
DocumentRoot /var/www/example
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save and close the file
Run the following command sudo a2ensite example.mylaravelproject.com.conf
Run sudo nano /etc/apache2.conf
Make sure that this line appears somewhere in this file (preferrably in a <Directory> tag - AddType application/x-httpd-php .php
Then restart Apache by issuing the following command sudo service apache2 restart
Technically now your site has a valid vhost and should be working.
If you're doing this on a local environment and want to access your example project via the browser, you'll need to complete a few more steps:
sudo nano /etc/hosts - again, assuming that you're running Ubuntu
Add this line somewhere to your project: localhost example.mylaravelproject.com
Save and close that file. You should now be able to access that url via your browser.
If these steps don't work, it's likely that Apache isn't parsing the PHP files. If that's the case, try these links for some good answers on making Apache parse PHP:
Apache 2 server on ubuntu can't parse php code inside html file
Apache Virtual Host not parsing PHP
I got a question about a special php framework called Koala-Framework.
I've set up an apache2 on my virtual ubuntu OS, added a virtual host reserved only for my first website with this cms, also added the hosts entry and followed the tutorial on http://www.koala-framework.org/about/cms/installation , but if I enter the local domain (in my case the configured kwf-cms-demo.localhost), I'm only redirected to see the folder-structure and not the downloaded demo-website...
Which DocumentRoot the virtual hosts needs to be redirecting? (Because I think this could be the root of this problem...)
PS:
/var/www/kwf-cms-demo$ php bootstrap.php setup returns:
Application seems to be set up already. (update file exists)
so, I think the setup has to be finished without any problem...
Seems Apache isn't starting up the bootstrap.php because the rewrite rules in .htaccess are not honored.
Enable mod_rewrite like that:
sudo a2enmod rewrite
Also see point 5 here:
http://www.koala-framework.org/about/server_requirements/ubuntu_example_configuration
I deployed an application on Heroku and I used a folder to place all my files inside thus now my application is only accesible from:
http://myapp.heroku.com/app/
Is it possible to create a virtual root to point
http://myapp.heroku.com -> http://myapp.heroku.com/app/ ?
Something similar to Apache VirtualHost?:
<VirtualHost 10.1.2.3>
ServerAdmin webmaster#host.foo.com
DocumentRoot /www/docs/host.foo.com
ServerName host.foo.com
ErrorLog logs/host.foo.com-error_log
TransferLog logs/host.foo.com-access_log
</VirtualHost>
Thanks in advance.
Yes you can configure the apache as well, however, this needs some changes on your system.
I've compiled a blog post recently that shows this (as the last part), it also shows how you can compile your own PHP extensions for heroku:
PHP on Heroku, again (by hakre; 20 May 2012)
It basically works by extending the standard configuration with your additional settings in another file. Look for the Configure the Webroot section, that's where it starts:
Now comes the next tricky part that is specifying the webroot. Specifying the webroot needs a little bit more work and background information. The CVBacklogs applications webroot in the git-tree is src/app/public. For Heroku, by default, the webroot is the root of the git-tree. That directory is internally mapped to /app/www btw. So what this needs is to create a so called Procfile that starts a sh-script each time the Heroku app web-node starts. That script then modifies the Apache configuration and includes your own config which is setting the webroot to /app/www/src/app/public. So we create the procfile, a config directory, the script and the Apache configuration. Ready?
You can't do anything with Apache / Nginx configuration on Heroku - these are all beyond your control. You could do some kind of php based redirect in the root folder to the /app folder or alternatively rejig the repo so app is the top level.
Earlier today I tried installing the MyImouto image board software on my Apache server. I already have the full MediaWiki engine installed on port 80 (localhost/wiki/) and the MyImouto board installed in a virtual host on port 3000, running completely separate from the main web server.
After fiddling around a little, I made a mistake with a php-based upload on the main server and had to reinstall apache and php both, which I did, and upgraded to the latest versions (Apache 2.2.22 and PHP 5.4.0). I managed to get my setup up and running successfully, both with the port 3000 virtual host and without. And MediaWiki functions fine, except for one thing.
NOW when I type in http://localhost/wiki/index.php as I have always done in the past, something is redirecting it to http://localhost:3000/wiki/index.php/Main_Page and shifting it to the other virtual host, where there is no wiki at all. However http://localhost/wiki/index.php/Main_Page does work perfectly.
There's an .htaccess file in localhost:3000 which I renamed to something else, but that doesn't seem to do the trick. I also tried clearing the browser cache as well as running a session_destroy via php. It didn't fix it.
I even turned off the second virtual host in Apache's httpd.conf, but it still redirects me which tells me that it is something in the main webserver. I did not touch the MediaWiki configuration or code during this entire time.
I also attempted accessing http://localhost/phpMyAdmin and THAT redirected me to http://localhost:3000/phpMyAdmin/, as well as http://localhost/AdminTools which does the same type of thing. Httpd.conf now no longer has any references at all to the virtual host *:3000.
However, my main index (http://localhost/index.php) has the following header redirect, which successfully lets it work even when http://localhost is typed into the address bar.
header("Location: index.php?content=main");
I tried disabling expires_module and headers_module in Apache, thinking there might be some weird caching issue due to that now-renamed .htaccess file. That did not help either. In addition, I checked my hosts file and there is nothing odd in there, nor am I proxying through anything (this -is- localhost after all).
Would appreciate any help in figuring out what's causing this and how to fix it.
Windows XP SP3
Enabled Modules in Apache:
actions, alias, asis, auth_basic, authn_default, authn_file, authz_default, authz_groupfile, authz_host, authz_user, cgi, dir, env, expires, headers, include, isapi, log, mime, negotiation, rewrite, setenvif, php5
Enabled extensions in PHP:
curl, fileinfo, gd2, mbstring, exif, mysql, mysqli, openssl, pdo_mysql, sockets
I managed to figure it out. After fiddling a little bit with .htaccess and Rewrite Rules (none of which did anything), I took a look inside my httpd.conf file again and found that I had typo'd my port-80 Virtual Host:
<VirtualHost *:80>
ServerAdmin -myemail-#gmail.com
ServerName -blahblah-.no-ip.org:3000
DocumentRoot "C:/wwwroot/tfg"
<Directory "C:/wwwroot/tfg">
OptionsIndexes FollowSymLinks
AllowOverride All
Allow from all
Deny from 186
Deny from 187
</Directory>
</VirtualHost>
When in fact it should have been ServerName -blahblah-.no-ip.org:80.
Simple typos: always the ones that slip by the easiest.
I have just started using the Zend-Framework. On advice of a friend I use NetBeans for PHP development with Zend. I have installed NetBeans and referenced the Zend-Framework under Tools>Options>PHP>Zend, registered it since I am using a version newer then 1.10.
Under PHP>General I have inluded the Zend-library path as a Global-Include-Path.
Since I've read that the beginners tutorial provided on the website (http://framework.zend.com/manual/en/learning.quickstart.create-project.html) has some errors and since it does not use NetBeans I started with this video tutorial: http://netbeans.org/kb/docs/php/zend-framework-screencast.html
Creating the project as a Zend-Framework Project worked just fine, all default folders and files are created. However, when I run the project with this defauilt setup the browser should diplay the index.php provided by the Framework under localhost/quickstart, instead of that it just displays a listing of the files of directories:
Index of /quickstart
Parent Directory
.zfproject.xml
application/
docs/
library/
nbproject/
public/
tests/
I suppose there is something wrong with the configuration of the apache server but the video screencast did not mention any needed configuration when using netbeans.
I am using xampp and one of the things that might be the problem is the httpd.conf file as described in the tutorial (http://framework.zend.com/manual/en/learning.quickstart.create-project.html) since no NameVirtualHost-propperty is defined there and no VirtualHost configured. However I didn't want to change the httpd.conf without knowing if that is the problem.
Also adding a line "127.0.0.1 quickstart.local" to the hosts file turned out to be impossible under Windows 7, so in case this is actually neccesary, I would apreciate any help.
Thanks,
Lukas
Have you set the DocumentRoot in the apache httpd-vhost.conf to the public folder?
All you should need to do is add public to the end of your current document root...
Also to change the vhosts file in windows 7 you need to find notepad in the start menu -> all programs -> accessories
Right click and run as Administrator
File -> open -> C:\Windows\System32\drivers\etc\hosts
Now add your records and save.
Opening as Administrator allows the save to attually save the changes.
Ironically, I just went through all of this yesterday. First, what happens when you type: localhost/quickstart/public, into your browser instead of: localhost/quickstart ? The controller is accessed via the index action and .htaccess file inside that directory.
Second, in regards to editing the hosts file... I have windows 7 as well, and all i did to find it was type "system32" in the Search Programs and files, then follow the path to the hosts file. I was able to edit it using notepad and it worked great!
there are two steps to configuring the vhost after that. You will need to uncomment a line in the httpd.conf file under the apache folder, remove the # from httpd.conf:
#Include conf/extra/httpd-vhosts.conf
Then go to the extras folder and add the following to the bottom of your httpd-vhosts.conf file like so:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.localhost
DocumentRoot "C:/path_to_local_webroot/quickstart.com/public"
ServerName quickstart.com
ServerAlias quickstart.com
ErrorLog "logs/quickstart.com-error.log"
CustomLog "logs/quickstart.com-access.log" common
</VirtualHost>
For your hosts file, just add one line to the bottom:
127.0.0.1 quickstart.com
Then restart your server and you should be good to go.