how to run symlink in laravel project inside add-on-domain? - laravel

I have an add-on-domain xyz.in inside public_html as 'public_html/xyz.in' and uploaded a laravel project inside xyz.in. However when I am uploading file using storage link the file is not getting saved inside public folder but the image is getting saved in storage folder. I am saving image in the following path
storage/app/public/images/
This is my htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
This is my web.php file inside routes.
Route::get('/clear-cache', function() {
$run = Artisan::call('config:clear');
$run = Artisan::call('cache:clear');
$run = Artisan::call('config:cache');
return 'FINISHED';
});
Artisan::call('storage:link');
Route::get('/', 'frontController#index')->name('homepage');

you can use the code I always use with symlink.
<?php
$target = '/home/public_html/xyz/storage/app/public';
$link = '/home/public_html/xyz/storage';
symlink($target, $link);
echo 'Symlink done!';
You can create a symlink.php file inside public_html/xyz/public and then go to the link.
Example:
http://www.xyx.com/symlink.php
** Don't forget to delete this file after you finish from linking the storage folder.

Related

laravel intervention image source not readable on deployment

Image class intervention not readable!
can anyone help me that why image not readable error show on deployment when i upload new photos to laravel project,
which is totally fine in development environment but in production has this error
enter image description here
AND this my intervention code in controller
if($request->hasFile('file')){
$nameWithExtension = $request->file('file')->getClientOriginalName();
$extension = $request->file('file')->getClientOriginalExtension();
$fileName = pathinfo($nameWithExtension, PATHINFO_FILENAME);
$newFileName = $fileName.'_'.time().'.'.$extension;
$upperExt = strtoupper($extension);
if($upperExt == 'JPEG' OR $upperExt == 'PNG' OR $upperExt == 'JPG' OR $upperExt == 'GIF'){
$request->file('file')->storeAs('public/doctor/',$newFileName);
$request->file('file')->storeAs('public/doctor_small/',$newFileName);
$request->file('file')->storeAs('public/doctor_small2/',$newFileName);
//Resize image here
$thumbnailpath = public_path('storage/doctor_small/'.$newFileName);
$img = Image::make($thumbnailpath)->resize(520, 668, function($constraint) {
$constraint->aspectRatio();
});
$img->save($thumbnailpath);
$thumbnailpath2 = public_path('storage/doctor_small2/'.$newFileName);
$img2 = Image::make($thumbnailpath2)->resize(100, 100)->save($thumbnailpath2);
}
}
Whenever I see this type of question, everyone answers that you should store it in the public folder of the project. says use this storage: link but it is not always like this, you should bear in mind that if you upload the folder in two different projects one public_html and another in a folder called for example my project things will be stored in the folder my project and laravel will search for them in public_html where they don't exist, a solution would be to put the whole project in public html by changing the .httacces this way
<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...
RewriteRule ^(.*)$ public/$1 [L]
RewriteRule ^ index.php [L]
</IfModule>

URL Segment in Codeigniter

In my codeigniter project, i am working around the url parameter. Its almost working but there is some problem in the view page which is loading.
I have set all the configuration as per my knowledge. But I doubt there must be some issue in the .htaccess or routes.php file.
.htaccess file --
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
routes.php --
$route['default_controller'] = 'home';
$route['home'] = 'home/index';
$route['faq'] = 'home/faq';
$route['privacy-policy'] = 'home/policy';
$route['doupnow-videos'] = 'home/videos';
$route['doupnow-audios'] = 'home/audios';
$route['morevideo/(:any)'] = 'home/morevideo/$1';
$route['moreaudio'] = 'home/moreaudio';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Controller Page --
public function morevideo($cat)
{
$result['list']=$this->Home_Model->displayVideosAll($cat);
$this->load->view('header');
$this->load->view('doupnow-video-more', $result);
$this->load->view('footer');
}
Now when i navigate to "http://doupnow.com/morevideo/latest", this page getting the parameter correctly and also displaying the data based on the parameter only but the view is not getting the html and css elements like the other pages.
Kindly give me the proper direction. Thank You.
On your site, when you're linking to a script or stylesheet, you link it by doing:
/js/script.js
But you need to give the full url like this:
http://doupnow.com/js/script.js

Remove default controller to url - Codeigniter

I would like to know how to remove the default controller from home url on codeigniter.
Here is my htaccess file
Options -Indexes
RewriteEngine on
RewriteCond $1 !^(index\.php|assets/|css|img|js|fonts|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
And here is my routes file
$route['default_controller'] = "pages/index";
If your site is:- http://www.example.com/
Default controller is: - homepage
Want to display the content of 'homepage' controller on 'http://www.example.com/'
So, first create 'homepage' controller as a default controller with following process:-
Reach to the routes.php file through path 'application/config/routes.php', then change '$route['default_controller'] = "welcome";' to '$route['default_controller'] = "homepage";'
And write down the contents which you wants to display on the 'http://www.example.com/', under the 'index' function 'homepage' controller

Codeigniter index.php page

I'd like to set as default page some script from views directory, for example \application\views\index.php and delete index.php file from the root of application. IS it possible? (I tried to change value of config['index_page'] to what i would like, but it gives me error that page not found).
Or maybe codeigniter has so strict project structure that i can't do such changes?
You can't delete index.php file from root directory, instead of that you can remove index.php from the url.
You have to define default controller first, then do follow steps
Have the.htaccess file in the application root directory, along with the index.php file. (Check if the htaccess extension is correct , Bz htaccess.txt did not work for me.)
And Add the following rules to .htaccess file,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Then find the following line in your application/config/config.php file
$config['index_page'] = 'index.php';
Set the variable empty as below.
$config['index_page'] = '';
That's it, it worked for me.
If it doesn't work further try to replace following variable with these parameters ('AUTO', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_URI', and 'ORIG_PATH_INFO') one by one
$config['uri_protocol'] = 'AUTO';
$config['index_page'] = '';
will do the trick
from now if you access your site like:
http://mypage.com
the default controller would be called
you can change it in routes.php file in your application/config folder
like:
$route['default_controller'] = "views/index";
Btw. your views.php controller in (application/controllers) should look like somehting like that:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Views extends CI_Controller {
public function index()
{
$data = "Text from controller's index method";
$this->load->view('myview', $data);
}
}
And your myview.php in (application/views):
<?php echo $data; ?>

url_suffix in codeigniter not working properly

I am new to Codeigniter and using Codeigniter 1.7, I created a .htaccess file in root directory with code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]
to remove index.php from urls, and added
$config['url_suffix'] = ".html";
to config.php file to provide default suffix for all pages. After that I created a controller test.php with this code:
class Test extends Controller{
function test(){
parent::Controller();
}
function index(){
$this->load->view('test');
}
}
and a view also:
<?php
echo anchor(current_url(), 'This Page');
?>
When I navigate to http://localhost/ci/test.html it works fine, but when I click the link auto generated by anchor() function in my view it goes to http://localhost/ci/index.php/test.html
How can I remove /index.php/ from urls generated by anchor() function?
Also when i point to home page
localhost/ci/index.html
it shows me a 404 Page not found error but when I point to
localhost/ci/index.php
it works fine. Why home page is not being converted to index.html instead of index.php?
You have to create a rewrite condition with htaccess.
To remove index.php, add this to the root folder .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*) /index.php/$1 [L]
If your loading Test as your default controller then this will be your base url
localhost/ci/
or
localhost/ci/test/
or
localhost/ci/test/index.html
Make sure to set your config.php to this
$config['index_page'] = ''
You should also be using Codeigniter 2.1 for proper php 5 support.
Also your constructor funciton should be like so if using php 5. Else stick with what you have for php 4.
public function __construct()
{
parent::__construct();
}

Resources