5

I'm trying to upload multiple Laravel 4 projects to my web server, not my development server. Each laravel 4 app is housed in their own subdirectory. How should my file structure be? I've searched around for a htaccess to remove the /public from the url but i've been unsuccessful. this server is for testing purposes only, it allows others to follow along as the project is being built. I know their are major security issues with leaving the laravel base structure in these directories, but again they are just for testing purposes and when the projects are complete they are removed and placed on their own hosting server. This is my file structure now:

-public_html/ 
main website html files
          -Test Site Subdirectory Folder
          -subdirectoryFolder
            -Store/
             -laravel app 1
      -blog/
        -laravel app 2
      -newspaper
        -laravel app 3

if i install laravel app in each subdirectory folder (www.testsite.com/Store, www.testsite.com/blog, www.testsite.com/newspaper) each application works, however I am trying to remove the public at the end of the url, www.testsite.com/Store/public is what is shown in the browser. Any help with this problem is greatly appreciated. Thank you.

Chonchol Mahmud
  • 2,717
  • 7
  • 39
  • 72
user3307994
  • 75
  • 1
  • 5

2 Answers2

11

Looks like my development structure here is exactly what you're trying to do. So I have this folder structure:

var
|-- www
    |-- Store
    |    |-- app 
    |    |-- bootstrap 
    |    |-- ...
    |-- blog
         |-- app 
         |-- bootstrap 
         |-- ...

This is my VirtualHost file /var/www/Store/vhost.conf:

Alias /Store "/var/www/Store/public"
<Directory /var/www/Store>
  Options Indexes Includes FollowSymLinks MultiViews
  AllowOverride AuthConfig FileInfo Indexes
  Order allow,deny
  Allow from all
</Directory>

Yeah, I put it in my project folder and add an include in /etc/apache2/apache2.conf:

Include /var/www/Store/vhost.conf

This is my .htaccess file:

<IfModule mod_rewrite.c>
    #Options -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /Store/index.php/?$1 [L]
</IfModule>

And I just have to hit

 http://server.dev/Store

or

 http://[ipaddress]/Store

To see it.

I've built a small script to do all that for me: https://github.com/antonioribeiro/laravel-installer. It downloads, installs, configures and boot a Laravel application in whatever folder I need to, doing whatever is necessary. Compatible with Debian based distros, like Ubuntu.

EDIT

Note that there are two things that remove the /public and the /index.php from your url:

1) the /Store pointing directly to your public folder:

Alias /Store "/var/www/Store/public"

2) and the rewriting rule to keep your url clean from the index.php:

RewriteRule ^(.*)$ /Store/index.php/?$1 [L]
Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
  • +1 .... just mentioning it here, if the projects are related, then making subdomains with laravel domain route grouping is much easier. :) – itachi Feb 15 '14 at 15:13
  • the projects are not related. this is on a live server, not my development server <- I have that set up correctly. it's just when i upload to the production server is where i run into a problem. – user3307994 Feb 15 '14 at 15:37
  • Development or not doesn't matter (and yours is a testing server), this is universal apache configuration and it will work even if you use it on a production server. If you want us to check your configuration, you should provide your configuration files. If your local configuration is not working on your server, looks like your server is pretty different from your local, so you have to understand the differences. Those configuration files I posted here can give you a hint of what you can do to remove the `/public` from your urls. – Antonio Carlos Ribeiro Feb 15 '14 at 15:50
  • my development server is working just fine. I upload the app to a development server for other ppl to test user interaction, just for feedback purposes. however when i upload to my server and i type in www.mylivedomain.com/Store i get a list of the files in that directory with the title of list of /Store. I tried you htaccess file but am unsure of what i change /project1/index.php to. I tried using public/index.php and Store/index.php...no change, still shows the list of files in that folder. – user3307994 Feb 15 '14 at 16:26
  • however if i click on the public folder in that list, it shows the home page with the url of www.liveserver.com/Store/public. i do wish to remove the public in the url. Also i was placing the htaccess file in the public folder and outside the public folder, i was unsure where that should go. – user3307994 Feb 15 '14 at 16:27
  • I think you need to revise your virtual host configuration. Just edited to point to the lines you must check. If you share your virtual host configuration and your .htaccess files, would be easier for ppl to help here. – Antonio Carlos Ribeiro Feb 15 '14 at 16:35
  • This partially got me there. I had to modify RewriteRule ^(.*)$ /Store/index.php/?$1 [L] TO RewriteRule ^ /Store/index.php/ [L] – Ratty Aug 08 '14 at 21:07
  • can you please le me know that if "Store" is my main project then how to access the routes of "Blog" from "Store" using a single domain? – Khuram Dec 18 '15 at 17:13
3

move all content include index.php in each public directory to Store, Blog and Newspaper respectively. and change the following line:

require __DIR__.'/../bootstrap/autoload.php';

$app = require_once __DIR__.'/../bootstrap/start.php';

to

require __DIR__.'/bootstrap/autoload.php';

$app = require_once __DIR__.'/bootstrap/start.php';

good luck.

EDIT: Sorry. You have to edit /bootstrap/paths.php as well, change

 'public' => __DIR__.'/../public',

to

'public' => __DIR__.'/../',
egig
  • 4,370
  • 5
  • 29
  • 50
  • just to clarify. when i enter the url www.testsite.com/Store i get a list of the files in that folder (Index of /Store) when i click on the public folder then the home page displays but it has the url of www.testsite.com/Store/public....i'm trying to remove that public in the url. When i tried your suggestion I just got a blank screen. – user3307994 Feb 15 '14 at 15:34
  • This is on a live server not a development server – user3307994 Feb 15 '14 at 15:35
  • can you please let me know that how to access/run the routes of laravel app 1 or others from laravel app 2 or laravel app 3? – Khuram Dec 18 '15 at 17:11