Configuration of laravel under apache to avoid public - php

I recently installed laravel under a LAMP server, but can't get it to work if I don't specify public in the url for another routes than the index.php.
This is my apache site config (/etc/apache2/sites-available/furbook.com.conf):
<VirtualHost *:80>
ServerName furbook.calhost.com
DocumentRoot "/var/www/html/furbook.com/public"
<Directory "/var/www/html/furbook.com/public">
AllowOverride all
</Directory>
</VirtualHost>
Then created a symbolic link from /etc/apache2/sites-enabled:
sudo ln -s ../sites-available/furbook.com.conf
Finally, this is my .htaccess file in furbook/public:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
With this now I'm able to skip the public folder, localhost/furbook.com works redirecting to the public/index.php as expected.
But the problem is when I try to route an url like localhost/furbook.com/cats, then it throws a page not found error.
If I use localhost/furbook.com/public/catsthen works as expected.
What am I missing?

There's not quite enough information to answer you question 100% authoritatively -- here's my best guess.
If I use localhost/furbook.com/public/catsthen works as expected
Apache allows you to setup multiple "VirtualHost" configurations on a single server. A "VirtualHost" is a domain name like furbook.calhost.com that points to a specific folder on your computer. It's called Virtual because, at the time Apache was created, there was a strong bias towards "one host name/one physical server"
<VirtualHost *:80>
ServerName furbook.calhost.com
DocumentRoot "/var/www/html/furbook.com/public"
<Directory "/var/www/html/furbook.com/public">
AllowOverride all
</Directory>
</VirtualHost>
You have setup a virtual host for the name furbook.calhost.com
ServerName furbook.calhost.com
However, in your URL, you're still accessing the system via the name localhost. Accessing via localhost means apache will use the default host/site configuration, which (appears to) still be pointing at the folder above root.
Your options
Setup local DNS or a host file to have furbook.calhost.com point to 127.0.0.1
Change the default configuration of your apache system (probably in httpd.conf) to point to the public folder
Good luck!
(Also, don't forget Apache systems typically require a reset to pickup new configuration changes)

Related

Problems with friendly routes PHP

I did a basic project of an API using pure PHP, I used .htaccess to make everything written after my endreço, was assigned to the $path. I used a xampp through Windows 11 and changed the apache settings so that the rendered folder was that of my application
C:\xampp\htdocs\API
and everything worked perfectly, then transferred the files from my repository to my ubuntu machine on an EC2 AWS instance and changed the apache server settings so that the rendered folder was also changed, I used the following command:
sudo nano /etc/apache2/sites-available/your_domain.conf
and i set it up as follows:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName your_domain
ServerAlias www.your_domain
DocumentRoot /var/www/your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
when accessing my localhost, in windows, my application works normally (I will attach some images), but in my instance, it shows a Not Found error
here's my .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?path=$1 [QSA,L]
my code
working on windows
index.php working on ubuntu
error in ubuntu :/
I believe the problem is in the apache settings in ubuntu but do not know how to solve, help!

Apache virtual host always redirecting to /dashboard

I'm having what appears to be a common problem but any solutions I've found don't seem to work for my case.
I'm trying to set up a virtual host so that I can access the public file of my Laravel installation by going to "mytestdomain.local" but when I type this address into google chrome I am always redirected to the xampp dashboard at this address "https://mytestdomain.local/dashboard/".
I've installed Laravel in the following xampp directory: c:/xampp/htdocs/mytestdomain_uk.
I have "C:\xampp\apache\conf\extra\httpd-vhosts.conf" set up as follows:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/mytestdomain_uk/public"
ServerName mytestdomain.local
</VirtualHost>
And I have "C:\Windows\System32\drivers\etc\hosts" set up as follows:
127.0.0.1 localhost
127.0.0.1 mytestdomain.local
If anyone could offer any insight into this issue I would be very grateful.
Put this as the first line in C:\...\httpd-vhosts.conf (and restart the web server):
NameVirtualHost *:80
So, it should look like this:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>
<VirtualHost *:80>
ServerName walkpeakdistrict.local
DocumentRoot "C:/xampp/htdocs/walkpeakdistrict_uk/public"
</VirtualHost>
I would place all my projects somewhere outside of C:/xampp/htdocs and C:/xampp. Let C:/xampp/htdocs be the standard localhost location, with just two files inside (simple index.php and index.html), but use another one for the projects. Even better, use another partition, not the system partition C:. Like D:/projects, or so. So, you would have D:/projects/walkpeakdistrict_uk.
Good luck.
Ok, I'm not sure why this was an issue but it seems to work when I change the virtual host's server name to anything other than ".local".
Thanks again to all who replied!
This happened with me as well. And I resolved it. In my case, it was happening because of the SSL module. So, turning it off got me out of the trouble. Just Open the httpd.conf file and comment the SSL include code by adding # to the front of the code as given below.
# Secure (SSL/TLS) connections
# Include conf/extra/httpd-ssl.conf
After this, it will be resolved.
I'm pretty sure the issue for me had to do with SSL redirects, for some reason. When I edited my .htaccess to exclude local.mydomain.com when forcing https, I stopped getting redirected to the XAMPP dashboard.
Below is the section of my .htaccess that excludes local sites from redirecting to https. You can add extra RewriteCond lines for other local domains.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTP_HOST} !local\.
RewriteCond %{HTTP_HOST} !other.localdomain.example.com
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
</IfModule>
<IfModule mod_headers.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !local\.
RewriteCond %{HTTP_HOST} !other.localdomain.example.com
Header set Strict-Transport-Security "max-age=16070400" env=HTTPS
</IfModule>
Change your document root to this, just add a slash at the end of public and it will work
DocumentRoot "C:/xampp/htdocs/walkpeakdistrict_uk/public/"
I had this problem after developing my website and I got round it by simply rebooting my machine. Many months later, Google then invalidated the use of .dev so my virtual host stopped working. I changed the name of my virtual host to .test and got the dashboard. I had forgotten the simple solution and arrived on this page searching for a solution. Then i remembered......I rebooted my machine and hey presto....it worked. No more dashboard. I get the right homepage.
In your case, you put localhost settings in virtual host. check if you got this script on default file conf, then comment it. Case on xampp for mac
Include "${your_xampp_path}/conf/httpd.conf"
The solution is very simple, it always redirects the https url to the Dasboard, you just have to remove the s leaving http:
Example:
http://juego123.com
I was facing the same error. I solved the error by removing the *80 port number from the virtual host tag and then my code look like
<VirtualHost *>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>
<VirtualHost *>
ServerName walkpeakdistrict.local
DocumentRoot "C:/xampp/htdocs/walkpeakdistrict_uk/public"
</VirtualHost>
**NOTE:**Your Virtual Host tag looks like this <VirtualHost *>
This means we are redirecting to any other port or not bounding the virtual host to port 80 this will work definitely.
I came here with the same problem, in my case accessing the website through http instead https worked.
In browser, instead of accessing this way:
https://mytestdomain.loc
try this one
http://mytestdomain.loc
Its works for me once I remove header location from 'htdocs/index.php' file

How Symfony routing works

I am a beginner for Symfony and following the Symfony documentation and it has a create page tutorial
and after creating this this when I test this using the browser,
I can access it using the following URLs
localhost:8000/lucky/number and
localhost:8000/app_dev.php/lucky/number
but when I try to access it using the usual way like
localhost/appname/lucky/number
it gives 404 and I use Ubuntu with Apache2 localhost so I need to know the idea behind this Symfony3 routing and why I cannot access the page using usual localhost/cmstest/lucky/number
Thanks
Following the Symfony doc, this is how your vhost should looks like:
<VirtualHost *:80>
DocumentRoot /var/www/MySymfonyProject/web
<Directory /var/www/MySymfonyProject/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
<Directory /var/www/MySymfonyProject/web/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
ErrorLog /var/log/apache2/MySymfonyProject_error.log
CustomLog /var/log/apache2/MySymfonyProject_access.log combined
</VirtualHost>
Now that you have a clean vhost, here are some details/instructions:
All terminal commands are done as admin (sudo).
In terminal, run this command a2enmod rewrite
In terminal, as you don't use any URL, make sure to disable the default vhost a2dissite 000-default.conf
In terminal, make sure to enable your site vhost a2ensite myVhost.conf
Make sure your project directory is right /var/www/MySymfonyProject
In terminal, restart apache service with service apache2 restart
Access your site through localhost or localhost/app_dev.php (you don't have to specify the bundle name)
Because you have to use the web/ directory (which is the public root of your application, only this directory should be accessible using the browser).
When using server:run, it'll use web/ as your server root automatically. When accessing via the directory structure, include it in the URL: http://localhost/appname/web/lucky/number
Hewwo PM-Riabel~
Can you paste here your virtual-host config?
Your first problem may be in it...
Do you have only one virtual-host active on your machine?
I would guess you try to view it from Linux (correct me if it's not the case)
You should set a fictive URL to your hosts file (myurl.com) and redirect it to 127.0.0.1 (localhost)
Then you can configure your virtual-host to work with this same URL. (Better do it when you want to work multiple projects)
Cordially,
Preciel.

Laravel 4 Virtual Host and mod rewrite setup

I've been trying for a few hours to install Laravel 4 and make the Virtual Hosts and Routing work but so far I've been unlucky. I'm mentioning that I'm doing this on a Windows 7 machine and WAMP.
I'll describe what I've already done:
I've enabled rewrite_module.
Updated httpd-vhosts.conf with the following:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
</VirtualHost>
Next, I've set up the etc/hosts:
127.0.0.1 localhost
127.0.0.1 laravel.dev
Also, the following lines are uncommented both in wamp/../conf/httpd.conf and in wamp/.../conf/original/httpd.conf:
LoadModule vhost_alias_module modules/mod_vhost_alias.so
Include conf/extra/httpd-vhosts.conf
The content of my .htaccess is the following:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Yet, when I go to http://laravel.dev I get an Internal Server Error - The server encountered an internal error or misconfiguration and was unable to complete your request..
If i remove the .htaccess file from the public folder, then I'll see the Laravel "You have arrived" message. If then, i create a route like this (within the app\routes.php):
Route::get('/newroute', function()
{
return View::make('hello');
});
and then go to http://laravel.dev/newroute I'll end up with a 404 Not Found - The requested URL /newroute was not found on this server.
I am seriously confused and have no idea how I can get past this. I mention (although i think it's clear) that I ran a composer install after cloning the project template, installing the dependencies.
If the htaccess file that you posted was in your /public/ folder, then that's why you're getting a 500 internal server error. That htaccess file was made for the folder that the /public/ folder is in. But since your public folder is the document root, you don't need it.
The htaccess file in the /public/ folder should look like this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
(for WAMP).
Try turning on AllowOverride All on the directory by changing your VirtualHost to:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
<Directory "c:/wamp/www/laravel/public">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I have gone through the same issue and followed the all the treatments given above but virtual host can not be set.
When I inspected file http.conf then I found that inclusion of file httpd-vhosts.conf was commented as given below. Make sure to include httpd-vhosts.conf in httpd.conf.
#Include conf/extra/httpd-vhosts.conf
I have removed the # comment. Restarted the wamp and it was working.
Include conf/extra/httpd-vhosts.conf

Wildcard Subdomain Exceptions

I have a wildcard subdomain enabled and dynamically parse the URL by passing it as-is to my index.php (ex. somecity.domain.com).
Now, I wish to create a few subdomains that are static where I can install different application and not co-mingle with my current one (ex. blog.domain.com).
My .htaccess currently reads:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Can I manipulate this .htaccess to achieve what I need? Can it be done through Apache?
Your .htaccess does nothing useful, as Apache is probably configured with DirectoryIndex index.php. Well, it does move domain.com/a to domain.com/index.php, but I doubt that is what you want.
Your wildcard virtualhost works because you probably have ServerAlias *.domain.com in your configuration, or a single virtualhost and DNS pointing to the address of your server. (When you have a single virtualhost, it shows up for any request, and the first listed virtualhost is the default one)
You have to create new VirtualHosts for the static domains, leaving the default one as, well, the default one :)
Check these tutorials that explain it all.
You'll have to configure apache for those static sub-domains. The "catch-all" site will be the default site configured, so that one will catch the other ones.
I'm not sure I understand completely what you need to accomplish, but it might helpful to setup virtual domains within your Apache configuration file. You can map them to folders on the drive with different applications installed. Each virtual domain is treated much like a root directory. I have my development environment setup locally on my Windows machine a lot like this:
NameVirtualHost *:80
# Begin virtual host directives.
<VirtualHost *:80>
# myblog.com virtual host.
ServerAdmin webmaster#myblog.com
DocumentRoot "c:/apache_www/myblog.com/www"
ServerName myblog.com
ServerAlias *.myblog.com
ErrorLog "c:/apache_www/myblog.com/logs/log"
ScriptAlias /cgi-bin/ "c:/apache_www/myblog.com/cgi-bin/"
<Directory "c:/apache_www/myblog.com/www">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
If this does not help get you on the right track, then try researching the VirtualHost directive to come up with a solution. I find trying to do all this in an .htaccess to be cumbersome and difficult to manage.
I don't know if you have cPanel installed on your host, but I was able to do this by adding a new subdomain * and then sending all that traffic to a particular subdomain, for example: *.domain.com -> master.domain.com. Then you can read out which URL you are at in master.domain.com and go from there.

Categories