最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Unable to load javascript files on apache - Stack Overflow

programmeradmin1浏览0评论

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

/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.

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

/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.

Share Improve this question edited Apr 9, 2019 at 14:17 treyBake 6,5687 gold badges28 silver badges63 bronze badges asked Mar 3, 2015 at 2:14 user3889486user3889486 6562 gold badges7 silver badges22 bronze badges 1
  • 1 Your document root is /var/www/project/index/. Apache cannot serve a relative path above that – Phil Commented Mar 3, 2015 at 2:25
Add a ment  | 

2 Answers 2

Reset to default 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/

I Install phpmyadmin and after this javascript don´t load. I found on /etc/apache/conf.enabled the file javascript-mon.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

发布评论

评论列表(0)

  1. 暂无评论