How to set frontend&backend yii2 turnkey? - php

I am a newbie looking forward to set yii2 and experiment with it.
I set a containter in proxmox with yiiframework turnkey.
Then installed adminlte and now I am trying to get backend and frontend work.. but I can't.
I tried with prettyUrls enabled and disabled but simply https://192.168.1.3/frontend/web/index.php or https://192.168.1.3/backend/web/index.php give me back the 404 error "The requested URL /frontend/web/index.php was not found on this server."
Everything is fresh and clean as just barely installed, except for this :
'view' => [
'theme' => [
'pathMap' => [
'#app/views' => '#backend/views'
],
],
],
'assetManager' => [
'bundles' => [
'dmstr\web\AdminLteAsset' => [
'skin' => 'skin-blue',
],
],
],
that is the adminlte integration.. nothing that could even screwed something up.
I tried to set up a .htaccess file in the root with this inside:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
and two different .htaccess files for frontend and backend....
even followed different guides like this one: https://devreadwrite.com/posts/htaccess-for-yii-2-advanced
But It seems that I do not have this frontend and backend separation but just 192.168.1.3 site...
Thanks a lot,
Waiting for some help.
Lordcroci

the frontend and backend are available when using the advanced template. To create a project with the advanced template you should use:
composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application
being yii-application the name of your project. After that you should initialize the project, using:
/path/to/php-bin/php /path/to/yii-application/init
After that, you should get the web folders and config files for both backend and frontend available, including the index.php
It's only after those steps are completed that you can change the prettyUrl in their respective config/main.php files (frontend and backend).
https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/start-installation.md

you can't access backend and frontend by these url you put in question
https://192.168.1.3/frontend/web/index.php or https://192.168.1.3/backend/web/index.php
use this
https://192.168.1.3/frontend/web/site/index.php or https://192.168.1.3/backend/web/site/index.php
1.first of all after installing yii2 by using this commant
composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application
2.you must use init command so index file will be available to access the url. After install project just enter to project folder and open terminal and enter command
./init
and select the development option. after this the index file will be available in web folder in both backend and frontend folder.
3.Create a database with any name you want and update common/config/main-local.php file by entering the database detail.
4.Go to your project folder and run command
./yii migrate or yii migrate
it will create two table in your database name users and migrate.
after this add the htaccess file to your backend and frontend's web folder
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
and enable pretty url in config file in backend and frontend and uncomment the url manager code.
5.after this you can access the backend and frontend by
https://hostname/backend/web/site/index.php and
https://hostname/frontend/web/site/index.php
but in the question you write this
backend/web/index.php
frontend/web/index.php
which is wrong.
Just access frontend and backend by this
https://hostname/backend/web/site/index.php and https://hostname/frontend/web/site/index.php
and you are good to go.

Related

How to deploy a Laravel-Vue project on shared server (GoDaddy)

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.

Deployment Of Laravel 5.6 project to shared hosting

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

How to host Laravel application in a sufolder along with normal php application?

I have a laravel application and a normal application. I want the normal application to run when user opens example.com/ but when the user opens example.com/laravel_application/ I want the laravel application to run. How can I achieve this. I tried various methods like creating symlinks but I seem to be always redirected to root directory (example.com/) e.g. when I open example.com/laravel_application/login
I am open to using apache or nginx.
you can add whole code in common laravel project and define different routes for
both normal and laravel for ex. when you call example.com/ define this route and
call it from controller. May be this will help.
It's easier to add a subdomain for Laravel app. Otherwise, you will have to create Laravel routes based on the example.com/laravel_app path.
There are two solutions:
Using .htaccess with mod_rewrite
Create .htaccess file on sub-folder where you put your laravel application.
and add the code in .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
You can add a index.php file containing the following code and put it under your root Laravel folder.
<?php
header('Location: public/');
?>

Deployed new Laravel project to live server - inner page links do not work

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.

How to fix '/' in caffinated moudule in laravel

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.

Categories