I'm new to both PHP and developing on Mac OS X.
I have the following code on the front-end (browser on my laptop):
$('form').on('submit', function(e) {
$.post( 'save.php', $(this).serialize(), function(response) {
console.log( response );
});
e.preventDefault();
});
And this simple PHP code on the back-end (Apache server on my laptop):
<?php
$f = $_POST['content']); //content is coming from a form textarea
echo $f;
I expect whatever I submit to be echo'd on the console (by PHP). What happens instead is that I get the entire PHP code in the console. My rudimentary understanding is that the server is not executing the PHP code and is instead returning it as plain-text.
I've searched around for three hours and did the following:
- (Re)installed MAMP.
- Made sure Apache server is actually running
- Made sure I access the site via Apache as opposed to opening it as a file in the browser. I'm doing /localhost/~username/index.html
Checked to see if httpd.conf contains this line and it does:
LoadModule php5_module modules/libphp5.so
Added this to httpd.conf and restarted Apache server:
AddType application/x-httpd-php .php
I then started reading the PHP documentation and found this, which describes the problem I have and the solution. The issue is that, unlike with libphp5.so, I don't actually have a mod_php.so or a lib_perl.so file under the modules folder. I also searched for them on Spotlight and it didn't return anything.
So... what else do I need to do/check? Thank you in advance.