Run PHP and Nodejs app together in a cPanel account
I have installed Nodejs on my cPanel Cloudlinux server.
I created a Nodejs app [COLOR=rgb(41, 105, 176)](Nuxt.js) for my website frotend via [COLOR=rgb(41, 105, 176)]"Software > Setup Node.js App" in my cPanel account and linked it to my website root [COLOR=rgb(41, 105, 176)](example.com/)[COLOR=rgb(0, 0, 0)].
Now I want to create an API PHP service [COLOR=rgb(41, 105, 176)](Laravel) for my website backend and place it in my [COLOR=rgb(41, 105, 176)]"example.com/api" directory which it returns JSON from this address.
But when I visit this url, it returns my Nodejs app page which I created before for website root.
In fact, I want the [COLOR=rgb(41, 105, 176)]"publci_html/api" folder to be exclude from rendering via Nodejs server.
Is it possible?
Or should I commit some changes in [COLOR=rgb(41, 105, 176)]".htaccess" file?
Regards
-
Hello @Gamecock, Thank you for contacting cPanel! Did you set up your Node.js application following the instructions on the following page? The Application Manager uses Phusion Passenger to reverse proxy requests to your site on port 80 to the port the application is listening on. For this reason, it would likely be simpler to install your Node.js app to a subdirectory or a standalone domain. To modify the VirtualHost entry for your domain as described in the StackOverflow thread above, you would need to use an Include file. We have instructions in our documentation for how to accomplish that: 0 -
To modify the VirtualHost entry for your domain as described in the StackOverflow thread above, you would need to use an Include file. We have instructions in our documentation for how to accomplish that:
I created a subdomain called api. Assume that our cPanel username is username. I created includename.conf file in /etc/apache2/conf.d/userdata/std/2_4/username/api.example.com pasted this code there: [CODE=apacheconf] PassengerEnabled off AllowOverride all
and saved changes and restart apache with /usr/local/cpanel/scripts/rebuildhttpdconf and /usr/local/cpanel/scripts/restartsrv_httpd commands. But nothing happened and the api.example.com url still shows the NodeJS pp content which is defined for example.com/ I also edited the codes like this includename.conf file: [CODE=apacheconf] PassengerEnabled off
But again no changes appeared after save and restart. I also tried to writePassengerEnabled off
statement in .htaccess file which is placed in /home/username/public_html/api but no success. Note that I use Litespeed webserver, not Apache. Does it require different configurations? Thanks0 -
Hello again @Gamecock, Thank you for your detailed reply. I found that the same answer from the StackOverflow page I shared with you is actually found in the Passenger documentation as well: PassengerEnabled off AllowOverride all DirectoryIndex index.php
Note, in theLocation
section I used a relative path. Additionally, I added aDirectoryIndex
directive, but this was not necessary. There are no special steps that need to be taken for compatibility with Litespeed. Please let us know if you have any additional questions. Best regards0
Please sign in to leave a comment.
Comments
3 comments