Laravel Name resolution issue - php

I am new to laravel and trying to learn laravel but I am stuck while
entering a server name in httpd-vhosts.conf I entered this in httpd-vhost.contf:
<VirtualHost *:80>
DocumentRoot "D:/Xampp/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/Xampp/htdocs/lsapp/public"
ServerName lsapp.dev
</VirtualHost>
and in system32 host file :
127.0.0.1 localhost
127.0.0.1 lsapp.dev
See the error in homepage

Use run this command, in project root
php artisan serve --host=lsapp.dev --port=80
Be sure to stop mysql from xampp , which uses port 80,
Above command require to set 127.0.0.1 lsapp.dev in your host file, as you did already
If you want to go without command set DocumentRoot in httpd-vhost.contf as you did already
"D:/Xampp/htdocs/lsapp/public"
ServerName lsapp.dev
And in host file
127.0.0.1 lsapp.dev
And restart apache, stop and then start apache to reflect, and hit lsapp.dev browser

<VirtualHost lsapp.dev:80>
DocumentRoot "D:/Xampp/htdocs/lsapp/public"
ServerAdmin laravel.dev
<Directory "D:/Xampp/htdocs/lsapp/">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
and don't forget the .htaccess file in public folder
Apache (from laravel docu...)
The framework ships with a public/.htaccess file that is used to allow URLs without index.php. If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.
If the .htaccess file that ships with Laravel does not work with your Apache installation, try this one:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
If your web host doesn't allow the FollowSymlinks option, try replacing it with Options +SymLinksIfOwnerMatch.

Related

XAMPP Access Forbidden

I have just downloaded the latest version of XAMPP with PHP version 7.2.4. I have made a very simple PHP validation for a HTML form and when I press submit it comes up with the following:
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
localhost
Apache/2.4.33 (Win32) OpenSSL/1.1.0g PHP/7.2.4
I'd don't know what the problem is as I have tried changing Require none to Require all granted.
Please Help!
I have experienced this problem and found out that localhost link is not configured in
httpd_vhosts.conf.
So I added this line at the bottom part of httpd_vhosts.conf
<VirtualHost *:80>
DocumentRoot "E:/xampp/htdocs"
ServerName localhost
</VirtualHost>
Well, probably this must be happening because the localhost link is not configured in your xamp vhost, try to look for the vhosts configuration file and add the same one there. Just add this block of code making the appropriate path changes until your repository so that you can access the localhost:
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#hcode.com.br
DocumentRoot "C:\ecommerce"
ServerName www.hcodecommerce.com.br
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
<Directory "C:\ecommerce">
Require all granted
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</Directory>
</VirtualHost>
By default in httpd.conf your entire system directory "/" is secured and not allowed access
in httpd.conf:
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
AllowOverride none
Require all denied
</Directory>
Add the below additional under the above
<Directory /home>
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
Change /home to your hosted installation public directory - e.g. /projects or /devsite.local etc...
For more info on Apache see here: https://httpd.apache.org/docs/current/mod/core.html#directory
The 'Options' are typical .htaccess directives - change as needed
The 'AllowOverride All' gives access to the /home folder and everything under it
The 'Require local' makes sure only localhost / 127.0.0.1 has access to folder and files under /home
Hope this helps :D

Apache is not redirecting to index.php in Arch Linux

I am trying to configure a Wordpress project on my localhost, but when I open the browser on localhost I only see the files in the root of my wordpress project.
If I click on index.php or access localhost/index.php it executes the PHP as expected.
I have installed apache 2.4, php 7.2 and php-apache 7.2.
My project is in /srv/http/mysite:
The relevant lines in /etc/httpd/conf/httpd.conf file:
LoadModule rewrite_module modules/mod_rewrite.so
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Note: Since httpd.conf is very big I showed only the lines I know to be relevant. If this is not enough I can upload the entire file on pastebin.
The file /etc/httpd/conf/extra/httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin webmaster#test.localhost
DocumentRoot "/srv/http/mysite/"
ServerName test.localhost
ServerAlias test.localhost
ErrorLog "/var/log/httpd/test.localhost-error_log"
CustomLog "/var/log/httpd/test.localhost-access_log" common
<Directory "/srv/http/mysite/">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
The file /srv/http/mysite/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
My /etc/hosts file:
127.0.0.1 localhost
127.0.1.1 mycomputer_name
127.0.2.1 test.localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
About this last file I noticed that if I remove the <IfModule ...> and </IfModule> site it works and redirects to index.php, but I would prefer not to change this file since it works the way it is on the remote server that uses ubuntu.
The main question is why this is not working but I would be also happy to know what the <IfModule mod_rewrite.c> is doing and why it is being ignored even though LoadModule rewrite_module modules/mod_rewrite.so is enabled.
I know this is not an easy question but I have not found anyone with this same problem on the web. I will be very grateful for any help.
Apache needs to be setup to recognize your index files (in this case index.php)
Do you have the following in your Directory
DirectoryIndex index.php
So
<Directory "/srv/http/mysite/">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
In httpd.conf you should have something like...
<IfModule dir_module>
DirectoryIndex index.php index.htm index.html
</IfModule>
This would be your catch-all fall-back.
And then in your httpd-vhosts.conf one of many site descriptions might look something like...
<VirtualHost *:8080>
ServerAdmin admin#siteName.com
DocumentRoot "e:/Stack/Sites/siteName/web"
ServerName siteName
ServerAlias siteNameUser
<Directory "e:/Stack/Sites/SiteName/web">
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/siteName.error.log"
CustomLog "logs/siteName.access.log" common
</VirtualHost>
Note: The DirectoryIndex index.php in httpd-vhosts.conf site declaration is unnecessary if you included the fall-back defaults in httpd.conf
If you are not wanting to use default port 80 then in either file have something like: Listen 8080
For localhost I use: in httpd.conf... Listen 127.0.0.1:8080 and in httpd-vhosts.conf Listen 8080
In your hosts file you will need to define something like...
127.0.0.1 siteName siteNameUser www.siteName.com
Currently using: Apache/2.4.33 (Win64) PHP/7.2.4 ~ MySql 5.7.22 homebrew stack.
The httpd-vhosts.conf example portion is for Drupal 8.x - For WP your DocumentRoot and Directory will differ.
You can listen on multiple ports such as 8080 for dev, 8081 for test, 8082 for prod. Also you can have many different site definitions in your httpd-vhosts.conf file.
I prefer to define all sites in httpd-vhosts.conf, but you could just place them in httpd.conf

How to perfectly set up virtual host for codeigniter project?

I am trying to make a virtual host for a codeigniter project. I have done this in httpd-vhosts.conf:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\CI_projects\facebook-login"
ServerName dev.facebook-login.com
<Directory "C:\xampp\htdocs\CI_projects\facebook-login">
Require all granted
</Directory>
</VirtualHost>
and in application/config/config.php,
$config['base_url'] = 'http://dev.facebook-login.com';
and
$config['index_page'] = '';
the browser opens the landing page. but when transiting from any other uri it says object not found.
And when i configure httpd-vhosts.conf like this:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\CI_projects\facebook-login\index.php"
ServerName dev.facebook-login.com
<Directory "C:\xampp\htdocs\CI_projects\facebook-login\index.php">
Require all granted
</Directory>
</VirtualHost>
It arises problem with assets things, i,e images and some css doesnt loads. How can I solve it?
I am on windows 10 and I use xampp with virtual host this is way I set up.
Put forward slash at end of base url
$config['base_url'] = 'http://dev.facebook-login.com/';
First go to
Windows > System32 > drivers > etc > host
You may need to open as administrator to be able to save it
You might see some thing like
127.0.0.1 localhost
Below that create another one for dev.facebook-login.com like example:
127.0.0.1 localhost
127.0.0.1 dev.facebook-login.com
Save it
Then go to the
xampp > apache > conf > extra > httpd-vhosts.conf
open it as administrator so you can save it.
No need for the index.php on DocumentRoot
<VirtualHost *:80>
##ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "C:/xampp/htdocs/CI_projects/facebook-login"
ServerName dev.facebook-login.com
##ServerAlias www.dummy-host.example.com
##ErrorLog "logs/dummy-host.example.com-error.log"
##CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
Save it and restart the severs.
I use this for my htaccess
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
httpd-vhosts.conf
Listen 1122
<VirtualHost *:1122>
DocumentRoot "D:\laragon_server\www\hugpong_production"
<Directory "D:\laragon_server\www\hugpong_production">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
https://www.namecheap.com/support/knowledgebase/article.aspx/10026/33/installing-an-ssl-certificate-on-xampp/
php 8 is not ready for CI4 as of jan 2021!
XAMPP has preloaded ssl certificate in php 7 packages
consider uncommon vhosts extra and place this in it
my only persistent issues is codeigniter 4 routes, have to turn on php spark serve to get XAMPP to route pages outside of default index, nothing else works, its garbage to that extent, will try with composer next....a whole book needs
to be wrote about codeigniter 4 routes and why they don't work, 200 pages plus
<VirtualHost localhost *:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
<VirtualHost example.com *:8080>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "C:\xampp\htdocs\codeignite4\public"
//my project folder is codeignite4 without using composer this time
//i added listen 8080 under listen 80 in htppd.conf
ServerName example.com
<VirtualHost truservex.com *:443>
DocumentRoot "C:\xampp\htdocs\codeignite4\public"
ServerName example.com
SSLEngine On
SSLCertificateFile "C:/xampp/apache/conf/ssl.crt/server.crt"
// you can verifiy these file locations, certificate data
SSLCertificateKeyFile "C:/xampp/apache/conf/ssl.key/server.key"
// going without the Directory tag can be helpful to drop in vhosts
<Directory "C:\xampp\htdocs\codeignite4\public">
Require all granted
doing this i was able to replicate the original install, create site access
using http://localhost:8080 or http://example.com/ as my base url
in my example index.php is removed, set to ''
when using command prompt to get into codeignite4 project folder i can
launch php spark serve and routes will work that were previously 404
Using Xampp 7.3.25 Dec 2020 because php 8 will not run error
free with codeigniter 4 as of this date, this worked for me as
my first codeigniter 4 virtual host setup, my install had
difficulty initially with using port 80, seems to want to for
port 443 if it can..I'm not a server pro but i wanted to
leave this for the next guy....This is strictly name based
virtual hosts for develop, ip based would have obvious
advantages. Because i had trouble in initial CI4 testing with
port 80 the (*) in virtual hosts vs (*:80) seemed to solve one
hurdle in searching for more ports, now i can finally begin my
first project ...my default URL was also changed to example.com
in appstarter/apps/config file. Carefully reread <tags> for
typos, its easy to shut server down!
<VirtualHost *>
DocumentRoot "C:/Xampp/htdocs/"
ServerName localhost
<Directory "C:/Xampp/htdocs/">
Require all granted
<VirtualHost *>
DocumentRoot "C:/Xampp/htdocs/appstarter/public/"
ServerName example.com
ServerAlias www.example.com
# maybe don't attempt to use dir tag, shuts down server
# the directives at httpd.conf appear to suffice
I have added a htaccess file in the appstarter/public
I assume this is primitive, can get far more advanced
The Apache help pages helped me focus a bit more on
what i must accomplish, name based virtual hosts this case
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
2.2 Apache configuration: :Apache server context important!
Order allow,deny :The hackers are winning.....
Allow from all
2.4 Apache configuration:
Require all granted

Routing url in Yii2 with xampp

My basic project is in C:\xampp\htdocs\site.local\www
I can run my app whith http://site.local/basic/web/index.php
But I want run it as http://site.local/index.php
How can I solve this problem?
I changes my httpd.conf :
DocumentRoot "C:/xampp/htdocs/site.local/www/basic/web"
<Directory "C:/xampp/htdocs/site.local/www/basic/web">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
AllowOverride All
Require all granted
</Directory>
But it doesn't work
Your solution is simply named Virtual Host. In C:\xampp\apache\conf\extra\httpd-vhosts.conf add the following:
<VirtualHost 127.0.10.80:80>
##ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "C:/xampp/htdocs/site.local/www/basic/web"
ServerName site.local
ErrorLog "logs/site.local.log"
##CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
Then, run the notepad as administrator and from it open the hosts file in C:\Windows\System32\drivers\etc\hosts and add the following line to its end:
127.0.10.80 site.local
Save the both files and restart the Apache Server and restore the default .httaccess.
Notice: the IP 127.0.10.80 is called internal loop IP and it is dedicated for local hosting. It may be any other value starts with 127, such as 127.0.0.1 (the default one)

Apache Mod Rewrite For Laravel

I have an installation of Laravel on Wampserver. The directory is as follows:
C:\wamp\www\laravel
Now URLs are like this:
http://localhost/laravel/public/index.php/home/index
So I used the following htaccess code
Options +FollowSymLinks
Options -indexes
DirectoryIndex index.PHP
RewriteEngine on
RewriteCond $1 !^(index\.PHP|images|robots.txt)
RewriteCond %{REQUEST_ FILENAME} !-f
RewriteCond %{REQUEST_ FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L, QSA]
To reduce the URL to
http://localhost/laravel/public/home/index
But the laravel framework insists that all application files reside in the public folder.
So I would like to know what I need to add to (or subtract from) the htaccess file so that the URL can look like
http://localhost/laravel/home/index
Thanks
When testing locally I do one of two things.
Create a new .htaccess below the public directory with the following.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Create a new virtual host. With WAMP you can navigate to C:\wamp\bin\apache\YOUR APACHE VERSION\conf\extra and find your httpd-vhosts.conf file, in there you can see example virtual hosts. Here's one of mine:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
</VirtualHost>
Make sure that your vhosts configuration file is being included. Open up your httpd.conf file and search for the vhosts file, uncomment the include line if it's commented out. Then I open the CLI and enter notepad "C:\windows\system32\drivers\etc\hosts" which opens up your hosts file. Underneath the item that mentions localhost place your new host. Here's an example.
127.0.0.1 laravel.dev
Make sure you restart Apache and bingo, you should be able to navigate to http://laravel.dev and you won't have any annoying public directory. This is how I achieve it, as I prefer the nicer looking virtual host rather then a long winded localhost URL.
Hope this helps.
I finally figured a way out. First of all, I had to open and edit my Apache httpd.conf by selecting it from the Wamp Aestran tray menu. The I had to uncomment the line
#Include conf/extra/httpd-vhosts.conf
After that, I opened the file which is located at the
<wampdirectory>/bin/apache/apache.x.y.z/conf/extra/httpd-vhosts.conf
then I added the following lines.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
Options Indexes FollowSymLinks
<Directory "C:/wamp/www">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
#If you want to allow access from your internal network
# For specific ip addresses add one line per ip address
#Allow from 192.168.0.100
# For every ip in the subnet, just use the first 3 numbers of the subnet
#Allow from 192.168.0
</Directory>
</VirtualHost>
## must be first so the the wamp menu page loads when you use just localhost as the domain name
<VirtualHost *:80>
DocumentRoot "C:/wamp/sites/laravel/public"
ServerName laravel.dev
Options Indexes FollowSymLinks
<Directory "C:/wamp/sites/laravel/public">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
#If you want to allow access from your internal network
# For specific ip addresses add one line per ip address
#Allow from 192.168.0.100
# For every ip in the subnet, just use the first 3 numbers of the subnet
#Allow from 192.168.0
</Directory>
</VirtualHost>
The next step was to edit my hosts file at C:\windows\system32\drivers\etc
and added
127.0.0.1 laravel.dev
Then restarted Wamp and it worked. Thanks to you guys for pointing me in the right direction. Really Appreciate it
The easiest way I got this working on my local dev environment was to do the following:
(Assuming you have WAMP installed in C:\WAMP)
Create the following folder:
c:\wamp\www\laravel
Download laravel and put the contents in the above directory. You will know you have done it right if you can browse to hxxp://localhost/laravel/public and get the opening screen. However, this isn't good enough. We want to get that screen by going to http://localhost/laravel
So then we do the following:
Create a textfile containing the following:
Alias /laravel "c:/wamp/www/laravel/public"
<Directory "c:/wamp/www/laravel/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Allow from all
</Directory>
Save this file as laravel.conf in the c:\wamp\alias directory.
Finally, restart your wampserver.
You should now be able to surf to http://localhost/laravel
Note that the above is strictly for a local development environment.
You're gonna end up with your code and your public folder residing in the same place, which most people do not recommend. I'd suggest you take advantage of using a local web server.
Why not make mysite.dev point to laravel/public directory so you could just use http://mysite.dev everytime, you have cleaner and shorter URL's too?
As a newb to WAMP and Laravel, I struggled at bit but did get the virtualhost thing to work on my WIN7PRO 64-bit box. In WAMPSERVER/Apache/hppd.conf at the end of the file, I added:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot C:/webapp/public
ServerName webapp
<Directory C:/webapp/public >
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from All
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/wamp/www
ServerName localhost
</VirtualHost>
and I added:
127.0.0.1 webapp
to the hosts file. (I was never successful editing the vhosts files, as many posts on the web suggested.)
These changes allow me to get to my Laravel test app in my browser via
http://webapp
(and also, via just http://127.0.0.1)
and, to get to all my other sites, via:
http://localhost/devsite/whatever..

Categories