Jump to content

XAMPP for Linux 8.2.4 - could not see javascript file

Go to solution Solved by requinix,

Recommended Posts

Hi all, I installed XAMMP for Linux 8.2.4 to run my website including php codes test locally first. 

When I copied everything one-to-one from server to my local htdocs folder of XAMMP, I can run my page and php codes, and css codes. However, not javasript codes. My index.php file includes external javascript file defined as in meta tag  :

<script type="text/javascript" src="/js/main.js"></script>

File is there but developer console said "main.js could not found". Then I looked at the w3schools website(https://www.w3schools.com/tags/att_script_src.asp) and I changed the line as :

<script src="./js/main.js"></script>

I added "." infront of the path and remove 'type="text/javascript' words. Then error gone, but none of the function worked correctly. New error was : 

Warning: file_put_contents(/opt/lampp/htdocs/pages/filesList.txt): Failed to open stream: No such file or directory in/opt/lampp/htdocs/enginery/pages/standards/home.html

: file_put_contents(/opt/lampp/htdocs/pages/filesList.txt): Failed to open stream: No such file or directory in

What is happening? Both files are there, is there any problem with write premission? Everything under XAMMP's htdocs are under root's control, is this the problem?  Does anybody guide me to solve this error?  Thanks.

Edited by eaglehopes
Added new explanation information and new error
Link to comment
Share on other sites

  • Solution

1. You're using XAMPP on Linux? 😆 Just install Apache, PHP, and whatever else you need through your package manager. Normally.
2. It's code. Singular. "Codes" are things you enter into videogames.
3. Don't reference w3schools. Sometimes they tell you the right thing to do, sometimes they tell you the wrong thing to do, and if you're learning then you won't be able to tell the difference between them.

Where did you put main.js? /opt/lampp/htdocs/js/main.js? Then the first form you had is correct. If not then (a) why not? and (b) the second form was correct (except "js/main.js" - no ./ - is cleaner and means the same thing), however you might discover problems with this approach...

And changing that won't affect any of your PHP code. The thing with file_put_contents is a completely separate issue. That error is telling you that /opt/lampp/htdocs/pages does not exist.
It's also a red flag that you're using code to create this filesList.txt file, but I'm going to ignore it.

Also, please tell me you're not running this as root. Use your user account - give it ownership of /opt/lampp/htdocs and everything inside it.

  • Like 1
Link to comment
Share on other sites

1. I tried installed them  package by package but, could not start Apache2. Since I didn't know there is log, but I could not know etc. so I changed my tactic and uninstall all and install XAMPP. Even after XAMPP apache server did not  start since it gave error "port already listening..." due to that another program had already used apache's port etc. I used "ss" command etc. to solve it manually(i gave details in my own blog page). So normal procedure did not work as I expected for me as a beginner, so I used XAMPP which is more compact and solves all of my configurations related problems(except port :D ) . And using XAMPP in Linux is not a guilt, XAMPP has Linux version :D.

2. Since English is not my mother/native language, it is my mistake.

3. Thanks for drawing an attention to that point,I am learning so I will be more careful about that point next time. 

Ok, as you said, file_put_contents error was solved, since I copied everything from server to local htdocs folder of XAMPP but under folder named "enginery", not to its root(htdocs). So as you said my php code did not work locally because of that !

I love red flags :D. If I prevent access to that file by .htaccess file, can I drop that red flag?

:( I used them as root but changed :D as you suggested and now everything is easier than before! 

Thanks requinix from a short course from English to Linux & PHP !

Link to comment
Share on other sites

1 hour ago, eaglehopes said:

I tried installed them  package by package but, could not start Apache2.

Did you edit any of the configuration yourself? It pretty much works out of the box... and given that XAMPP said the port was already in use means that it was, in fact, running.

1 hour ago, eaglehopes said:

Since English is not my mother/native language, it is my mistake.

It's a common thing that even English speakers will do. It annoys me, personally. I was unnecessarily harsh on you for it.

1 hour ago, eaglehopes said:

If I prevent access to that file by .htaccess file, can I drop that red flag?

I mean more that you (probably) shouldn't be creating this file at all. What is it? Most of the time, someone will do this sort of thing because the file acts as a database instead of, you know, using an actual database (which is the "M" in XAMPP).

Link to comment
Share on other sites

No, I could not manually configured anything before installing XAMPP since I did not know where and how to do it(by the way I am still do not know it). However, after installing XAMPP, it puts all apache, php and sql files under the same folder(/opt/lampp) and by the help of XAMPP's own help documents I learn that how to configure each(including php.ini etc.).

I managed my website by using php-javascript code combination such that,  php code does :

1. first checks category/subcategory folders and put their names on the menu

2. checks folders for each subcategories

3. lastly, checks files under each subcategories and prepage them as links

4. javascript get all those links and put them into pagination process.

Therefore, when I add a "x.html" file under category/subcategory folder, it automatically put it into the menu as a link, similar for category and subcategories- each folder creates a new item in menu....

I read some specific tags from each ".html" file I added such as title, date publish/edit and summary....etc. and when users clicks on it, everything will be tranferred to the div inside the main page... goes on like that, so I did my some kind of automatic website management system. I am now trying to do all these jobs by using sql database. 

So when I delete some files, it automatically removed from web page links. Therefore, in such times I need to create XML sitemap again! So list of files is basically for

1. creating XML sitemap and

2. to see which file I edit the latest. Since I put some of the latest edited blog pages in my home page (main.js does that). It means it includes last edit time info too.
I created a shell(bash) script file and using this file, I can create XML sitemap easily. Script is very easy, simply add page's own link and some xml tags and before and end of file's path !

5 hours ago, requinix said:

I was unnecessarily harsh on you for it.

No problem :D every bit knowledge is important.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.