codeigniter folder structure on webserver - php

I want to upload code igniter folder to remote server. Should I upload codeigniter root folder to my public_html folder so I got following structure
public_html/
codeigniter/
application/
system/
....
or should I upload application system ... directly to my public_html,
and if I upload under codeigniter folder can I point somewhere in config to my codeigniter library in a way that my links remains without /codeigniter/

it's better to do like:
application/
system/
public_html/
index.php
for security reason, put your application and system folder outside your public_html

Form the user guide
For the best security, both the system and any application folders
should be placed above web root so that they are not directly
accessible via a browser.
So my setup is to have a custom public directory in the codeigniter codebase and have the index.php inside it.
And copy the .htaccess and index.html from either system or application folder to the codebase to forbid access to the base.

It will depend on the apache configuration on your server.
From my POV, it is better to have a structure like :
public_html/
codeigniter/
application/
system/
[...]/
Then, make your apache configuration point to this folder with something like :
<VirtualHost *:80>
DocumentRoot "path_to_the_folder/codeigniter"
ServerName yourDomain.loc
ServerAlias www.yourDomain.loc
<Directory path_to_the_folder/codeigniter/ >
#Your options
</Directory>
</VirtualHost>
and your /etc/hosts file look like :
127.0.0.1 yourDomain.loc
127.0.0.1 www.yourDomain.loc

You would typically upload everything under /codeigniter. So you would have a directory structure like:
- public_html
- images
- js
- system
- application
- other codeigniter folders

Related

laravel 5.2 internal server error

My laravel project work good in localhost by artisan serve commend.
Now i'm trying to host it on web host.
I upload my project under public_html and copy all files from public folder i also edit app.php 'debug' => env('APP_DEBUG', true), for showing the error.
i edit index.php
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
but it still give a 500 Internal server error back.
I also try an another way,
Upload my project into root directory except public folder and upload public folder into public_html directory .
and i edit index.php as
require __DIR__.'/laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/laravel/bootstrap/app.php';
i can't find what wrong with my code.
how can i deploy my laravel 5.2 project into a web hosting.?
No No no.. You need to achieve the second option with some improvements. Let me explain it to you. A laravel application looks like:
app/
config/
public/
public/index.php
.env
composer.json
artisan
Right? good, now a web host's structure looks like:
/home/user/
/home/user/public_html/
But the structure above does not fit our needs because is public/ folder that should be accessed instead of public_html/. So.. the first step is to upload your project, lets say, like these:
/home/user/home/project/app/
/home/user/project/config/
/home/user/project/.env
/home/user/project/composer.json
/home/user/project/public/index.php
The next step is decide if you want your project as a main domain, or as subdomain.
If your laravel's project will serve as a main domain just edit apache's config file httpd.conf and set the following rules:
DocumentRoot "/home/user/project/public"
...
If you want you project as a subdomain, just edit the apache's config file httpd.conf and add a virtual server like this:
Listen 80
<VirtualHost *:80>
DocumentRoot "/home/user//project/public"
ServerName my-project.example.com
# Other directives here
</VirtualHost>
With this directive you are telling to apache Hey! when people visits my-project.example.com show them the content of my site under /home/user/site/public.
IF you are using cpanel, just create a subdomain and point it to /home/user/site/public
That is all, you do not need to hack any project's files like index.php, that is a bad practice.

Only getting list of files on /var/www/html folder

I'm trying to host my laravel app on an ubuntu machine
I added the laravel app to the /var/www/html folder which is root directory for my domain on apache conf file. But when I access my domain, I only get the list of files in /var/www/html folder. When I insert a index.html file for test, it works perfectly when I access the domain. What can be happening?
Your apache needs to be configured to recognize index.php as well as index.html. This is done by setting the directoryindex in the httpd.conf file.
Laravel is served out of index.php inside the public folder.
You are getting your list of files because your domain is pointing to var/www/html which contains the root of your Laravel application and not the public directory which contains index.php.
If you go to www.yourdomain.com/public you will find your application served correctly if your apache is set up to recognize index.php which it should be.
To fix this up so you don't need to use public inside the URL you can just edit /etc/apache2/sites-available to point your directory to /var/www/html/public and then you will be able to access it through www.yourdomain.com.

Apache: No such file or directory

My website is on apache server.
Path: /var/www/example.com/public_html
I am trying to access file in public_html folder.
PHP
require('/application/config/development/dev_config.php');
ERROR
PHP Warning: require(/application/config/development/dev_config.php): failed to open stream: No such file or directory in /var/www/example.com/public_html/index.php on line 53
When I tried to do this:
require('application/config/development/dev_config.php');
It's running fine. But, I used forward slash in all over the place in my project. Is there any way to change this setting in .htaccess file? so, I can access it by using /.
Apache Config File
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Apache and PHP Understand / Differently
Apache views your web root as your root folder (/var/www/example.com/public_html/), whereas PHP is able to access your entire system (so '/' means '/'). That means that while
...
really means /var/www/example.com/public_html/home.php,
header('Location:/home.php');
would mean a home.php file in the root directory of your server's system.
Solution
The easiest (IMHO) way to avoid typing out the entire web directory structure when indicating a web file to PHP is to use the $_SERVER['DOCUMENT_ROOT'] variable. This queries Apache to find the path to the web directory root, and you can add the rest of the file path as though you were talking to Apache. For example:
header('Location:'.$_SERVER['DOCUMENT_ROOT'].'/home.php');
would be understood by PHP to mean /var/www/example.com/public_html/home.php.
/application does not exist, the actual folder you want is:
/var/www/example.com/public_html/application/config/development/dev_config.php
By beginning with / you are telling the system to look at the very root path of your file system (where/var is for example).
The reason application/config/development/dev_config.php works is as you are calling the folder relative to the current folder as you are already in public_html

Setting the DocumentRoot in Laravel

I am wanting to host multiple laravel projects as subfolders within a domain, so for one project the laravel code base would reside at somedomain.com/project1 and another project at somedomain.com/project2, and so on.
Is there a way to tell laravel that the document root is actually in a subfolder of the top level directory of the domain rather than the top level directory itself?
I had previously setup each project as a 2nd level domain with each having it's own DocumentRoot config in Apache VirtualHost directives (such as project1.somedomain.com & project2.somedomain.com), but I want to switch to using subdirectories and have one top level directory as the Apache DocRoot and the individual projects as subfolders.
What is the best way to do this?
Yes this is possible. There are a few howevers though.
First off, normally you'd put laravel's public directory as your webserver's document root. In this case you'd rename the public directory to be the name of the subfolders.
You also need to ensure that your Laravel code (i.e. not public) is an extra level back from the public folder (so you keep your code away from possible access). You'll probably want to put the two separate apps in their own folders too. Now change all the paths in index.php and the paths.php file to make sure that each application points at the right supporting code.
You'll end up with something like this:
/path/to/docroot-parent/
app1/
app/
bootstrap/
paths.php ('public' => __DIR__.'/../../actualdocroot/app1')
...
app2/
app/
bootstrap/
paths.php ('public' => __DIR__.'/../../actualdocroot/app2')
...
actualdocroot/ ← webserver points here as docroot
app1/
css/
js/
index.php (points to ../../app1/bootstrap/autoload.php and ../../app1/bootstrap/start.php)
app2/
css/
js/
index.php (points to ../../app2/bootstrap/autoload.php and ../../app2/bootstrap/start.php)

Storing multiple PHP apps on one domain

I have got myself a server, and on it I'd like to host my portfolio. My portfolio will be built using a tiny PHP MVC framework I wrote myself. This will be accessed by going to domain.com (for instance).
Now, on my portfolio, I want to host all of the other pieces of work I do. These will also be PHP MVCs. So, for example, domain.com/app1, domain.com/app2 and so on. However, as you probably know, the nature of a PHP MVC means that some files are not meant not be in the DocumentRoot (talking about Apache here). So, if you wanted to store all of your work like this, how would you go about achieving it?
An example directory structure of one of my apps:
/application
/views
/models
/controllers
/public
/js
/css
Therefore domain.com/css should point to that apps css folder which is in the public folder, as should domain.com/app1/css point to its css folder in its public folder.
I'm just trying to work out a good way of organising my work. I would really appreciate anyones thoughts!
I would suggest that you use an apache alias for each new application :
http://httpd.apache.org/docs/2.2/mod/mod_alias.html#alias
You will keep only one Virtual Host :
<VirtualHost *:80>
ServerName domain.com
Alias /app1/ /var/www/app1/public/
Alias /app2/ /var/www/app2/public/
</VirtualHost>
Well
I would have my folders something like this:
/lib (main portfolio lib)
/projects
/project1 (main lib for project 1)
/public_html (main portfolio public root)
/projects
/project1 (main public root for project 1)
The only thing here is that for project 1, you'd have to set the lib folder to
../../../lib/projects/project1
as opposed to it's standalone
../lib
I hope that helps

Categories