I am new to Laravel 5 and have realized that a lot has changed, I am more familiar with Laravel 4. I just tried uploading my site to a live VPS, I managed to change the URLs in index.php and server.php but I keep getting these errors:
Which makes me believe there was something else I was supposed to change that I did not because these files are indeed there and my application works just fine on my localhost.
Also with the exception of my home page, the rest of the pages say not found when I click on their links.
This is my document structure:
index.php
<?php
require __DIR__.'/../*********/bootstrap/autoload.php';
$app = require_once __DIR__.'/../*********/bootstrap/app.php';
$kernel = $app->make('Illuminate\Contracts\Http\Kernel');
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
server.php
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylorotwell#gmail.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' and file_exists(__DIR__.'/../public_html'.$uri))
{
return false;
}
require_once __DIR__.'/../public_html/index.php';
Following step you have must followed to move local to live server in Laravel.
Move all public folder data into root directory
In index.php change path to
require DIR.'/../bootstrap/autoload.php'; to require DIR.'/bootstrap/autoload.php';
AND
$app = require_once DIR.'/../bootstrap/app.php'; to $app = require_once DIR.'/bootstrap/app.php';
and set file permission to 744
In .htaccess file add following code after RewriteEngine On.
RewriteBase /
Change parameter in .env file.
Related
I wanna deploy my application on shared hosting on Cpanel where the primary document root has public_html but Laravel project public
You have to follow 2 steps to change your application's public folder to public_html then your can deploy it or anything you can do :)
Edit \App\Providers\AppServiceProvider register() method & add this code .
// set the public path to this directory
$this->app->bind('path.public', function() {
return base_path().'/public_html';
});
Open server.php you can see this code
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
Just Replace it with :
if ($uri !== '/' && file_exists(__DIR__.'/public_html'.$uri)) {
return false;
}
require_once __DIR__.'/public_html/index.php';
Then serve your application with php artisan serve, you also can deploy it on your Cpanel shared hosting where primary document root public_html
You can rename your public directory to whatever you want and tell Laravel to use the current directory path as the public path. Just navigate to the index.php inside the public folder (or whatever you renamed it to) and add the following code after the $app definition:
$app = require_once __DIR__.'/../bootstrap/app.php';
/* *** Add this code: *** */
$app->bind('path.public', function() {
return __DIR__;
});
/* ********************** */
there, idk if you have same problem like me, my cases is i using shared hosting, and i deploy it in my main domain. i place all my files in the root, my problem is the storage:link keep between public, not public_html (because its default by the hosting) so what i need to do i changhe the link using this code :
Before :
'links' => [
public_path('storage') => storage_path('app/public'),
],
After :
'links' => [
app()->basePath('public_html/storage') => storage_path('app/public'),
],
I hope it can help few people :)
Just Rename the "public" folder to "public_html" and it will work.
No changes are required in the code. Tested in Laravel 8.
my two cents :) What helped to me was:
Open LaravelService/vendor/laravel/framework/src/Illuminate/Foundation/Application.php and change publicPath() method to return public_html.
public function publicPath()
{
return $this->basePath.DIRECTORY_SEPARATOR.'public_html';
}
Then if you are using webpack also change the output folder:
const output = 'public_html';
mix.ts('resources/js/web/App.ts', output + '/js/web').setPublicPath(output).react();
This helped to me. Only issue is that it is probably not recommended to change Application.php as it is part of Laravel framework and after updating it, it will be probably erased so you have to put it back.
I have the following script:
// Initialize Joomla framework
const _JEXEC = 1;
// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}
// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';
// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';
/**
* Cron job to trash expired cache data.
*
* #since 2.5
*/
class DoCron extends JApplicationCli
{
public function doExecute()
{
echo 'ok3';
$this->out('Fetching updates...');
}
}
JApplicationCli::getInstance('DoCron')->execute();
I have added this in CPanel with a Cronjob and get the results of excecution by e-mail.
Now I hoped for an e-mail with 'ok3' or 'Fetching updates...' but none of that all. I do get an e-mail but it is an reference to php excecution.
When I add an 'echo ok' tag right before:
JApplicationCli::getInstance('DoCron')->execute();
I get that 'ok' as a result in the e-mail.
Any thoughts on what goes wrong here? The script is based on general scripts coming with joomla 3.6.5. Those scripts also give no result.
I had the same problem. It turns out that the default php binary for most hosts is the PHP CGI. Running under PHP CGI results in no stdout, stderr and stdin which is why you are not seeing the correct output.
Instead, check your CPanel documentation and look for the CLI version of PHP. It is most likely called php-cli. For example, I had to run a cron job for a Joomla CLI app and found the following to work:
/usr/bin/php-cli /path/to/joomla/cli/my-cli -a b -c d --verbose
I have a few subdomain in my laravel 5 application, each sub domain have a specific configuration, like mail, nocaptcha, etc.
how to set .env file to work with my-specific subdomain ?
Yes, you can use separate .env files for each subdomain so if you use env variables in your config it will work without great modifications.
Create bootstrap/env.php file with the following content:
<?php
$app->detectEnvironment(function () use ($app) {
if (!isset($_SERVER['HTTP_HOST'])) {
Dotenv::load($app['path.base'], $app->environmentFile());
}
$pos = mb_strpos($_SERVER['HTTP_HOST'], '.');
$prefix = '';
if ($pos) {
$prefix = mb_substr($_SERVER['HTTP_HOST'], 0, $pos);
}
$file = '.' . $prefix . '.env';
if (!file_exists($app['path.base'] . '/' . $file)) {
$file = '.env';
}
Dotenv::load($app['path.base'], $file);
});
Now modify bootstrap/app.php to load your custom env.php file. Just add:
require('env.php');
after
$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/../')
);
Now you can create separate env files for each domains for example if you use testing.app, abc.testing.app and def.testing.app you can have .env file for main domain (and for all subdomains that don't have custom env files) and .abc.env and .def.env files for custom env variables your your subdomains.
The best solution I found is to use .htaccess plus env variables.
In .htaccess add these lines:
<If "%{HTTP_HOST} == 'sub.domain'">
SetEnv APP_DOMAIN sub
</If>
In bootstrap/app.php add after the app initialisation:
//own env directory for separate env files
$app->useEnvironmentPath( realpath(__DIR__ . '/../env/') );
//separate files for each domain (see htaccess)
$app->loadEnvironmentFrom( getenv('APP_DOMAIN') . '.env' );
Create a new directory called "env" in your Laravel root and add your config files as:
"sub1.env",
"sub2.env" ..etc
(Of course you can keep it in your root as is currently, but for many subdomains it's better to move into a directory => looks much cleaner => everyone's happy! :) )
You can’t. Each subdomain will be running in the same environment.
If you want per-subdomain configuration then your best bet is to either create a configuration file in the config directory with each subdomain’s settings, or use a database approach.
I had the same issue, Based on #Marcin's answer I built this one (Works with laravel 5.2.X)
I added in the bootstrap/app.php
if (isset($_SERVER['HTTP_HOST'])) {
$hostArray = explode('.', $_SERVER['HTTP_HOST']);
//if the address is a subdomain and exist the .xxx.env file
$envFile = sprintf('.%s.env', $hostArray[0]);
if (count($hostArray) > 2 && file_exists(sprintf('%s/%s', $app['path.base'], $envFile))) {
$app->loadEnvironmentFrom($envFile);
}
}
after
$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/../')
);
I hope that helps someone
Greetings
I installed HMVC by wiredesignz but the routes from application/modules/xxx/config/routes.php didn't get recognized at all.
Here is an example:
In application/modules/pages/config/routes.php I have:
$route['pages/admin/(:any)'] = 'admin/$1';
$route['pages/admin'] = 'admin';
If I type the URL, domain.com/admin/pages/create it is not working, the CI 404 Page not found appears.
If I move the routes to application/config/routes.php it works just fine.
How do I make it work without putting all the admin routes in main routes.php?
I searched the web for over 4 hours but found no answers regarding this problem. I already checked if routes.php from modules is loading and is working just fine, but any routes I put inside won't work.
I found a way of making the routes from modules working just fine, I don't know if is the ideal solution but works fine so far:
open your application/config/routes.php and underneath $route['404_override'] = ''; add the following code:
$modules_path = APPPATH.'modules/';
$modules = scandir($modules_path);
foreach($modules as $module)
{
if($module === '.' || $module === '..') continue;
if(is_dir($modules_path) . '/' . $module)
{
$routes_path = $modules_path . $module . '/config/routes.php';
if(file_exists($routes_path))
{
require($routes_path);
}
else
{
continue;
}
}
}
the following solution works fine even if config folder or routes.php is missing from your module folder
Here's the thing: the module's routes.php only gets loaded when that module is "invoked", otherwise CI would have to load all route configurations from all modules in order to process each request (which does not happen).
You'll have to use your main application's routes.php to get this to work. You aren't using the pages segment in your URL, therefore the routing for that module never gets loaded.
I know that's what you wanted to avoid, but unfortunately it's not possible unless you want to get "hacky".
Here's the routing I use to map requests for admin/module to module/admin, maybe you can use it:
// application/config/routes.php
$route['admin'] = "dashboard/admin"; // dashboard is a module
$route['admin/([a-zA-Z_-]+)/(:any)'] = "$1/admin/$2";
$route['admin/([a-zA-Z_-]+)'] = "$1/admin/index";
$route['(:any)/admin'] = "admin/$1";
You just need this https://gist.github.com/Kristories/5227732.
Copy MY_Router.php into application/core/
index.php
$admin_cookie_code="1234567890";
setcookie("JoomlaAdminSession",$admin_cookie_code,0,"/");
header("Location: /administrator/index.php");
.htaccess file
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/administrator
RewriteCond %{HTTP_COOKIE} !JoomlaAdminSession=1234567890
RewriteRule .* - [L,F]
i used this code but it's not working...
page will be redirect to administrator but www.domain.com/administrator is also accessable
I got tired of searching an answer for this one and just made a PHP code that will redirect if the visitor gets into the /administration folder without the security key or as a registered user:
Just place this code at the end of the index.php file on your administration folder (/administration/index.php) before the 'echo' instruction:
/* Block access to administrator
--------------------------------------------- */
$user =& JFactory::getUser();
$secretkey = 'mysecretkey';
$redirectto = 'location: yourdomainurlhere';
$usertype = 'Registered';
//Check if the user is not logged in or if is not a super user:
if ($user->guest || (!$user->guest && $user->usertype != $usertype) ) {
//Check if the secret key is present on the url:
if (#$_GET['access'] != $secretkey) { header($redirectto); }
}
/* --------------------------------------------- */
After you will be only able of accessing your site using:
mysite.com/administrator/?access=mysecretkey
Tested on Joomla 1.5 and Jooma 2.5, worked well for both.
I explain it a little bit more on my page:
https://www.infoeplus.com/protect-your-joomla-administrator-folder/
Are you trying to hide the administrator URL ? Here is what I'm using :
http://extensions.joomla.org/extensions/access-a-security/site-security/login-protection/15711
You can find more extensions here : http://extensions.joomla.org/extensions/access-a-security/site-security/login-protection
http://extensions.joomla.org/extensions/access-a-security/site-security/login-protection
you can use this protect your admin login.
this is really esay and nice extension.