ajax php example not working on local web server mac - ajax

I am trying to learn ajax on my mac apache server using the example code in http://www.w3schools.com/php/php_ajax_php.asp . But it is not working on my local server as desired( I am using CODA 2 in mac 10.8). I have no idea what is going wrong. Can someone help me with this.

It may be a port issue. I run MAMP (which I just switched to from WAMPP, and I love it). By default it runs Apache via port 8888 and MYSQL via port 8889. I had to switch this to ports 80 and 3306, respectively, to get everything working properly.
But if you can run any more basic php calls, I'd rule out this suggestion.

Related

Localhost refused to connect on WSL2 when accessed via https://localhost:8000/ but works when using internal WSL IP adress

What I'm Trying to Achieve
To access localhost from my local machine during the development of a Symfony web app.
My Environment
WSL2 running on Windows 10
Linux, Apache2, MySQL, PHP-7.4 stack (with Xdebug3 intalled)
Debian 10
Symfony 5.4 (although not sure on if relevant to this problem)
Steps I've Taken
Set up WSL2 according to this Microsoft WSL2 tutorial
Set up LAMP stack according to this Digital Ocean tutorial
Set up Symfony according to this Symfony tutorial
Run the following bash script on startup to start my services and set the host to the virtual WSL IP in my xdebug.ini file
#!/bin/sh
REMOTEIP=`cat /etc/resolv.conf | grep nameserver | sed 's/nameserver\s//'`
sed -i -E "s/client_host=[0-9\.]+/client_host=$REMOTEIP/g" /etc/php/7.4/mods-available/xdebug.ini
service php7.4-fpm start
service apache2 start
service mysql start
Run my Symfony project on the development server using symfony serve -d (Symfony then tells me "The Web server is using PHP FPM 7.4.23 https://127.0.0.1:8000")
Go to https://localhost:8000/ in Chrome where the app is running
What I Expect to Happen
My Symfony web app to be running on https://localhost:8000/ when I visit the URL in my Chrome browser
What Actually Happens
I get "This site can't be reached localhost refused to connect." in the Chrome browser
What I've Tried
This used to happen less frequently and I would give my laptop a restart, repeat the process above, and I could connect via https://localhost:8000/. However, it refuses to connect more regularly now (like 8/10 times I start up for the day)
Connecting to https://127.0.0.1:8000 yields the same result.
Connecting to the site using the internal WSL IP address, found using hostname -I and replacing localhost with this IP (still on port 8000). This is an adequate workaround to use my app, however I am unable to interact with my database via MySQL Workbench without having to set up a new connection, therefore a fix where I can use localhost would be very helpful!
(Based off comments) Only ran symfony serve -d without starting apache and PHP services separately - still sometimes allows connections to localhost but sometimes doesn't work.
Conclusion
The behaviour is odd as it works sometimes but other times it doesn't when the exact same steps are carried out. I am unsure where else to look for answers and I can't seem to find anything online with this same problem. Please let me know if any config files, etc would be helpful. Thank you so much for your help! :)
When it's working normally, as you are clearly aware, the "localhost forwarding" feature of WSL2 means that you can access services running inside WSL2 using the "localhost" address of the Windows host.
Sometimes, however, that feature breaks down. This is known to happen when you either:
Hibernate
Have the Windows "Fast Startup" feature enabled (and it is the default). Fast Startup is a pseudo-hibernation which triggers the same problem.
Typically the best solution is to disable Hibernation and Fast Startup. However, if you do need these features, you can reset the WSL localhost feature by:
Exiting any WSL instances
Issuing wsl --shutdown
Restarting your instance
It's my experience that localhost forwarding will work after that. However, if it doesn't, thanks to #lwohlhart in the comments for mentioning that another thing to try is disabling IPv6 on WSL2, since (I believe) there's a possibility that the application is listening on IPv6 while the Windows->WSL2 connection localhost connection is being attempted on IPv6.
You can disable IPv6 on WSL2 per this Github comment by creating or editing .wslconfig in your Windows user profile directory with the following:
[wsl2]
kernelCommandLine=ipv6.disable=1
A wsl --shutdown and restart will be necessary to complete the changes.
If you find that this works, it may be possible to solve the issue by making sure to either use the IPv4 (127.0.0.1) or IPv6 (::1) address specifically in place of localhost on the Windows side, or by configuring the service to listen on both addresses.
Try to run command netstat -nltp. It shows active addresses and ports. Your nginx process should be run at 0.0.0.0:8000. 0.0.0.0 means the nginx process is available from anywhere.
If your nginx process is ran by any specific ip address, you should access it by that ip address, e.g http://192.168.4.2:8000.

xampp is not working and i try almost every thing

i downloaded MySQL workbench and the port is 3306 then i runs the x.a.m.p.p and the port is 3306 also i change the x.a.m.p.p port to 3307 and still not working
is their any solution to this
First we need to make sure that you installed XAMPP in proper way. Follow this video about how to prepare PHP environment using XAMPP.
If you followed the steps correctly make sure that both MySQL and Apache servers are running.
Then in XAMPP control panel click on MYSQL Admin. It will open phpMyAdmin and it will show a successful connection to MySQL server. If you noticed any error this means you have problem in your MySQL server.
Also it will be a good help to tell us from there your server type and version and your MySQL workbench version.

XAMPP on MacOS - use localhost instead of IP address

I am trying to switch web development from Windows to Mac but I have encountered a problem which would need me to alter a lot of existing code.
I am running Apache and MySQL using XAMPP.
Basically, I want to access a PHP Rest API which I have created on a Windows system where I can access it like this:
http://localhost/api/read.php
However, on Mac I have to access it like this (with XXX.XXX.XX.X being my local IP address) which works perfectly fine:
http://XXX.XXX.XX.X/api/read.php
But when I try to access localhost (the same way as I did on Windows) I get an error:
Safari cannot establish a connection to the server.
Safari cannot open the site "localhost", because Safari cannot establish a connection to the server.
Is there a way to "enable" access via localhost on Mac without using the IP address?
Thank you in advance!
You may be installed the application that sets up a virtual machine.
Go to download page again.
here: https://www.apachefriends.org/download.html
Now select "7.3.0 / PHP 7.3.0" or latest version according to your visit time without 'VM'.
Remember don't select "XAMPP-VM / PHP 7.3.0" or latest version with 'VM'

How do I set up my computer to serve website using web2py?

I've got web2py working so I can access my webapp from my computer locally. I also have tornado working and listening on port 8080 as I want to use websockets.
I've chosen the "Public (0.0.0.0)" option when firing up the server and listening on port 8000.
I've set up port forwarding on my router from port 80 to port 8000 using the "other" function of the guide p.58.
When typing "what is my ip" it seems to be an IPv6 IP so no idea if that matters but I tried to check if I've done it correctly by going to this site http://www.ipv6proxy.net/index.php and trying to navigate to my IP address that google spit out when I typed "what is my ip?" but get a couldn't connect to the host message.
Any idea what I'm doing wrong?
I'm relatively new to this.
To explain motivation I simply want to do a dry run of the website and websockets online. I think there are a tonne of security risks associated with what I'm doing and this is simply a learning exercise for me and do not intend to host the website this way. I do want to understand how I would do this though.
EDIT
I'm running ubuntu 14.04 LTS

Not able to access Neo4j server on CentOS VM on Mac

I have a Mac running a CentOS VM. I successfully installed Neo4j and was able to start the server ([API] Remote interface ready and available at [http://0.0.0.0:5000/]).
I also uncommented the line org.neo4j.server.webserver.address=0.0.0.0 in the neo4j-server.properties file. I changed the webserver port from 7474 to 5000 (org.neo4j.server.webserver.port=5000) since I know for sure that the port works - as I run Flask web-apps on CentOS and view the UI on Mac by putting http://<vm-ip-address>:5000/on Chrome (I made sure the Flask process is stopped and no one is using that port). But this is not working for the Neo4j local server as I keep getting This webpage is not available for both 7474 and 5000. Am I missing something ?

Resources