Integrating Angular frontend with PHP backend: Best practices?

Hey everyone,

I’m working on a project where I’m using Angular for the frontend and PHP for the backend. I’ve got them on separate domains right now. The PHP part is done and working, and I’ve set up some APIs.

I’m not sure about the best way to connect these two. Should I just copy the PHP files into my Angular src folder? Or is it better to keep them separate and make API calls between domains?

I’ve looked at some tutorials, but I’m still confused. What’s the most common approach for this setup? Any tips or suggestions would be super helpful!

Thanks in advance for your advice!

yo dude, keeping em separate is the way to go. don’t mix ur angular and php files, that’s a recipe for chaos. just use angular’s http stuff to talk to ur php api. make sure u set up CORS right tho, or you’ll be pulling ur hair out. trust me, been there done that lol

hey there! i’m curious, have you thought about using a reverse proxy? it could neatly bridge angular with php without CORS hassles. what kind of data do you send? maybe we can come up with neat ways to improve security and performance. what’s been your biggest challenge so far?

Keeping your Angular frontend and PHP backend separate is generally considered best practice. This separation of concerns allows for better scalability and maintainability. Instead of copying PHP files into your Angular src folder, you should maintain them on different servers or domains.

To connect them, use Angular’s HttpClient to make API calls to your PHP backend. Ensure your PHP server is configured to handle CORS (Cross-Origin Resource Sharing) to allow requests from your Angular domain. This approach gives you flexibility to evolve each part independently and even switch technologies in the future if needed.

For security, implement proper authentication mechanisms like JWT tokens. Also, consider using environment files in Angular to manage API endpoints across different environments (development, staging, production). This setup will serve you well as your project grows in complexity.