I'm using MAMP just for my development environment and haven't really understood the folder structure of /var/www/project-name/ on a web server. I'm wondering whether you're meant to point the web server to the htdocs folder or it's supposed to point to the root of the project folder?
The reason I ask is because libraries are meant to exist outside of the htdocs folder for security purposes, but how are they pointed to from the web application itself? Surely the web application can't access folders outside of the htdocs folder if the web server is pointing to the htdocs folder for the web application?
A simple solution is to have a folder structure like so:
/var/www/project-name/
+ webroot/
+ libraries/
Point your apache2 DocumentRoot to the webroot directory. Keep all the libraries that you don't want accessible from the web in the libraries directory. In your php code, use the include directive to access the libraries code.
The trick is to understand that php can include any file on your system it has read access to. A person browsing your website can only access files inside your webroot directory.
If you have multiple vhosts on the same server, it's pretty common to have each site in a directory under /var/www, and each of these have a htdocs folder, which is mounted as the web root. You can then have logs and application-specific libraries in a folder above the web root. Eg.:
/var/www/lolcats.com
/var/www/lolcats.com/htdocs
/var/www/lolcats.com/htdocs/index.php
/var/www/lolcats.com/lib
/var/www/lolcats.com/log
PHP can access any file in the filesystem for which the apache server user has the correct permissions. On a linux box running apache without virtual hosts, /var/www is a common place to use for your htdocs directory.
You place the libraries in PHP's include_path which is inaccessible to the general user.
It is a googd idea to map your local websites in directories in the same way as your domains work.
Often you have multiple websites on a single web hosting account, so setup virtual hosts to mirror the setup.
If your shared hosting is:
/var/www/root
/var/www/root/website1
/var/www/root/website2
/var/www/root/website3
Create 3 vitual hosts on your local PC but keep an identical file structure.
Also, use conditions in your config files to setup the site deifferently depending on the server file structure, to ensure the same config file works on both setups. This means you keep your one-step build process.
Related
I have several websites hosted in the same public_html folder of my Linux server.
I want that each folder cannot access the other folders, but only include some specific files.
Here is my server structure:
-> public_html
---> site1 folder
---> site2 folder
---> site3 folder
---> common scripts folder
If for example an hacker breaks site2 I need he cannot list the content of the public_html folder or access and run scripts from the other folders.
But in the same time I also need that for example site2 is able to include and run some specific files included in the "common scripts" folder.
Is it possible to achieve this just with a htaccess rule?
Thanks for the help.
no you can not achieve this just with a htaccess rule
it all depends on php handler, if it is dso or cgi then you can not isolate websites, a simple php shell will be able to access all websites and their data.
FCGI, suPHP or PHP-FPM can be used to run php securely with separate UID for each website.
you can also check chroot
First of all, you cannot achieve this through htaccess.
because if a hacker breaks into a site, then that hacker can have control over the complete server space where the current user-account(the account which hacker pass-through. ex: www user account) have access and permissions.
If you need a complete concrete solution, then create multiple users for your vps server and define access rules and permissions for each users and let their sites deployed into corresponding users space like
/home/user1/sites/site1
.
.
/home/user1/sites/site10
/home/user2/sites/site1
This above scenario is simple like a server being virtually splitted and sold to multiple users.
Ex: buying a shared hosting space from godaddy or hostgator
where godaddy virtually separates their server and sell them to multiple users.
each user can view and access their own space only and cannot access other users space eventhough they both reside in the same cloud server
I am new to web development and cPanel. Now I am developing a website which has a medium scale database and a configuration php file. I am using small business web hosting plan with cPanal and phpMyAdmin included. Currently I am developing my site using WAMP server installed in my own home PC. So my question is this.
When I am searching more information about my project, I saw that someone has mentioned;
DO NOT PLACE DATABASE AND CONFIGURATION FILES ON LIVE & PUBLIC FOLDER. PLACE THEM ON DIFFERENT DIRECTORY OR USE HASH BECAUSE THEY STORES DB USER NAMES AND PASSWORDS..!
So, I don't know what is a "Hash" all about and all I want is to place my database and configuration files more securely.
Therefore, please tell me where to place my database files and other important files on cPanel and how I write paths between database and PHP files on different locations..? ex: www.abc.com/db/...
On the cPanel File Manager, the home directory, the directory you're in is the one above the public_html or www. Place your private stuff such as passwords and whatnot in directories there. DO NOT place them inside of public_html or www as this gives the public access to those files.
You can find phpmyadmin in cpanel for databases
I have WAMP installed in a machine and I have only one application in the www directory. SO I want localhost to point to my application directly.
In short, if I hit the
http://localhost/
in my browser i want my application to open. I don't want my application url to be like
http://localhost/application/
Can anyone help me out to do the configuration changes.
Thanks,
Uttam Dutta
Put the files for your application in the directory that your DocumentRoot points to instead of in a subdirectory (called application in your example) of that directory.
This answer should also be helpful, if you'd prefer to keep your files where they are now and point the DocumentRoot to the files instead.
Also, you may consider making a virtual host for each of your projects. Read about creating virtual hosts for localhost here.
I have developed a python desktop application and application itself having setup page to change some configurations in the application and it is saved as a configuration file.
Now I need do to give web interface to change those configurations by using web browser remotely. But I need to change the same configuration file.
I can’t access any file outside the web root, So My first question is how can I edit that file which is located outside the web root.
more info : for web application I use LAMP stack and desktop application is python based.
someone suggest me to use CGI, Second question : Is that possible, if it is possible how I can I do it?
Probably by bind mounts (assuming Linux), so that the file is in it's original location as well as in the web root.
Or by priviledge separation. The web root sends a query to some worker job, that has access to all the needed files.
I have learned how to create a simple website with the Zend Framework. Now suppose I want to put it on some web hosting server. In my ZF project, I have a folder named public, which I want to appear as the root of the URL. I want my site to be visible and accessible as
http://www.mysite.com
while being served from a page like /public/index.phtml or similar.
How is this done?
If You want domain like www.mysite.com, u must buy somewhere one (for example ovh.org), there is not free *.com domain.
After that u could direct domain to your host computer (nice free hosting: 60free.ovh.org). There is PHP of course, so i think you could install Zend there.
You have to put the public_html files you're using with Zend_Framework in the root folder of your host. The host server will give you a folder which will be the root for that domain, put in there and you will not have /public/index.phtml in front of your domain name.
Do you already have a hosting server or are you looking for one?
Usually you can achieve your goal by using the tools provided by your hosting provider, some allow you to change the directory from which http://www.yoursite.com is server, set that to /public and you are done.
It really depends on the provider.
You'll need to deploy the entire Zend Framework directory structure to the host you end up using. In your Zend Framework directory structure, you have your public directory. This directory will need to be the one that your web server looks at as your document root. The setup for this is probably different based on which host you use. Some will have web interfaces and others will force you to edit an httpd.conf file.
I'm using Rackspace for our site and the default web location is /var/www/html/. We've deployed the entire site here so we have the following directories:
/var/www/html/application
/var/www/html/library
/var/www/html/public
/var/www/html/scripts
We then had to change our Apache config to point to /var/www/html/public instead of /var/www/html.