Run laravel 5.2 under IP address, view does not work - view

I have just created a new Laravel 5.2 project with composer and uploaded to my ubuntu 14.04 LTS server, which has Apache 2.4.7. My server does not have domain name, so I must run project based on something like xxx.xxx.xxx.xxx/login. But in this condition, my route file cannot load views.
For example if i have view file with name login.blade.php, if in my route file I write:
Route::get('/', function () {
return view('login');
});
the view file cannot be loaded. But, if in terminal and in the root of my project I type:
php public/index.php
and then if I refresh the url, the view now loads and works.
What is going on here? I cannot understand what is going on. Can somebody help with this?

First you have to set your laravel permission
chown -R apache.apache /var/www/html/yourLaravel
chmod -R 755 /var/www/html/yourLaravel
if it still not working. you have to set your firewall
setenforce 0
this command you have to set all the time you restart your server

Related

Unable to get the login/register pages with Laravel 8's Jetstream on Apache

I've installed Laravel version 8, and made a project using the --jet flag, I've also run the npm install && npm run dev afterwards, and have also run the migrations successfully(confirmed by the artisan's messages and also looking at my database and seeing the tables there), and also the mydomain.loc is showing me the Laravel's welcome page, but my problem is that the mydomain.loc/register doesn't show the register page, neither does the mydomain.loc/login. Entering these addresses in the browser shows the Apache's 404 page(mod_rewrite is enabled too and I've tried restarting the Apache service as well).
I'm running Apache2 on an Ubuntu 20 virtual machine, and it is serving my Laravel's project in the DocumentRoot /var/www/html/myproj/public. Also the MySQL is running in the VM and I've added its info to both the .env file and the config/database.php, and weirdly everything "seem" to work all fine(Database connection is working... and also the Laravel's welcome page is shown...) except for the login and register pages.
Not sure if it matters, but also since this is only in development, I've done a chmod 777 -R on the project's root too, to make sure it's not a permission thing.
Here is my Apache site's configuration(only the parts that matter for this question):
# nano /etc/apache2/sites-available/mydomain.loc.conf
ServerName mydomain.loc
ServerAlias www.mydomain.loc
DocumentRoot /var/www/html/myproj/public
And here's what I have inside my routes/web.php file:
Route::get('/', function () {
return view('welcome');
});
Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
return view('dashboard');
})->name('dashboard');
Sounds like you don't have your site configured correctly for url rewriting (pretty urls). As you should at the least be getting a Laravel 404 error not the web server. Which means rewriting isn't working and it is looking for a file/folder instead of handing off to the index.php file.
Laravel 8.x Docs - Installation - Pretty URLs

How to migrate tables on a running site for laravel?

Using laravel how to migrate table(if there are changes) on a running site?
We use CMD if working offline. My question is simple if I have a site running fine already (online) then how to migrate...we can't run CMD there, right?
one way is using Artisan command in routes like this:
Route::get('/migrate', function(){
\Artisan::call('migrate');
dd('migrated!');
});
and then call this route.
remember to REMOVE this route after MIGRATING...!
if your server is linux you can use ssh to access command environment.
If your personal system is Windows you can install putty to open ssh.
how it works is in this link :
https://mediatemple.net/community/products/dv/204404604/using-ssh-in-putty-(windows)
how to access ssh in mac system is in this link
https://www.servermania.com/kb/articles/ssh-mac/
after access ssh you most first install composer then locate your project folder and now you can call all php artisan command like
php artisan migrate
import Artisan at web.php
use Illuminate\Support\Facades\Artisan;
you can write migrate route like this
Route::get('migrate',function(){
Artisan::call('migrate');
});
you can write migrate:rollback route like this
Route::get('rollback',function(){
Artisan::call('migrate:rollback');
});
you can write routes & view clearing route like this
Route::get('vr-clear',function(){
Artisan::call('route:clear');
Artisan::call('view:clear');
});
Basically i will suggest you too use like this reboot route for clearing cache and route clear after deploying the Laravel project to live.
Because sometimes it can be show some error message.
Route::get('reboot',function(){
Artisan::call('view:clear');
Artisan::call('route:clear');
Artisan::call('config:clear');
Artisan::call('cache:clear');
Artisan::call('key:generate');
});
The answer is also simple. You're still going to use CLI or CMD while your site is online. If you use cPanel, go to Advanced tab and select terminal. Inside your terminal use cd to change drive. Default drive might probably be public_html. cd public_html, cd <your_project_folder>php artisan migrate.
This will process migration while your application is running.

Xampp localhost not working

I am running laravel on xampp and I have problem with accessing pages,
http://localhost/laravel/public/ I get a login page which is good
however when I go for example http://localhost/laravel/public/smokeyard
I get 404 error with The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
Route:
Route::get('smokeyard', 'GuzzleController#smokeyard');
Controller:
function smokeyard(){
return view('smokeyard');
}
All my views are located in resources folder.
if you want to access laravel project without running artisan serve, you need to change few settings,
copy the .htaccess file from the public folder and paste it in the root folder of your application
rename the server.php in the root directory to index.php
now go to localhost/your_project_name/smokeyard for the url you want to check
hope this helps
Run php artisan serve and access your server at http://localhost:8000. Your routes should work fine then.
You can't access your laravel application routes straight away through the folder structure with xampp. You need to setup the web root to point to the public folder and access localhost or run the laravel server and use it. This is because the url rewriting would fail when you access the routes in laravel the way you do.
I tried this in MX Linux 21.xx. My xampp got messed up after installing larvel on it.
check MySQL status with command
mysql service status
stop the service using the command
service mysql stop
you will be prompted to provide your password, Enter password.
start xampp using command
sudo /opt/lampp/lampp start
All should be back to normal

Laravel 5.3 sometimes return different 404 page

I'm trying to understand why my 404 page is not loading if I try to go under public folders.
When I'm trying to go assets folder. I'm getting this 404 page.
Make sure your views are placed inside resources/view folder.
When you run Laravel in your local PC or server, run it with administrative privileges (not a must be thing)
sudo php -S localhost:8888 -t public
This is what I use in Linux. I think you are missing something here.

How to run laravel 5.0 project on localhost without use php artisan serve

I have created a laravel 5.0 project with php artisan serve, now i need to know how to run laravel 5.0 project run without start php artisan serve, i have already browse lot of websites no one help me..
You need to change "server.php" to "index.php" then copy ".htaccess" from public to root directory.
See: https://stackoverflow.com/a/30053989/3948755
Laravel sever Folder is "public". There is an index.php so you can run you project from there.
Suppose if you using UbuntuOS then you have to create your local server in public directory. Suppose your folder name is laravel_test then go in that directory and run some thing like this
php -S localhost:8000 -t public
If you using windows then access public folder from URL.
localhost/laravel/public
Actually it's bad practise to access folder from URL but for local its good. You also can go with host entry. Just make sure that your target folder is "public" directory.
Normally you would have WAMP/XAMPP installed. You can access Laravel project like below
localhost/laravel/public
But this is not recommended. You should create Virtual host for example
laravel.local that pints to server-root/laravel/public.
this is how you create virtual host.
Or even better go for a Laravel Homestead .
How is your .htaccess file configured?
Try with localhost/laravel/public/index.php
Use http://localhost/projectName/public
It will be work. but in case if you have another Route and you can not access that Route and get the error like " Page Not Found " then please use the following command
sudo a2enmod rewrite
Now open the http://localhost/projectName/public/yourRoute
This is a little late but still applicable, what I like to do (using ubuntu 14.x+) is put my laravel project (let's say Project1) in my var directory, so it would be in /var/Project1, then symlink the public folder to somewhere in /var/www(+/html depending on apache version).
Symlink can be done something like this:
ln -s /var/Project1/public /var/www/html
This keeps your internal files off the grid so to speak, this is untested so if I've missed anything just comment and I will amend this post.
EDIT:
Obviously if your http root is /var/www/html you can put your project in /var/www/Project1
If you have access to xampp or wampp on your operating system you can more or less configure your virtual host like in the instruction below:
https://bestin-it.com/creating-virtualhost-on-your-local-computer-to-start-simple-index-php/
This instruction shows how to run it locally on your PC, but it works generally the same on any hosting portals. In most case in payed portals you have any web panels to configure your public folder that reference to /public folder in laravel folder's structure.

Resources