2

I have the following file structure for a php application running with apache server in a debian computer.

/var/www/project/
|-- index/index.php
|-- local
    |-- view
    |   `-- *.php
    |-- model
    |   `-- *.php
    |-- controller
    |   `-- *.php
    |-- supportfiles
    |-- css
        |   `-- *.css
    |-- javascript
            `-- *.js
    . . .

I've configured apache so that when I type in my browser http://localhost, apache loads /var/www/project/index/index.php.

To do this, I've changed two files

/etc/apache2/sites-available/000-default.conf

where I set

DocumentRoot /var/www/project/index/

and the file

/etc/apache2/apache2.conf

where I also set

<Directory /var/www/project/index/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

This changes seem to work ok since http://localhost loads the intended index.php file located in the /var/www/project/index directory; however, I'm unable to load java script files such as the following

<!-- <script language="JavaScript" src="../local/supportfiles/javascript/validation.js"></script>  -->

What is the problem here? I'm guessing the problem is that apache does not have access to /var/www/project/supportfiles/javasecript/*.js. The original apache configuration (where the apache root directory was /var/www/ and had to load the index.php file by typing http://localhost/project/index) loaded the java script files normally.

1
  • 1
    Your document root is /var/www/project/index/. Apache cannot serve a relative path above that Commented Mar 3, 2015 at 2:25

2 Answers 2

5

Apache cannot serve files that are outside of the document root. In this case, your document root should probably be set to /var/www/project/. If you would like to be able to still access your site with http://localhost/ then you should move "index.html" to the root of the project folder.

/var/www/project/
- index.php
- local/
    - view/
    - model/
    - controller/
    - supportfiles/
    - css/
    - javascript/
Sign up to request clarification or add additional context in comments.

2 Comments

I see. Is it safe to put the local/ directory inside the document root? That's why I separated the project into two different folder index/ and local/
I'm not sure what the significance of your local folder is but any document that is going to be served by the web server needs to be inside of the document root. You will not be able to access any of the php, css or js files in the local folder unless it is included in the document root.
1

I Install phpmyadmin and after this javascript don´t load. I found on /etc/apache/conf.enabled the file javascript-common.conf inside this file has a line Alias /javascript /usr/share/javascript

This line make apache follow to /usr/share/javascript all content of pages. You need change on your pages of javascript to scripts or other name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.