Run PHP code on macOS local Jekyll site, port 4000

I created a Jekyll site on my localhost (MacOS Mavericks). The website is served by http: // localhost: 4000 / website / and everything about Jekyll works fine.

However, I now want to have a contact form in PHP that allows me to receive emails. I put the contact.php file in a folder / folder and got a POST form for that file. On my remote web server, this works fine. However on localhost PHP is not parsed and plain text is displayed on contact.php. However PHP parses just fine at localhost / contact.php.

How do I get my localhost (Apache? PHP?) To process PHP files on my local Mac http: // localhost: 4000 / (without breaking my Jekyll website, which is listening on the same: port 4000)?

+3


source to share


2 answers


You cannot use the same port. The port defines the application endpoint that will process the request by IP address. Jekyll server (WEBrick library) uses port 4000 by default.

A typical solution to this problem is to use a "web service" to add dynamic functionality. For example, the jekyll docs suggest using something like FormKeep or SimpleForm .



What you are asking is to set up a "web service" yourself. To do this, he will need to be on a different port or a different IP address. The "Service" will simply act as an endpoint for receiving and processing your form message. In this case, you can set up a web server using Apache / PHP on a different port than Jekyll, for example standard port 80, and then write a PHP script (for example webform.php) that is combined with a static configuration form to respond and process your form.

Note. ... You can configure both Jekyll and Apache to respond to requests on port 4000. However, both applications (for example, servers) cannot run at the same time. The ip: port combination determines which application the Internet request is sent to.

+5


source


I understand the post is out of date, but this might help someone ...

Mike Stewart's answer is excellent and describes what needs to be done to achieve the goal.

To add to this answer, consider the specifics of how I do this type of development on Mac.



  • Configuring CORS in Apache
  • Run the Jekyll site on the default port 4000
  • Running MAMP stack on default port 8888
  • The code is sent to the MAMP htdocs folder (htdocs / your_project)
  • PHP is located in the "php" folder or another folder inside the "your_project" folder
  • Jekyll looks in the "your_project" folder and compiles to _site as usual.

The CORS problems you run into can be resolved locally during development in several ways. Here is a good resource for enabling CORS on Apache: http://enable-cors.org/server_apache.html

Once CORS is configured, you should be able to make PHP Ajax calls on port 8888.

0


source







All Articles