-1

I have created a virtual host locally using domain name virtual hosting in which I have used an Alias to a directory pointing to another project on the same server (my local host) as given below:

<VirtualHost *:80>
    ServerAdmin admin@mail.com
    DocumentRoot /var/www/Proj1/public

    ServerName www.proj1.dev

    Alias /billing /var/www/Proj2/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /var/www/Proj1/public/>
        AllowOverride All
    </Directory>
</VirtualHost>

Now using 'www.proj1.dev/billing' I can access the 'Proj2' directory on my local. That's fine. In my 'ect/apache2/hosts' file the IP address 127.0.0.1 points to www.proj1.dev. Every thing is fine till here.

But when I did the same thing for my EC2 and try to access the 'l4.proj.etc/billing', which off course don't use '127.0.0.1' and uses actual IP address publicly accessible, gives me the 500 error. I can't get what is the problem. Here is my Virtual Host file on EC2:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/Proj1/public

    ServerName l4.proj.etc                # this is a subdomain

    Alias /billing  /var/www/Proj2/public

    <Directory /var/www/Proj1/public/>
            AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

I think the alias working might be different for the local host and the actual domain name.

Can someone please help me in this regard?

Here is the Log file's data:

127.0.0.1 - - [23/Dec/2015:16:34:21 +0500] "GET /billing/plans/img/unknown-plans.png HTTP/1.1" 304 180 "http://www.www.proj1.dev/billing/index.php/plans" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"

::1 - - [23/Dec/2015:16:34:28 +0500] "OPTIONS * HTTP/1.0" 200 126 "-" "Apache/2.4.12 (Ubuntu) (internal dummy connection)"



EDITING AS PER @Froggiz and @bangal ANSWERS

Modified Virtual Host File on EC2

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/Proj1/public

    ServerName l4.proj.etc                # this is a subdomain

    Alias /billing  /var/www/Proj2/public

    <Directory /var/www/Proj2/public>
        Require all granted
    </Directory>

    <Directory /var/www/Proj1/public/>
            AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

.htaccess file in Proj2's Public Directory

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Khuram
  • 101
  • 2
  • 11
  • Sometimes you have written "Porj" instead of "Proj". Are those typos? – Cybran Dec 23 '15 at 10:23
  • @MKJ, the configs you have posted, you have two different `ServerName`. If they are same virtualhost, the ServerName should also be same. – Diamond Dec 23 '15 at 10:45
  • yes off course both are different as one is on my local, and the other is on EC2. My local VH is fine, but on EC2 is not working. Local VH is not linked in any case with EC2 VH. It's just for testing on local while developing. – Khuram Dec 23 '15 at 10:53
  • yes DevCybran, 'Porj' is wrong, 'Proj' is correct. It's just a typo. I'm gonna correct it. – Khuram Dec 23 '15 at 10:54
  • @MKJ, Guess you don't get my point. In your 2nd config, you have `ServerName l4.proj.etc` but you are trying to access: `mydomain.etc/billing`. How should this ever work? You can only access it like: `l4.proj.etc/billing`. – Diamond Dec 23 '15 at 11:19
  • Error 500 mean logs, what does say logs ? – Froggiz Dec 23 '15 at 11:35
  • Hi Froggiz, I've added the logs data at the end of the my Question, you can see there. – Khuram Dec 23 '15 at 11:50
  • @bangal, now see, it was a typo, Pleas also try to guess what I wanted to describe and ask in this question. The only problem is every thing works fine on local, but don't work same thing on EC2. – Khuram Dec 23 '15 at 12:21
  • 1
    `304` mean not modified, so url has been delivered without error, and is the same than last time you visited it. This is not a `500` error. – Froggiz Dec 23 '15 at 13:28
  • @Froggiz! It might not be the 500 errror but browser shows it as 500 error. What can I do, it's strange enough, it works locally, but not EC2!!!!! – Khuram Dec 23 '15 at 20:59

1 Answers1

1

As your aliased directory resieds outside of the DocumentRoot, I guess you will need to explicitly permit access to the target directory:

Alias /billing  /var/www/Proj2/public

<Directory /var/www/Proj2/public>
   AllowOverride None
   Require all granted
</Directory>

See here: https://httpd.apache.org/docs/2.4/en/mod/mod_alias.html

Diamond
  • 9,001
  • 3
  • 24
  • 38
  • I would bet on `FollowSymLinks` rather than `Require all granted`, even if error hasn't been prooved at the moment ;) – Froggiz Dec 23 '15 at 13:31
  • Lets see ... :) – Diamond Dec 23 '15 at 13:36
  • @bangal and @Froggiz! Not working your answers. I've a .htaccess file in the public direcotory of Proj2. It's given at the end of my question and the modified virtual host file according to your answer is also given at the end of this question. Same error again. – Khuram Dec 23 '15 at 20:41
  • @MKJ, pls also add `AllowOverride None` in the same block and try. – Diamond Dec 23 '15 at 23:09
  • Hello @bangal and @Froggiz! My problem resolved, thanks for your help, can you help me how to remove 'index.php' when accessing alias 'billing'? Currently I access l4.proj.etc/billing/index.php/otherRoute but I want to use l4.proj.etc/billing/otherRoute. In my Virtual Host file AllowOverride all let me allow to remove 'index.php' from 'l4.proj.etc/routeOfProj1' but when accessing Alias I cant' get rid of 'index.php' Can you also help me in this regard? – Khuram Dec 24 '15 at 09:03
  • First, post what you did to make it work please. Then add `RewriteCond %{REQUEST_URI} !/billing` to your rewrite cond with index.php – Froggiz Dec 24 '15 at 09:31
  • Where to put that line? I'm not much aware of Apache language and it's handling. Can you pleas see [link](http://stackoverflow.com/questions/34356663/how-to-handle-routes-of-two-laravel-projects-on-one-domain-or-server) and go to the bottom of the answer I gave, This is what I wanted to. and Please give me detailed answers as I'm new with apache's handling. Pleas? – Khuram Dec 24 '15 at 09:47
  • @MKJ, see my updated answer pls. – Diamond Dec 24 '15 at 21:06
  • @bangal! I'm requesting and suggesting this idea! Pleas create a Laravel 4 project and a Laravel 5 project. Then do the same thing I'm doing i.e. create a virtual host for Laravel 4 project and in this Virtual Host file create an alias for Laravel 5 project. Then use the same answer their, you'd find what's wrong and what's to do? It is a request. Feel free to ignore me. – Khuram Dec 29 '15 at 16:56