Point to a virtual directory - php

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.

Related

Softaculous start symfony app

So i have downloaded Softaculous (ampps), and from their dashboard I installed the symfony framework, and it created a symfony3 folder with all of the files in the www directory (with an index.php file in the root directory of symfony that only prints a welcome message).
When I access it through http://localhost/symfony3/ it shows the index.php (if i remove the index.php it just shows the tree of the symfony3 directory)
Is it possible to set my localhost to launch the app? If I run php bin/console server:start it launches my app on localhost with port 8000. Is it possible to set up Ampps to launch my app when it is accessed through localhost/symfony3/ ? Thanks in advance!
EDIT: So turns out I could do this just by editing the httpd70.conf file (ampps>conf>httpd70.conf)
find the <VirtualHost 127.0.0.1:80> block and change the <Directory "{$path}/www"> to the web folder in your app (in my case it was <Directory "{$path}/www/symfony3/web"> and do the same thing for DocumentRoot "{$path}/www" in the same block. Restart your Apache. You should now see your app when you just go to http://localhost/ (http://localhost/app_dev.php/)
If I understood your question, you need to set up you web server with correct configuration file and to change permissions for Symfony project.
It might be helpful (documentation for Symfony 2.8.*):
Web server configuration.
Symfony project file permissions.

Laravel – Include external Project

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

Setting PHP Document Root on webserver

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.

How to run PHP application out of localhost?

I got this task form school, to make a PHP web application. But I don't really understand what this requirement might mean
It should be possible to run this application outside the domain root
e.g. sample URL: http://localhost/task/.
I searched a little bit on the internet but was not able to find anything that I could understand ?
I have wamp, and the folder where is my sites is wamp/www/task
When they say "outside of domain root" it means that you should not be forced to go to
http://localhost/yourfile.php
but you could put it in a subdir, like
http://localhost/task/yourfile.php
What they want you to do is harder to guess, but it could mean that you need to be able to run it in any subdir, so take care of you imports to be able to handle that (e.g.: not hardcode the dir you're working in).
Domain root seems to be at localhost, this just means it should be easy to rename your web application folder and make it still work at anywhere.
# http://localhost/task
$ cd wamp/www/
# http://localhost/task2 - should be accessible without you needing to change anything
$ mv task task2
From technical point of view, you should use relative path for all your links and images as well as external resources such as javascript / css files
you can set vitual host for your web server & access your PHP Application likw www.oorja.local
in the wamp server, just add below code at end of your httpd.conf file, which allow you access your PHP application without localhost, Document root and Directory have your physical pathe of your application directory.
ServerName oorja.local
DocumentRoot E:/LAMPSYSTEM/wamp/www/oorja/public
<Directory E:/LAMPSYSTEM/wamp/www/oorja/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>

Netbeans and Zend-Framework

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.

Categories