Jump to content

Where should my project folder go ?


ajoo

Recommended Posts

Hi all !!
 

I have finally setup my ubuntu linux VM on Virtual box for web development. :happy-04:  

 

My document root is /vagrant/myproject.com/public. which is the same as /var/www/myproject.com/public. This is the directory structure by default if i understand correct. 

My project folder which contains the index.php and all other files and folders is in say a folder called Magical. 

 

Now I am supposed to place my project folder at this location: /vagrant/myproject.com/public/Magical. 

 

If I now type, http://myproject/magical in the URL, the index.php inside Magical is invoked correcty and displays the webpage. However this is rather odd and not in accordance with the manner websites are normally invoked. I would like to type, just like everyone else, http://Magical.com to invoke the index.php.

That would be like placing Magical in place of myproject in the folder hierarchy so that the document root is  /vagrant/Magical.com/public. That seems to go against the convention and the tutorial followed. The root folder should be below the public folder.  

 

So what should I do to rectifyy this ? Do I need to change some settings in the conf files or in the placement of my folder so that I just  type http://Macical.com to invoke the index.php ? Please help clarify.

 

Thanks all !

 

Link to comment
Share on other sites

You need to use separate <VirtualHosts> for each domain you want to have. I do not use vagrant so I have no idea if you can configure multiple domains through it or if you'd have to edit the configuration files yourself.

 

You'd end up with something like this:

<VirtualHost *:80>
    ServerName magical.com
    DocumentRoot /vagrant/magical.com/public
</VirtualHost>
<VirtualHost *:80>
    ServerName myproject.com
    DocumentRoot /vagrant/myproject.com/public
</VirtualHost>

You'll also need to ensure that your magical.com and myproject.com resolve to the VM's IP so they connect properly. You can change your host's hosts file to change what the names resolve too. Rather than override actual domain names what I prefer to do is create .local equivalents. For example magical.local, myproject.local. That leaves me with the ability to visit the actual .com's if necessary.

Link to comment
Share on other sites

Hi kicken,

 

Thanks for the response.

 

Vagrant is just to set up a VM fast everytime. Once it's installed ubuntu and apache and the required software, it's role is almost over if one wants that. So it's just a ubuntu machine on a VM now. The only thing is that I get a shared folder /vagrant which maps to /var/www. i.e any changes I make to the folder /vagrant/myproject.com/public will reflect in var/www/myproject.com/public. Other than that I can configure the VM it as I like. 

 

So yes I have a virtual host configured exactly as you have shown. I have made changes to the hosts file on windows so that I can check out / try out the website on my host machine and it's working too. Yes I can create local equivalents of domain names but that's not really the issue. 

 

There is no index.html in public folder because my project, as I wrote earlier, is in a folder called Magical. Instead of putting an index.html in the public folder, I need to put my entire project in that folder. So it becomes /vagrant/myproject.com/public/Magical and to access the index.php in this Magical folder the URL becomes  - http://myproject.com/magical. - which is what is odd. What I am looking for is to make whatever changes needed and where ever so that when I type http://www.magical and that should access the index.php from the said folder and display the webpage. 

 

I hope I am able to clearly enunciate my problem. Thanks for the response and looking for some more help here.

 

Thanks loads ! 

Link to comment
Share on other sites

Hi requinix,  

 

Thanks for the reply. 

 

You wouldn't be angry if i told you that I did?  :happy-04:. I did, But i thought that it was also convention  to have the public folder as the last in the document root. i.e. either public or public_html or html, because every search on google showed the document root to end in the public folder. So I thought it was mandatory to have the public folder there and so there was some mechanism for what I wanted. 

 

Just one thought then, what's the use of myproject.com in /vagrant/myproject.com/public. I would rather have /vagrant/magical.com/public/magical. Would that not be more logical and nicer? What do you say?

 

Thanks again ! 

Edited by ajoo
Link to comment
Share on other sites

Hi requinix,

 

I am at a stage where I really want to check whether my website is good for a server and therefore try it out in a real development environment or as close to it. So i have to know how to get my website up and running on a server. So it was important for me to know the where and how on a server. 

 

 

 

 

Personally I would make "magical" its own site at /var/www/magical.com but fact is it doesn't really matter.    

 

I think you mean I don't really need to have these two - /myproject.com/public/ -folders in between. Correct ?! Please affirm. i'll head back to get the site up.

 

Thanks ! 

Link to comment
Share on other sites

Just one thought then, what's the use of myproject.com in /vagrant/myproject.com/public. I would rather have /vagrant/magical.com/public/magical. Would that not be more logical and nicer? What do you say?

I generally use /var/www/example.com/public_html as my document root format. That keeps it nice and organized by domain. Sub domains end up in a folder under the domain, eg sub.example.com would be located at /var/www/example.com/sub/public_html. I'll adjust the document root if it works out better as something else. For example on a Symfony based site I'd point the root to the web/ folder.

 

I don't really see the point in the extra /magical at the end of your example path, seems unnecessary.

Link to comment
Share on other sites

Hi kicken, 

 

Thanks for the reply.  :happy-04:

 

It's not that I see any point in the extra /magical folder at the end, it's just that I am trying to figure out where to place my project folder so that when I type magical.com as the URL, it should access the index.php of my project folder. . :confused:

 

All the examples that I came across just show a index.html inside the public folder. None showed how to handle a project folder that contained the index.html and the rest of the project folders and where to place that project folder.  

 

Please show me how best to place my website / project folder in the directory hierarchy so that it may access my project's index.php when I type magical.com in the URL 

Link to comment
Share on other sites

:suicide:

 

It's not that I see any point in the extra /magical folder at the end, it's just that I am trying to figure out where to place my project folder so that when I type magical.com as the URL, it should access the index.php of my project folder. . :confused:

The location of the site code on the server has absolutely no bearing on the domain name. You can put the files anywhere you want so long as you have your virtualhost config set up with the right ServerName and the right DocumentRoot.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.