1

I'm attempting to setup a server configuration where React is the frontend and Laravel is the API, but I'm unsure of how to setup Apache2 so that mydomain.com/api will serve Laravel and everything else will serve React

I tried setting up a separate site config file for Laravel at mydomain.com/api being routed to the Laravel public folder but it doesn't work

Any advice is appreciated

Thanks

  • Zach

1 Answer 1

5

I had this before and fixed it as below.

I did not create a new configuration file for the second site, just included it as Alias as below.

in your 000-default.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName example.com
    ServerAlias www.example.com
    Alias /api/ /var/www/html/api
    DocumentRoot /var/www/html


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Alias defines your new site or application.

When you are setting up the Alias, if "/api/" does not work, try /api. either one of them should work.

And make sure, you set your document root configurations in the /etc/apache2/apache2.conf

Sign up to request clarification or add additional context in comments.

2 Comments

This worked! Thank you so much! Couldn't find it ANYWHERE online
Thanks, it works, it worked for me using this form "/api" BTW

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.