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
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 root#example.com
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
Related
I'm trying to serve a Laravel 7 site on my server, built using a Raspberry Pi and storing the files on an external hard drive.
I cloned my Laravel project from Github, ran composer install and after a bit of fiddling and configuration, the root page loaded. However, the root page is the only route that will load. Neither my own routes nor the auth routes generated by Laravel work. Any attempt to access a different route leads to a 404 error thrown by Apache on my server.
Here is my VirtualHost config file in Apache:
<VirtualHost *:80>
ServerName myurl.tld
ServerAdmin myemail#example.com
DocumentRoot /mnt/external/public_html/MyProject/public
<Directory /mnt/external/public_html/MyProject>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Not sure what is going on here. The same thing happens with projects generated on the server as well as the cloned project.
Permissions on /mnt/external/public_html/MyProject are set to 775 all the way up to external, and the whole path is owned by the www-data user.
Try the below VirtualHost config
<VirtualHost *:80>
ServerName myurl.tld
ServerAdmin myemail#example.com
DocumentRoot /mnt/external/public_html/MyProject/public
<Directory /mnt/external/public_html/MyProject/public>
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Restart Apache.
Situation:
I have a website that iam working on, in my local machine
Server apache, php language.
In local i can access to the page by typing
http://localhost/(mysite)/public/index.php
Problem:
In the Hosting webserver, i want to access by
simply typing http://www.(mysite).com/index.php
Note: My website is based on mvc (Model view controller) architecture.
Question:
What is the appropriate way to « root » my website on the
« public » directory in my apache server.
Should i point the hosting web server document root to The « public/« directory ?
Thanks
On linux go edit /etc/apache2/sites-available/000-default.conf or mysite.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And append /public to whatever path you have as DocumentRoot
I have a Symfony project with the file index.php in /var/www/public.
I want to only allow access to the website using a virtual generate folder, so the site should always be accessed like this: http://localhost/generate.
http://localhost/ should just throw a 404.
I'm using the following Apache config, but the $_POST and $_GET globals are missing when I debug my script (I'm firing a POST request from Postman). It works when I reset my Apache config to just serve from the root without any alias..what is going on?
I'm not using any .htaccess files in my /var/www/public folder.
The Apache config:
<VirtualHost _default_:80>
ServerAdmin webmaster#localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<FilesMatch ".+(\.php)$">
SetHandler "proxy:fcgi://127.0.0.1:9100/
</FilesMatch>
DocumentRoot "/var/www/public"
Alias /generate /var/www/public
<Location /generate>
AllowOverride All
</Location>
</VirtualHost>
Since you are using Symfony, you can simply define routes for /generate and nothing for /
routes.yaml
Generate:
path: /generate
controller: ControllerNamespaceAndName::MethodName
Because you don't use route definition for / when accessing http://localhost/, symfony's kernel will throw a 404
I am new to VPS hosting.... and giving a try to digital ocean Linux VPS. I need to point 2 domains to my PHP app.
This is how my Virtual Host looks like inside /etc/apache2/sites-available
<VirtualHost *:80>
ServerAdmin root#domain1.com
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot /var/www/html
<Directory /var/www/html>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
However... I am not able to load my styling and access any files or directories that is in var/www/html directory. How can I enable the permissions for my domains to access these resources.
Similarly my second Virtual host for another domain
DocumentRoot /var/www/html/app/login.php
Everything seems working while I am accessing the site using the IP...However... after setting up virtual host... the content is loading but can not access css and js... in the current root directory.
I am not sure what I need to do to set up my domains as expected.
I am using ../ notation to point my previous directory. There is no error with the site that is showing...just not loading CSS. Also I have the APIs in the root directory.... inside API folder.... that is not accessible while I am pointing them ../../API/v1/create_user.php
I'm using WAMPSERVER to run a wordpress site that has to be acessible by the users in my network, like a environment for testing together.
Localhost works fine, but at first i couldn't access the aplication from other computers in the network. I created a rule to open the port 80, created an Alias in the Apache configuration, and it worked but the theme and any images inside subfolders wouldn't load and the console was returning lots of 404 responses.
I want to map the subfolders and its files that are under the 'base dir' of the site. I tried tons of options in the Apache conf. file but i couldn't make it.
Attached a printscreen of the responses, the apache conf file and the windows hosts file
Httpd.conf :
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "c:/wamp/www"
ServerName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#animamidia
DocumentRoot "C:\wamp\www\website"
ServerName www.animamidia
ErrorLog "logs/animamidia-error.log"
CustomLog "logs/animamidia-access.log" common
<Directory "C:\wamp\www\website\*">
Options FollowSymLinks Includes
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
Windows hosts file:
127.0.0.1 www.animamidia
The site with it's theme broken because the requisition returned a 404
Well i found the problem.
Even though i couldn't enter the wordpress-admin i decided to check the 'wp-config.php' file just in case something is wrong or missing.
And what i did find is that the 'Home-URL' and the 'WP-URL' were set at 'localhost/website' which means that all the requisitions would point at this location as a base directory.
All i had to do was to use the 'define' comand and set the site's URL to the machine's IP and now the environment is all set up for the guys over here to develop and test their stuff.