Creating new symfony project on localhost - php

Hello I'm trying to run project using newest symfony on my localhost.
What i already did:
I added this to my vhosts file in Xampp.
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "F:\Programy\XAMP\htdocs\Anka\web"
ServerName Anka
DirectoryIndex app_dev.php
ErrorLog "logs/vark.local-error.log"
CustomLog "logs/vark.local-access.log" common
</VirtualHost>
I added this in my hosts file in Windows\System32...
127.0.0.1 Anka
This is what i see after typing
anka\
In my browser.
My localhost website
And when i click on web i see this:
web
Can somebody help me what else i should do to see normal Symfony index page?

Try http://anka/app_dev.php or http://anka/web/app_dev.php
Also You can Change the directory to this one with the application and run:
php bin/console server:run
Then access http://localhost:8000/ in your browser
Like this:
https://symfony.com/doc/current/setup.html#running-the-symfony-application

First of all - ServerName value is case-sensitive, to Apache is not really recognizing request as this VirtualHost and you're getting listing of root directory.
Use http://Anka url, or change ServerName Anka to ServerName anka and 127.0.0.1 Anka into 127.0.0.1 anka.
Next thing is that you have some errors in your code and PHP cannot find AnkaBundle\AnkaBundle class. You're probably missing an autoloader, but that's only my guess. Not enough information to be sure.

Related

local assets(css/js) not found when using apache virtual host

I've added 127.0.0.1 my.pro to my hosts file
and add below code to httpd-vhosts
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/ci4/public"
ServerName my.pro
ErrorLog "logs/myproject-error_log"
CustomLog "logs/myproject-access_log" common
</VirtualHost>
the problem is i can't reffer to my assetes. assetes and project index page are in defferent directories.
-ci4
--public
---index.php
--assets
---css
C:/xampp/htdocs/ci4/public is project root and i locate assetes in C:/xampp/htdocs/ci4/assetes .
when I try to load a CSS file with this resource http://my.pro/assets/css/style.css it shows 404 error.
I know apache tries to load file from C:/xampp/htdocs/ci4/public/assets/css/style.css which doesn't exist.
but I have no idea how to fix it!

run laravel project without artisan serve

i have an issue that i want to run my laravel project without cmd command php artisan serve , i want something like usually in php project localhost/projectName , when i do all the steps like changing hosts in System32/driver/etc/hosts
and changing E:\wamp\bin\apache\apache2.4.33\conf\extra\httpd-vhosts.conf with all recommended option i restart wamp but when i put on the url projectname.dev the cercle above browser still Spins and nothing displays in the browser!!!!
someone has any idea
the configurations is
<VirtualHost *:80>
ServerAdmin webmaster#ahssanstore.dev
DocumentRoot "E:\wamp\www\AhssanStore\public"
ServerName ahssanstore.dev
ServerAlias www.ahssanstore.dev
ErrorLog logs/ahssanstore.dev-error.log
CustomLog logs/ahssanstore.dev-access.log common
<Directory "E:\wamp\www\AhssanStore\public">
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
and in C:\Windows\System32\drivers\etc
i add 127.0.0.1 ahssanstore.dev
and i restart wamp and after that i navigate to localhost/ahssanstore.dev
For windows, you can try use Laragon.
For those that have an Ubuntu Dev Server (with the possibility of other projects in your /var/www) I did the following to make it work.
Rename your-app/server.php to your-app/index.php
Copy .htaccess from your-app/public/ to your-app/
PS: If anyone knows that this creates some problems down the line please advice.
Done
Sometimes, servername: 'projectname.dev' doesn't work (I'm used to meet like this). Try changing 'projectname.me' instead 'project.dev'.
For VirtualHost configuration, you only need to set two lines:
<VirtualHost *:80>
DocumentRoot "E:\wamp\www\AhssanStore\public"
ServerName ahssanstore.dev
</VirtualHost>
Just Sharing my knowledge. Hope it also works!

Virtual Host on Xampp for Laravel is not working

Hello i am learning Laravel and trying to modifying vhost file of my xampp server for laravel practice project, but its not working.
code of vhost file is
<VirtualHost *:80>
DocumentRoot "D:/xampp/htdocs/laravel5Prc/public"
ServerAdmin admin#localhost
ServerName laravel5.prc
ServerAlias laravel5.prc
<Directory "D:/xampp/htdocs/laravel5Prc/public">
AllowOverride All
Options Indexes FollowSymLinks
Require local
# if you want access from other pc's on your local network
#Require ip 192.168.1.121
# Only if you want the world to see your site
#Require all granted
</Directory>
</VirtualHost>
i have taken this code from this url
How to enable Virtual Host on Xampp for Laravel?
its not working form me, anyone please guide me what am i doing wrong in it ?
I'm strongly recommend you to use Laravel's vagrant box called Homestead instead of xampp, it's really amazing! You can read about it here. It's much more flexible and easier to understand than anything else.
I was using php-7.3.2 and had similar problem. This is not the solution to the problem, but an alternative. I went back to php-7.1.25 and ran again. I'm still going to check out what the problem is with version 7.3 and laravel, but maybe this will help some people who come here with the same problem.
This is what you should do, add or uncomment this below at the top of the xampp vhost file
NameVirtualHost *:80
Change this to you valid assumed domain and add the Directory index
ServerName laravel5.test
ServerAlias laravel5.test
DirectoryIndex index.php
And then go to the this folder C:\Windows\System32\drivers\etc\hosts in windows and add your domain of choice for example see this below
127.0.0.2 laravel5.test
127.0.0.3 anotherdomain.test
**** Please note don't use the localhost or 127.0.0.1 created by default to set yours's
you should create you own e.g. (127.0.0.2, 127.0.0.3, 127.0.0.4) in that order
After then restart you xampp server you should be good to go
**** I notice your Document and Directory has this "D:/xampp/htdocs/laravel5Prc/public"
change the D to C and please I would advise your laravel project should be outside the xampp folder, you can use the Document folder for this.
//Open C:\Windows\System32\drivers\etc\hosts
127.0.0.1 laravel5.prc
//Open xampp/apache/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "C:/xampp/htdocs/laravel5Prc/public"
ServerName laravel5.prc
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/d`enter code here`ummy-host2.example.com-access.log" common
</VirtualHost>
why you don't use
php artisan serve
to run laravel on localhost.
from https://laravel.com/docs/5.4/

Why I can't set a vhost for this PHP website on my XAMPP?

I am finding the following problem trying to create a vhost for a PHP website that I have into XAMPP.
So basically this is where is the index.php file of my website is deployed: C:\xampp\htdocs\MyProject-Panda
Then into the C:\xampp\apache\conf\extra\httpd-vhosts.conf** file I have declared 2 vhost:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/HotelRegistration/public"
ServerName laravel.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/MyProject-Panda"
ServerName panda.dev
</VirtualHost>
(the first one works fine, the second one no).
Finally into the C:\Windows\System32\drivers\etc\hosts file I have:
127.0.0.1 localhost
127.0.0.1 laravel.dev
127.0.0.1 panda.dev
So I am enabling the panda.dev domain on my local machine.
The problem is that when I open the panda.dev domain into my browser it is automatically "rewrited" into http://www.panda.dev/ and it says that can't contact the server.
Why? What could be the problem? How can I try to solve this situation?
You should use .local for local sites. .dev must not be interpreted correctly by browsers, even if you have hosts record.
In this case I think problem is - you have some .htaceess in C:/xampp/htdocs/MyProject-Panda with redirect to WWW version. Windows hosts does not work for subdomains automaticly (as www.panda.dev is subdomain of panda.dev). You eighter has to remove this redirection or add 127.0.0.1 www.panda.dev record to your hosts file.

Apache VirtualHost Issues

I have two installations of laravel. One in a folder called "laravel" and the second in a folder called "learningLaravel". Both of them are siblings in the same parent folder. Before i installed "learningLaravel" i used to access the site in "laravel" through localhost/laravel/public, and everything works fine .
After i installed "learningLaravel", i decided to create a virtual host for it on my WAMP server with the name "learningLaravel.dev" . My [windows/system32/drivers/etc/hosts] file looks like this:
127.0.0.1 localhost
127.0.0.1 localhost
// I added this entry. The first two entries above was already there
127.0.0.1 learninglaravel.dev
I added the following to my Apache "httpd-vhosts.conf"::
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/learningLaravel/public"
ServerName learningLaravel.dev
</VirtualHost>
Now i can access "learningLaravel" through learningLaravel.dev. But when i want to access the site in the "laravel" folder through localhost/laravel/public, i get a message ::
Not Found
The requested URL /laravel/public was not found on this server.
I try localhost also and i get ::
Not Found
The requested URL / was not found on this server.
The problem i have now is anything that begins with localhost doesn't work, but learningLaravel.dev works.
What changes do i need to make? thanks.
Just define 2 virtual hosts:
The first catches all domains which don't have their own virtual host. In this example these are domain1.dev, domain2.dev, domain3.dev and localhost.
The second host catches the domain learninglaravel.dev
httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/"
ServerName localhost
ServerAlias *.localhost
</VirtualHost>
<VirtualHost learninglaravel.dev:80>
DocumentRoot "c:/wamp/www/learningLaravel/public"
ServerName learninglaravel.dev
ServerAlias *.learninglaravel.dev
</VirtualHost>
windows/system32/drivers/etc/hosts
127.0.0.1 learninglaravel.dev
# you don't need the following this is just for explanation:
127.0.0.1 domain1.dev
127.0.0.1 domain2.dev
127.0.0.1 domain3.dev

Categories