routing in laravel3 not working properly - php

I am new bee in Laravel. I have set up Laravel by help of this tutorial. I have set virtual host, on my virtual host I wrote this.
<VirtualHost *:80>
ServerName ranjitalaravel.com
DocumentRoot "/var/www/html/laravel4/public"
<Directory "/var/www/html/laravel4/public">
</Directory>
</VirtualHost>
In my host file i.e. /etc/hosts
127.0.0.1 ranjitalaravel.com
When I type the http://ranjitalaravel.com/ on my browser all list of file inside my laravel directory is showing. But when I type home after it it shows me "The requested URL /home was not found on this server.". I have write this code in route.php inside application folder.
Route::any('home', function()
{
return View::make('home.index');
});

<VirtualHost *:80>
ServerAdmin postmaster#some_server
DocumentRoot "E:/xampp/htdocs/some_server"
ServerName some_server
ServerAlias some_server
ErrorLog "logs/some_server.localhost-error.log"
CustomLog "logs/some_server.localhost-access.log" combined
</VirtualHost>
this works fine to me, hope helps you

Try this configuration
<VirtualHost *:80>
ServerName ranjitalaravel.com
DocumentRoot /var/www/html/laravel4/public
<Directory /var/www/html/laravel4/public/>
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
are you using symlinks?

Instead of using VirtualHosts which can get nasty from time to time why not use PHP 5.4 inbuilt development server.
Here's how XAMPP localhost returns object not found after installing Laravel

Related

404 on GET request Laravel 9

I'm working on a project with the new version of Laravel. My other projects are all previous versions. I tried every artisan clean method to make everything clear. I checked the server requirements, which are precisely the same as how I run my other Laravel 8 projects. But when I request by Postman my API, it returns a 404 page instead of the actual action.
Route
GET|HEAD api/token ... generated::*** › UserController#tokenRequest
api.php
Route::get('token', [UserController::class, 'tokenRequest']);
I return a simple response with a token. If there is a PHP error, I'll see it and not return with a 404, which is weird. I had the same problem with my other projects, but it was just a mod_rewrite issue, but I all checked those options. Each is set correctly in the .conf. I use apache on my Ubuntu 20.04 server, like my other projects. The only difference is the Laravel version.
URL that I use:
https://example.com/directory/api/token
Public directory URL is working perfectly.
https://example.com/directory/public
Custom domain .conf
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#domain1.com
DocumentRoot /var/www/html
<Directory /var/www/html>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com.log combined
I usually setup vhost for each project and this is how it looks like for me:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#domain1.com
DocumentRoot /var/www/html/example.com/public
<Directory "/var/www/html/example.com/public">
AllowOverride All
ReWriteEngine On
Options Indexes MultiViews FollowSymLinks
Order allow,deny
allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com.log combined
and this worked for all my laravel apps

apache2.conf and httpd.conf

After reading ubuntu AMP community and Apache 2.4 configuration.
I was wondering if there is a way to imitate the same behavior of the http docs used in XAMPP or bitnami stacks but using the default LAMP. Which uses apache 2.4
In XAMP you would assign an extra number to your httpd-vhost.conf like this:
Listen *:9000
<virtualhost *:9000>
ServerName localhost
DocumentRoot "~/xamp/apache2/htdocs/html/app-name/"
</virtualhost>
<Directory "~/xamp/apache2/htdocs/html/app-name/">
Options Indexes FollowSymLinks
AllowOverride all
</Directory>
Then Edit your httpd.conf files like:
//....Some code..... */
<Directory>
AllowOverride all
<Directory />
//...Some code...
and uncomment this line:
//....Some code..... */
# Virtual hosts
include conf/extra/httpd-vhosts.conf
//...Some code...
My question is:
Is there is a way to configure Apache 2.4 just by dropping all my vhost's in one single file, without having to go through the process of configuring etc/apache2/sites-available and then adding names to etc/hosts?
Then completing the process by including some things like above just like Bitnami or Xamp stacks will do so your localhost will be able to serve not only static html files but an entire application's folder.
What works is the following in (for example) your 000-default.conf:
<VirtualHost *:80>
ServerName site1.vm
ServerAdmin webmaster#localhost
DocumentRoot /var/www/site1/web/
ErrorLog ${APACHE_LOG_DIR}/site1_error.log
CustomLog ${APACHE_LOG_DIR}/site1_access.log combined
<Directory /var/www/site1/web/>
Options All
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName site2.vm
ServerAdmin webmaster#localhost
DocumentRoot /var/www/site2/web/
ErrorLog ${APACHE_LOG_DIR}/site2_error.log
CustomLog ${APACHE_LOG_DIR}/site2_access.log combined
<Directory /var/www/site2/web/>
Options All
AllowOverride All
</Directory>
</VirtualHost>
This way all you have to do is add the site to the conf file, add the host to your hosts file, and reload apache2 service. Hope that is what you were looking for.

XAMPP - Alias 127.0.0.1

Currently, I have XAMPP setup to where typing 127.0.0.1 in the browser redirects me to the home page found within htdocs.
I would like to be able to type "devtest" and have that be an alias for 127.0.0.1.
What I have tried so far is modifying: C:\xampp\apache\conf\extra\httpd.vhosts.conf where I added an entry that looks like:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot C:\xampp\htdocs\Workspace\MyProject
ServerName devtest
ErrorLog C:\xampp\htdocs\Workspace\MyProject\MyProject-error_log
CustomLog C:\xampp\htdocs\Workspace\MyProject\MyProject-access_log common
</VirtualHost>
Is there another step I'm missing?
Open the hosts file in Notepad:
C:\Windows\System32\drivers\etc\hosts
Add the line:
127.0.0.1 devtest
Navigate to: http://devtest
Use this, and make sure you enable using vhosts config file in apache.
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\Workspace\MyProject"
ServerName devtest.local
<Directory "C:\xampp\htdocs\Workspace\MyProject">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

php file operations permission denied

I have two Virtual Hosts on Redhat Enterprise server, one of which functions as desired. The second I a have problems when using PHP to do any kind of file operations. As far as I can tell both virtual hosts have been set up in the same. I have checked that file permissions have been set correctly on the folders/files in question. I have gone as far to set permissions to 777.
Can anyone suggest where I might have gone wrong? The virtual hosts are set up as follows:
<VirtualHost *:80>
ServerName intranet
ServerAlias intranet *.intranet
DocumentRoot /home/burnside/public_html
<Directory "/home/burnside/public_html">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName tracker
ServerAlias tracker *.tracker
DocumentRoot /home/tracker/public_html
<Directory "/home/tracker/public_html">
Allow from all
Options +Indexes
</Directory>
</VirtualHost>

Problems in installing Laravel at localhost

I am trying to install PHP-Laravel in Windows 8 and I am using Xamp server(localhost). I am following Installing Laravel guide.
According to this guide I am making virtual host using following code :
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/TssApp/public"
ServerName TssApp
<Directory "C:/xampp/htdocs/TssApp/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
</Directory>
</VirtualHost>
//Where "C:/xampp/htdocs/TssApp/public" is path of Laravel public folder
and I have also added following line in in etc/hosts
127.0.0.2 TssApp
After doing necessary steps mentioned in this tutorial when I type "http://TssApp" , it always redirect to "http://tssapp/xampp/" instead of Laravel Home page. I don't know if I am missing any thing.
Note: I can access laravel home page at "http://localhost/tssapp/public/" but want
to use "http://TssApp" link to access my application.
Please help me regarding this issue.
Thanks .
Do you have NameVirtualHost * in your virtual-hosts configuration?
You'll need to restart Apache after any changes to either /etc/hosts or your virtual-hosts configuration files
Try adding the code to C:\xampp\apache\conf\extra\httpd-vhosts.conf instead of adding it to your own conf file. As far as I know xampp will ignore it unless its in the vhosts file.
You could try this.
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs\TssApp\public"
ServerName tssapp
<Directory "C:\xampp\htdocs\TssApp\public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Although you should put your files in the xampp directory and not the htdocs directory, so your files should be C:\xampp\TssApp\public, This would stop people from visiting htdocs which is a public folder and getting access to your application.
According to the documentation (that you point to), you should write
<VirtualHost 127.0.0.2>
and not
<VirtualHost *:80>
Could you try that and restart your computer/server?
Add in:
Allow from all
after
AllowOverride all
The end result should be:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/TssApp/public"
ServerName TssApp
<Directory "C:/xampp/htdocs/TssApp/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Allow from all
</Directory>
</VirtualHost>
Also make sure you are editing the file "httpd-vhosts.conf" found in:
C:\xampp\apache\conf\extra

Categories