I’ve developed a SvelteKit frontend and a PHP backend which includes an API and database connection files. However, I’m struggling to get Apache to serve both segments of my application concurrently.
When I access mydomain.com/api/users.php, I receive database connection errors, and my PHP code displays as plain text rather than being executed. Interestingly, when I go to the same file with my server’s IP directly, it functions correctly.
The odd part is that my domain won’t run PHP files properly, while my IP fails to show the frontend—just the standard Apache landing page.
I’ve been adjusting my virtual host configuration for several days without success. Here’s how it’s currently set up:
<VirtualHost *:443>
ServerName example.com
DocumentRoot /var/www/html
# Process API requests
Alias /api/ /var/www/html/api/
<Directory "/var/www/html/api">
AllowOverride All
Require all granted
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
</Directory>
# Forward frontend to SvelteKit side
ProxyPass /api/ !
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
My directory structure appears as follows:
html/
├── sveltekit-app/
├── api/
│ ├── users.php
│ └── database.php
├── src/
│ └── routes/
└── package.json
I utilize pm2 to manage my SvelteKit application running on port 3000. The database access works without issues via IP, yet fails with the domain. Can anyone suggest what might be creating this problem?