Codeigniter - setting up directories and files permissions (chmod settings) - php

Since i don't think i got right permissions all over my application folders and files is there anyway to check the right permissions allover them?
I mean, does anyone knows/has a standard/tutorial/link to follow for Codeigniter to set chmod permissions?
thanks, any help appriaciated!
NB: when i say allover i mean from the root to all files the application & system folders contains
Also to specify little bit, i think i got problems with permissions, cause i passed my application through different OS and for example macosx setted different permissions on directories than windows etc... so it's sort of a hell actually
This is my app schema:
/project
/application
/system
/css
/img
/vendor
index.php
.htaccess

You want to:
chmod -R 0644 application system index.php
Assuming that CI is installed in the web root, with the application/ and system/ directories residing therein, which is the default setup.
What I typically do is put the application/ and system/ directories outside of the web root when I use Codeigniter, at which point you need to edit your index.php file to reflect that:
$system_path = '../system';
$application_folder = '../application';
Note, you'd be adding the ../ (and also need to move those directories one level down) but I digress. The permissions for each directory should be 0755 and for each .php file 0644, wherever you end up putting them. This includes any vendor, 3rdparty, sparks, etc, and any custom asset locations.
If using a templating engine of some sort, good setups will work with 0755 folder permissions at the location where the engine writes its output and intermediate output if applicable. If you find that breaking, find a host that supports suexec so that you don't have to make those locations 777 (or world writeable).
This is most easily done using a terminal (SSH), but should also be easily possible with whatever file manager thingadongdong your host provides.

change the permission of your codeigniter folder with this command:
$ sudo chmod -R 755 /var/www/html/Codeigniter_folder_name

Related

Some of the directories are accessible from public URL. How to avoid this in yii

In my Yii web application some of the directories are accessible from the public URL (main directory or application folder) like js, css, images etc. How to avoid this problem. This is a major security issue, but I don't know how to fix this. Please help me...
Thanks in advance...
If you're using Apache, you can restrict access to directories doing the following:
Create a .htaccess file in your directory so path/to/directory/to/deny/.htaccess
Open .htaccess and add Deny from all
You have to turn of apache directory listing. Use the link below.
How do I disable directory browsing?
Then change all files and folders permissions of a directory to 644 and 755.
Change all files and folders permissions of a directory to 644/755
Let me know if you need help
Here is some instructions given in documentation.
1) It's important that the directory be writable by the webserver user so that Yii can publish the resources there when needed.
2) When a project has multiple versions (production, testing, development, etc.) do not copy the assets/ folders from one area to another; allow Yii to deploy them automatically in each area.
3) Do not manually edit any file under assets/ - if you have a real need to make a change, find the publishing module, edit the source, delete the subfolder under assets/, and let Yii re-publish the updated files.
4) Do not reference names under the assets/ folder directly (say, to get at some other module's assets). If you need to use that
5) Do not add the contents of the assets/ folder to any source-code control system; these files have master source in other places.
6) It is safe to delete everything under assets/. Yii will re-publish the assets if they are not found under assets/.
Hope it will help you :)

How to redirect to upper directory with .htaccess

I have a VPS and use PHP 5.5 and Apache 2.2 on a 64bit CentOS.
I have many domains on this VPS that used a shared library named core.
each Domain redirect to a directory with same name in apache html's directory. to be clear, this directory's structure is like this:
cd /var/www/html/
ls
core
site1_dir
site2_dir
site3_dir
site4_dir
...
for example http://www.site1.com root directory is /var/www/html/site1_dir
but there are many files and libraries in core that can't be address like this:
http://www.site1.com/../core/etc
so i created an empty folder, named core in each site's directory and i want to put a .htaccess file in them, in ordor to access core contents in each domains. for example:
http://www.site1.com/core/js/script.js must be a direct link from /var/www/html/core/js/script.js .
creating this .htaccess file is my question, and any other given options will be useful for me.
You should be able to create a symlink in each dir to the upper core dir and then work the files that way.

File structure for dev server and repo

I have a development server at dev.mysite.com and I am working with coda and git to make commits and pushes to the repo which has a developmenet branch that points to my dev domain.
The file structure as of right now is this. As of right now does anyone see anything that I should reconsider changing. I'm asking this because of having a public_html inside the dev folder or what. With this setup currently when I load dev.mysite.com it shows the index of / which shows .gitignore, .git, and public_html.
../
/dev
/mysite.com
.git
.gitignore
/application
/public_html
/assets
index.php
/system
/mysecondsite.com
/application
/public_html
/assets
/index.php
/system
/sites
/mysecondsite.com
/application
/system
index.php
Does anybody have any ideas?
If you want to have a development environment and a production environment. While having the core files for CI outside of a public_html. You have to redefine your document root. I assume you are using a server the comes with cPanel as your means of administration for your server.
So that said, you go into your cpanel and where you defined your dev subdomain, you should be able to edit the document root folder. So on the server in your dev folder you will add a public_html like I gather you already have from the example above. And with your current folder settings for dev you add /public_html to the string that is the folder path now.
Once you do that allow a minute or two for it to delegate to the server from cPanel. And move your folders around as you see fit.
From there, you find the root index.php and open that up, find the references for your application folder and your system folder and change them to match the paths they should be looking for now. Likely using relative paths.. ie: ../../applications for example. Save your index.php
Assuming you have done everything in general correct your copy of CI should load correctly as it did when you didnt have everything in the folders split up like you want..

Access separate docroot in apache

I have a site on a server running Apache2 that resides at docroot /var/www/html. I want to access some of the files on a separate site at docroot /var/www/vhosts/othersite. Is there a way to access these files from the first site?
Thanks,
Chris Birk
You can include them using the include and require calls, or use symlinks to create a soft link in project 1 from project 2. These obviously depend on what you're actually trying to accomplish.
Edit: Oh, also, you could potentially add the folders you want to PATH.
The right way to do this is with mod_rewrite, and there are several ways of mapping URLs to different paths in the documentation here.
The cheatin' way of doing it would be to create a symbolic link from the directory outside the document root to a directory inside the document root, making sure the user Apache runs has can read that directory, and follow symlinks is turned on.
Yet another way of doing it would be to create a subdomain as a VirtualHost, with a document root of that other directory.

mkdir(folder_name) with 755 permission in php

I have my web application hosted in /var/www folder. I am creating a folder from one of the PHP scripts of the web application. The default permission of the created folder is drwx------, i.e. 700. But I want that folder to have at least 755 permission.
Up to now I tried: mkdir($path, 0755) and chmod($path, 0755) PHP functions but without any success.
Does anybody know how to solve my problem please?
Millions of thanks beforehand.
Have you tried changing the umask ?
Have a look here: http://nl3.php.net/manual/en/function.umask.php
The easiest way it to:
$oldmask = umask(0);
chmod($path, 0755);
umask($oldmask)
Since you have default permission of 700, which means the parent directory (the directory in which you are trying to create the folder) do not have rw permission for group owner or other users. Most often the running demon(httpd) is not the owner of the parent folder and hence cannot modify the directory.
In simple terms, the php script do not have access to modify or add new directory. You need to change the permission of the parent folder to at least drwxrw-rw- (or 0755).
Use ssh, cpanel or ftp client to do this. If you do it using php script you will end with the same problem again, as parent of parent will have again 0700. ;)

Categories