-2

I'm working with an existing PHP web application. It's running fine on the remote Linux server but I can't run it on WAMP server, Windows 7 on my local computer. The problem is the previous developer's used absolute path all over the code. for example one of them is:

require '/disk2/html/src/web_tool/db_connect.php';

my localhost folder is F:\wamp\www and I have the same structure: F:\wamp\www\myProject\disk2\html\src\web_tool\db_connect.php

But it can't find the db_connect.php. I can't change the path because it's a big project and if I want to, I have to find and change more than 400 line of code. I'm not sure what the problem is and how to make it work. Any suggestion is highly appreciated.

EDIT: I ran a simple test on my WAMP Server. I created this file structure: F:\wamp\www\test\myfolder\index.php with this code:

require '/myinc.php';

and F:\wamp\www\test\myinc.php with this code:

echo 'It works!';

I get this warning:

Warning: require(/myinc.php): failed to open stream: No such file or directory in F:\wamp\www\test\myfolder\index.php on line 2

and this error:

Fatal error: require(): Failed opening required '/myinc.php' (include_path='.;C:\php\pear') in F:\wamp\www\test\myfolder\index.php on line 2

I don't have such a folder as C:\php\pear on my disk.

The WAMP server is just installed, haven't touched anything in the php.ini or other config files. the version is:

WAMP SERVER 64bit version 2.5 including:

Apache : 2.4.9 MySQL : 5.6.17 PHP : 5.5.12 PHPMyAdmin : 4.1.14 SqlBuddy : 1.3.3 XDebug : 2.2.5

Sam
  • 93
  • 1
  • 9
  • 1
    the problem lies in the fundemental architecture of the project.. if you have to change 400 lines of code to edit the path to a library, then you have made a serious mistake. – RaggaMuffin-420 Jun 10 '14 at 13:14
  • What version of wampserver are you using and what version of Apache. – RiggsFolly Jun 10 '14 at 16:15
  • @RiggsFolly I just added the versions in the post. – Sam Jun 11 '14 at 01:03
  • 1
    @RaggaMuffin-420 It's not my code, it's the previous programmer's. it shouldn't have implemented like this in firs place but I have to live with it. – Sam Jun 11 '14 at 01:21
  • we've all been there :P – RaggaMuffin-420 Jun 11 '14 at 07:37
  • The `(include_path='.;C:\php\pear')` is because PHP is picking up a default value for the parameter `include_path` probably set at compile time. Create the Virtual Hosts as I suggested its the only reliable solution. Its what people should have been doing for all there projects anyway. Its the only way to create an environment that will accurately match a live hosted server environment. – RiggsFolly Jun 11 '14 at 10:20

3 Answers3

1

If you have the same folder strcture a simple set_include_path() should solve the problem in the root directory. I gues in F:\wamp\www\myProject there should be an index file, just add there:

set_include_path('');

But if you can't find the file you're looking for, I guess that it is missing / you did not copy over everything you needed (something like that). Than the problem is not really the relative path.

Sesertin
  • 462
  • 2
  • 11
1

I think your best solution would be to move the site source and create a Virtual Host, then the absolute paths would work and you can address the site properly as well.

First move the disk2 folder and all its subfolders to the root of your F: drive.

F:\disk2.....

Then create a Virtual Host to describe its new location.

Edit \wamp\bin\apache\apache2.x.y\conf\extra\httpd-vhosts.conf

If this is your first Virtual Host definition, remove the existing contents of this file.

I have assumed that F:\disk2\html is the correct folder to become your DocumentRoot.

Add this to the file

<IfDefine !APACHE24>
    NameVirtualHost *:80
</IfDefine>

## so the the wamp menu page loads
<VirtualHost *:80>
    DocumentRoot "F:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory  "F:/wamp/www">
        AllowOverride All

        <IfDefine APACHE24>
            Require local
        </IfDefine>

        <IfDefine !APACHE24>
            Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1 localhost ::1 
        </IfDefine>

    </Directory>
</VirtualHost>


<VirtualHost *:80>
    DocumentRoot "F:/disk2/html"
    ServerName example.dev
    ServerAlias www.example.dev

    <Directory  "F:/disk2/html">
        AllowOverride All

        <IfDefine APACHE24>
            Require local
        </IfDefine>

        <IfDefine !APACHE24>
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1 localhost ::1 
        </IfDefine>

    </Directory>
</VirtualHost>

Save this file.

Edit httpd.conf and remove the comment from this line

#Include conf/extra/httpd-vhosts.conf

remove the # in col 1 and save that file.

Now edit the hosts file C:\windows\system32\drivers\etc\hosts and add these lines.

127.0.0.1  example.dev
::1 example.dev

This is a windows protected file so you will have to open your editor using the "Run as Administrator" or you wont be allowed to save your changes.

Now start a command windows also using the "Run as Administrator" and execute these 2 statements to refresh the DNS cache with your changes to the hosts file.

net stop dnscache
net start dnscache

Now restart Apache so that it picks up your configuration changes, and you should be able to use this address in the browsers address bar.

example.dev

The DocumentRoot should be as it was on the live server and the absolute paths used in the PHP code should also now work as they do on the live server.

Change example.dev to whatever makes sense as related to your live sites domain name.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • I think I'm missing something rather simple. I've updated the post, please have a look at my test and errors I get. Thanks. – Sam Jun 11 '14 at 01:09
  • This is the best solution, I made a virtual host and all the absolute paths work! Thanks. – Sam Jun 12 '14 at 04:01
  • Your config didn't work though for some reason. I think I should've used www.example.dev in the browser instead of livedomain.dev you mentioned. Please edit the post and I'll accept it as the answer. Cheers :) – Sam Jun 12 '14 at 04:08
  • Woops, I have corrected so all references are consistant. The idea was that you use the live domain name but `.dev` instead of `.com` or whatever yur tld is! – RiggsFolly Jun 12 '14 at 09:09
0

This isn't much of a technical answer and it's five years later, but FWIW I had the same issue after upgrading my WAMP version after a couple of years that some of by requires were no longer working on the localhost while they were working just fine when published on the active webapp.

For me, I found a setting called 'allow_url_include' and activating that setting and restarting services everything appears to be in working order now. Hope this helps somebody.

it was the second php setting

ctrlcool
  • 53
  • 6