I make a fresh setup of laravel on localhost (/var/www/html/) with command composer create-project laravel/laravel moduleTesting --prefer-dist.
Then I move all the files inside folder to (/var/www/moduleTesting/setup), then move all the files from public folder(/var/www/moduleTesting/setup/public) to moduleTesting folder(/var/www/html/moduleTesting).
I changed bootstrap file path in index.php file placed in moduleexample.dev folder(/var/www/html/moduleTesting/).
require DIR.'/setup/bootstrap/autoload.php';
$app = require_once DIR.'/../../laravel_setup/bootstrap/app.php';
I also set the permission of folder /var/www/moduleTesting/setup/bootstrap/cache and /var/www/moduleTesting/setup/storage
Then I run command composer dump-autoload in terminal at (/var/www/moduleTesting/).
Then I try to run URL in the browser, and I see the welcome page of laravel app.
Then I install module package caffeinated/modules
Begin by installing the package through Composer.
composer require caffeinated/modules
Once this operation is complete, simply add both the service provider and facade classes to project /var/www/html/moduleTesting/setup/config/app.php file:
Service Provider
Caffeinated\Modules\ModulesServiceProvider::class,
Facade
'Module' => Caffeinated\Modules\Facades\Module::class,
After successful installation, I create a new module by command
make:module Admin and follow easy steps steps and it created successfully and run by hitting URL http://localhost/moduleTesting/admin'.
Issue
Now the problem is when I run URL.'http://localhost/moduleTesting/admin'
it runs successfully but when i run 'http://localhost/moduleTesting/admin'(add '/' only at the end of the same url) it does now work and redirect me to url 'http://localhost/admin'
Does anybody know, please help me how to solve this issue, On the same node if upload the setup on the server in a inner folder and run the same url it also redirect me.
This is probably because .htaccess redirects trailing slashes to an URL without a traling slash.
In this section in your .htaccess file, Apache redirects everything with a trailing slash - if not a folder - to its origin. This causes trouble, because the public of the project is located at a directory.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
Replace the second rule with:
RewriteRule ^(.*)/$ /moduleTesting/$1 [L,R=301]
Note: it is better not using a directory as your public destination because these kinds of problems occur. You should be better of creating a fake local domain, like: module-test.dev or something.
Related
This is the first time I am developing a Laravel Vue app. When I use php artisan serve, everything works fine. But when I load it with http://localhost/myProject/public, assets are not loaded. My images are in img directory inside public folder. I was using blade templating to manage this issue when I use Laravel alone. But now I can't use blade since it is a Vue component. How can I run the project without php artisan serve? My Ultimate aim is to deploy the project in godaddy shared server. Please help me.
Debug your application using 'php artisan serve' while you develop from your local machine.
When you publish it into godaddy,
compress the project folder (say 'my_project') and upload the zip file ('my_project.zip') to 'public_html' directory in godaddy.
unzip the folder.
Now the directory structure will be 'public_html/my_project...'
you will have a 'public' directory inside 'my_project'.
Now create a subdomain which points to the 'public' directory.
That's it. Now load the subdomain.
The assets and api's will work perfectly.
just rungit clone [your_project_address] in the www folder and then run 'php artisan migrate', of course, you should have configured well.
#ThasheelApps this is your solution to access api's.
Create a .htaccess file in root folder and paste the following code there:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This issue occurs many times due index.php in url. if you try your api endpoint including index.php, it will work perfectly. to prevent this issue we need to follow above soution htaccess
Follow these steps:
zip your project after npm run dev and php artisan serve without
any error.
Go to your shared hosting location and outside fo public_html
make a folder name say myproject. Inside this folder extract all
your project files.
cut your public folder from project folder on root, go to your
subdomain folder under public_html and paste.
go to index.php inside public folder and
require DIR.'/../vendor/autoload.php'; and
$app = require_once DIR.'/../bootstrap/app.php'; pointing to your project location on root.
That is all. Enjoy, if you have properly created and attached your DB to your project.
I have a major problem during the deployment of my laravel 5.6 project on shared hosting, It seems my blades are not going to work. I have copied all of my project files to a new folder in my root directory namely "muxproject" and then I coppied all of the files in public folder of laravel project to public_html, and i have changed the index.php file as follows
<?php
define('LARAVEL_START', microtime(true));
require __DIR__.'/../muxproject/vendor/autoload.php'; //changed
$app = require_once __DIR__.'/../muxproject/bootstrap/app.php'; //changed
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
When I navigate to the link http://example.com/ A login page according to my logic in web.php appear and ask for the login after login successfully the user is redirected to the link http://example.com/home no issue still here but when I navigate to http://example.com/register nothing load except my header, footer, and sidebar my registration page does not appear. the same is the case with http://example.com/branch and http://example.com/userbranch
following is the code for my web.php file
<?php
Route::middleware(['auth'])->group(function (){
Route::get('/home', 'HomeController#index')->name('home');
Route::get('/branch','Branch\BranchController#index')->name('index');
Route::get('/userbranch','Branch\UserBranchController#index')->name('index');
Route::get('/course', 'Course\CourseMasterController#index')->name('index');
Route::get('/coursedetail','Course\CourseDetailController#index')->name('idex');
Route::get('/studentenquiry','Enquiry\StudentEnquiryController#index')->name('index');
});
Route::get('/', function () {
if(\Illuminate\Support\Facades\Auth::check())
return view('home');
return view('welcome');
});
Auth::routes();
Route::get('delete/{id}','Auth\RegisterController#destroy');
Route::patch('update','Auth\RegisterController#update')->name('update');
Route::patch('/update/branch','Branch\BranchController#update')->name('update');
Route::post('/storebranch','Branch\BranchController#store')->name('store');
Route::post('/storebranchuser', 'Branch\UserBranchController#store')->name('store');
Route::get('/delete/branch/{id}','Branch\BranchController#destroy');
Route::get('/userbranch/delete/{id}', 'Branch\UserBranchController#destroy');
Route::patch('/update/userbranch','Branch\UserBranchController#update')->name('update');
Route::post('/storecourse','Course\CourseMasterController#store')->name('store');
Route::get('delete/course/{id}','Course\CourseMasterController#destroy');
Route::patch('update/course', 'Course\CourseMasterController#update')->name('update');
Following is the code for RegisterUsersController to show the registration form
public function showRegistrationForm()
{
$userData = \App\User::all();
return view('auth.register',compact('userData'));
}
#section('content')
//
#endsection
the content between here in my blades register.blade.php, branch.blade.php and
userbranch.blade.php is not working and I am having just empty page except header, footer and sidebar just on shared hosting Each and everything works fine on local
Below is the code for .htaccess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Please help me in this regard, I have gone through a lot of tutorials and I just figured out that for some reason the code in between #section('content') is not loading;
Why you have copied files and pasted in shared hosting and changed default files of laravel?
I think you should read this answer and understand and then deploy your project
You can do it in 2 ways
First way (recommended but time taking to learn):
1-You should learn how to use git (version control system). when you learn about it then you will be able to save your laravel project on a git server. while learning git you will read about clone it will let you download your project from git to any server, any computer. It can be difficult to understand at first but believe me it is very useful and you should use it. visit github.com , gitlab.com or bitbucket.com.
2- when you have learnt how to use git then save your code to git. Then use git bash (for windows) or use terminal for mac/linux these are command line tools. Using it you can connect to your server where you want host your site. login using ssh to shared hosting server and go to public_html and clone your laravel prpject there. After cloning,go to project direcrtory create .env file and change it according to your settings, then run composer install (it will install all packages that your project requires). Then set root directory of your laravel project to your domain using cpanel and hit domain. You should be able to see your laravel working
Second way:(NOT recommended but quick)
Copy project folder except vendor folder to shared hosting server
open your pc terminal, connect to server, go to laravel project directory, install laravel.
set domain to your laravel project root directory and hit domain
I have recently deployed a Laravel project to my live web server via FTP (Filezilla). Inside my young1.org web root folder I have the subdomain folder bookings, which displays web content at http://bookings.young1.org. Inside that folder I have the folder, 'laravel' that contains my entire laravel application, and inside that folder there is a 'public' directory.
I have imported my local database to one of the database accounts on the live web server via phpmyadmin, and I have switched the 'DB' credentials to point to the new database inside the env file in the laravel project root (changing the following variables: DB_DATABASE, DB_USERNAME, DB_PASSWORD).
When I navigate to http://bookings.young1.org/laravel/public, the home page of my application appears, fine and dandy. However, when I click on any of the internal links (e.g. the login and register) buttons, I just get a series of blank pages, and none of the internal pages appear.
Would anyone be able to take a guess at what the problem might be?
I have tried altering the .htaccess file to look like the below, and changing my 'PATHS' variable inside public/index.php.
Thanks,
Robert
London, UK
// public/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
// public/index.php
require DIR.'/../laravel/bootstrap/autoload.php';
$app = require_once DIR.'/../laravel/bootstrap/app.php';
do you have SSH on the server? if yes did u install laravel as you're supposed to, also could you include the .env file contents, you can mask out the DB username and pass and the key you had to generate
never mind my mistake, i clicked on a link and got a SQL connection error (refused)
i still need to know if you installed laravel via SSH or that you just made the public folder the root, because if that's the case laravel cant help you with that (you need a VPS and not a webhost that only supports FTP as far as i know)
and to be sure
BE CAREFULL!!!
you have SQL connection errors that show credentials
Notice that your URLs work fine if you use index.php in them, i.e.:
http://bookings.young1.org/laravel/public/index.php/register
To allow URLs without index.php the mod_rewrite module on your Apache web server must be enabled.
First try to add this line in your .htaccess file of Laravel above RewriteEngine On:
Options +FollowSymLinks
This directive is needed to enable mod_rewrite in .htaccess context.
If it doesn't work after this, then you can check if module is enabled on your web server, the easiest maybe is to paste this in the beginning of index.php in public folder:
phpinfo();
Then open any page and search for mod_rewrite on the page, and see if you can find it under Loaded Modules. If not, you have to enable it.
To do that, if you can access through SSH you can do:
sudo a2enmod rewrite
sudo service apache2 restart
For more help on enabling mod_rewrite on Apache web server, check this answer.
I have a laravel 5 site on my localhost. I want to launch it on a shared host but the host is neither providing me with the shell nor it has composer installed. Can I still launch my website on this host? If yes then how? If the answer is no then what should I do?
Yes you can upload via file manager if you wish. Follow below steps
Check the server configuration of PHP 5.4 (this because every little change on .htaccess file may change that config)
Create a directory in the same level of public_html and put your project inside that folder (except public folder).
Put the content of public (L5) directly on public_html (don't overwrite the .htaccess file)
Inside public_html all files of public directory of Laravel 5 resides now.
Go to index.php and edit the line 22
#From this
require __DIR__.'/../bootstrap/autoload.php';
#To this
require __DIR__.'/../[framework-folder]/bootstrap/autoload.php';
and on line 36
#From this
$app = require_once __DIR__.'/../bootstrap/app.php';
#To this
$app = require_once __DIR__.'/../[framework-folder]/bootstrap/app.php';
Then edit the .htaccess file and add some lines
RewriteEngine On
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_URI} !^
RewriteRule ^(.*)$ /$1 [L]
Hope this works. Worked for me.
You can but you need to upload your local directory after a composer install, including vendor and .env using and FTP client. I wouldn't recommend it though, it makes development really hard. Maybe look into a paas like Heroku to get you started for free.
You also need to make sure that the shared hosting supports the following:
PHP >= 5.5.9
OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
as take from the docs
I am installing zend framework 2 on my shared hosting server. So far I did the steps below.
downloaded the ZF2 skeleton application and uploaded to my public_html. I have config, data, module, public, vendor, and init_autoloader.php in "public_html" folder on my server at this moment.
downloaded the full package (ZendFramework-1.12.9) and copied "library" folder and placed it under public_html/vender/ZF2/ so that it would work in init_autoloader.php
created .htaccess in which I entered below:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !.(js|ico|txt|gif|jpg|png|css)$ index.php
created index.php and placed it under public_html/. The content is below:
<?php
define('RUNNING_FROM_ROOT', true);
include 'public/index.php';
?>
I opened a browser and ran the url (pbm.pbmarketing.ca).
I have got a fatal error message below:
Fatal error: Class 'Zend\Loader\AutoloaderFactory' not found in /home/pbmarket/public_html/pbm/init_autoloader.php on line 44
What step did I do wrong? Could you please help me with this issue?
Once you have the skeleton app, use Composer to install ZF2 (see the instructions here: http://framework.zend.com/manual/2.3/en/ref/installation.html). Since you're on shared hosting you may need to do this before uploading the files. You don't need to do download ZF itself (and not ZF1!)
I've not used ZF2 on shared hosting, so can't help you with that side of it, but the error you're currently getting is because you don't have any of the ZF2 files.