CodeIgniter in Ubuntu 16.04 - codeigniter

I'm trying to move my CI project from my localhost in windows to Ubuntu. I'm working with:
In my cognfig.php
$config['base_url'] = '';
$config['index_page'] = 'index.php';
My Virtual Host:
<VirtualHost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin mymail#mymail.com
ServerName mywebiml.com
ServerAlias www.mywebiml.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.php
DocumentRoot /var/www/html/CLASE
</VirtualHost>
The root folder of the CI application is "CLASE".
Also, I added entries in /etc/hosts
MyIp mywebiml.com
MyIp www.mywebiml.com
The problem being, I keep getting the custom 404 error from CI when I try access my page.

First you MUST give $config['base_url'] a value. Use the following
$config['base_url'] = 'http://mywebiml.com/';
Second, make sure you are using the file and class naming scheme CI requires. Class files must be named in a Ucfirst-like manner, while any other file name (configurations, views, generic scripts, etc.) should be in all lowercase.
Bad:
some_class.php
Good:
Some_class.php
Class names should always start with an uppercase letter. Multiple words should be separated with an underscore, and not CamelCased.
Bad:
class someClass {
Good:
class Some_class {
File names and class names must be exactly the same - case-sensitive.
The above rules won't matter on a Windows based development environment but will on a linux system like Ubuntu.
If you are using .htaccess to rewrite URLs so the index.php is removed use the following.
$config['index_page'] = '';

Related

Laravel 8 project deploy to shared hosting - security issues and public_html folder

I was able to deploy my laravel 8 application as and addon domain on inmotion shared hosting based on the following article
https://medium.com/backenders-club/how-to-host-a-laravel-project-on-a-shared-hosting-via-cpanel-d955d32c528e
However, there are security issues with this as I can type mysite.com/.env and the file contents is listed in the browser showing the passwords.
I've tried many options to place the public folder of my laravel app into a public_html/public folder and none have worked for me. Anyone also getting this problem?
Addon domain Document root - /public_html/public
Laravel 8 application - /mysite.com (public folder contents moved to public_html/public)
Inside the public_html/public folder, the index.php file modified as follows:
require __DIR__.'/../../mysite.com/vendor/autoload.php';
$app = require_once __DIR__.'/../../mysite.com/bootstrap/app.php';
In browser I get 'No input file specified.'
bad practice if you try to move files inside public folder to root directory , any one can view the files that exist in the root ,
my advice to you ,return your files to the public folder and use one solution from this :-
first , you can make change the domain document root to public path
second you can create .htaccess file in the root folder and contain this code :-
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
i prefer the first solution.

Laravel: a simple route is redirected to /public folder

I'm beginning Laravel 5.2 and I'm stuck with this simple route:
Route::group(['prefix' => 'admin'], function(){
Route::get('/', function(){
return view('admin/login');
});
});
When I type http://<my_site>/admin I am redirected to http://<my_site>/public/admin/? instead of returning the view (I also tried with a simple return 'ok' and it keeps get redirected.
I can't understand where I am wrong, please a help?
EDIT: I found out that it's because I have an admin folder in my public one, that maybe causes conflict! But I'd like to keep the name admin to my assets folder, what can I do?
You should set up public directory as root direcotry in your web server configuration. For example, for Apache do this:
<VirtualHost *:80>
ServerName myapp.localhost.com
DocumentRoot "/home/vagrant/projects/myapp/public"
<Directory "/home/vagrant/projects/myapp/public">
AllowOverride all
</Directory>
</VirtualHost>
The thing is if your web server is pointed to another directory (for example, the Laravel's root directory), your app will never work properly.

url rewrite debian

I just got fresh debian VPS into my hands.
I installed url rewrite and simple things like this does seem to work
RewriteRule ^login$ /login.php
However this doesn't work:
RewriteRule ^cats$ /index.php?cat=cats
Anyone have idea why?
(it works on local xampp server + it worked on shared host I had)
Thanks
First of all make sure that you have mod_rewrite, and it's on. To do so, create an empty Php file, then add <? phpinfo() ?> and diplay it in your browser.
If it's "on" then you can go on.
If it's in a .htaccess file then try with / without the slashes.
RewriteRule ^cats$ /index.php?cat=cats
Or
RewriteRule ^/cats$ /index.php?cat=cats
And if that's not enough:
Two hints:
If you're not in a hosted environment (= if it's your own server and you can modify the virtual hosts, not only the .htaccess files), try to use the RewriteLog directive: it helps you to track down such problems:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)

Magento multi website controller

Is it possible to programmatically dispatch websites in Magento? Currently, I have a directory in the root of my site called /websites. In this directory I have subdirectories for each website, for example, site_a, site_b, site_c. Then each site subdirectory has a .htaccess and index.php with appropriate run code, for example:
$mageFilename = '../../app/Mage.php';
require_once $mageFilename;
Mage::run("site_b", "website");
in the index.php in /websites/site_b. While this works, I do wish to avoid doing file management in the filesystem. Anyone can give any recommendation on the best way to do this? Perhaps a script in /websites that stands in place of the individual site sub directories. Any help appreciated.
You have access to the $_SERVER variables in php and you can use these to determine the Mage::run("whatever", "website"); call, e.g.:
$whatever=$_SERVER['condition/url/whatever'];
// or use some cookies
if (isset($_COOKIE['dev'])) $whatever=$_COOKIE['dev'];
switch($whatever)
{ case "example.com":
case "www.example.com":
$_SERVER['MAGE_RUN_CODE'] = "example";
$_SERVER['MAGE_RUN_TYPE'] = "website";
break;
case "dev":
case "test.com":
$_SERVER['MAGE_RUN_CODE'] = "test";
$_SERVER['MAGE_RUN_TYPE'] = "website";
default:
$_SERVER['MAGE_RUN_CODE'] = "live";
$_SERVER['MAGE_RUN_TYPE'] = "website";
}
Mage::run($_SERVER['MAGE_RUN_CODE'], $_SERVER['MAGE_RUN_TYPE']);
In this way you only need one code base plus correctly configured settings in Magento backend to route to your different stores.
You can handle all in .htaccess file
mine looks like this:
#SetEnvIf Host www\.lenjerii\.com MAGE_RUN_CODE=base
#SetEnvIf Host www\.lenjerii\.com MAGE_RUN_TYPE=website
#SetEnvIf Host ^lenjerii\.com MAGE_RUN_CODE=base
#SetEnvIf Host ^lenjerii\.com MAGE_RUN_TYPE=website
#SetEnvIf Host www\.wildfashion\.ro MAGE_RUN_CODE=wildfashion
#SetEnvIf Host www\.wildfashion\.ro MAGE_RUN_TYPE=website
#SetEnvIf Host ^wildfashion\.ro MAGE_RUN_CODE=wildfashion
#SetEnvIf Host ^wildfashion\.ro MAGE_RUN_TYPE=website
This solution eliminate any other folders for your additional websites.
if I understand you correctly, what you need are some symbolic link: in each subdirectory, make symbolic link to the original installation. IE: ln -s ../app/ ./app.
Check out this tutorial

Reaching files outside od the documentroot scope

I'm writing a script to build a dynamic website,
the website is created by loading external components.
The DocumentRoot is location at /sites/website/public
the components directory is located at /sites/website/components
i wannna reach the data directory of each component depends on the requested url.
for example:
the url:
http://ibuildmywebsite/component-data/randomimage/demo/swan04090044_small.jpg
should fetch the file /sites/website/components/randomimage/data/demo/swan04090044_small.jpg
how can i achieve that ?
i would prefer a way that can be placed inside .htaccess (if there is one) instead of modifying the virtual host definitions.
Thanks!
Combine RewriteRule with Alias maybe ?
Alias /randomimage /sites/website/components/randomimage
RewriteRule ^component-(.*)/randomimage/(.*)$ /randomimage/$1/$2 [R,L]
(Won't work in .htaccess though)
You could probably also use Symlinks with:
Options +FollowSymLinks
And link dynamically components-*/randommimage/* to /sites/website/components/randomimage/*/*/

Resources