Sharing same code accross different web applications - php

I have 106 PHP files present in folder. This folder is included (copied the folder in application folder) in all the web-application, which I have develop but the problem is, if I implement any change in code than I have to replicate that change in all the applications.
Is there any way through which I can share this folder in all web-application or domains which are hosted on same server?
I have tried using outside htdocs folder but things does not worked as I thought.
Kindly Guide.

Yes you can (assumed you have an linux server), if your domains are stored within the same server you can place your php files outside the html of one of them and then use something like this
include ("/home/user/domain/folder/file.php");
to include your php into another one
example
mydomainhost.com has the folder php with the 106 files
in your testdomain.com you include
include ("/home/user/mydomainhost.com/php/file.php");
user = your webserver account name
hope this helps you

Related

Where to place my database files and other important (configuration php) files on cPanel?

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

Edit a file outside the web root

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.

Setting up Yii on Shared Server

I wish to use a PHP Framework such as Yii, however, it seems to set this up I need access to a terminal or console. Unfortunately my only access to the server is via an FTP client as it's shared hosting.
Does this rule Yii out as a framework?
all you need to do is
1 - have a copy of yii framework folder
2 - generate a new yiic webapp folder
3 - upload both folders, the framework folder can go to some hidden place yoursite.com/wawa/framework/yii, and you can just upload the files in your webapp folder to yoursite.com/
4 - edit the index.php in your generated web app, so it know where your framework/yii folder is. than you are set
5 - just make different copy of your webapp folder, so you don't need to generate them if you dont want to. just use different names, wont make a difference, as long as the webapp index.php knows where your framework folder is, than it will work
According to this post you can generated all files on your computer and then just upload the files to your shared hosting.
You only need a terminal for developing on your local server (it isn't a good idea to develop directly on a shared server). To use it on a shared server just upload it.
In the strict sense you don't need a terminal. You could write your files yourself. The yiic program only creates a couple of php files.
I am first in Yii. Installed the application locally. FTP-ing the application to the share server in directory /home/sloki/user/h11741/sites/example.com/www then create abcd directory within /www and put framework into it.
Edit your index.php line 4 to be: $yii=dirname(FILE).'/abcd/framework/yii.php';
You will get error message like this
Application runtime path "/home/sloki/user/h11741/sites/example.com/www/protected/runtime" is not valid. Please make sure it is a directory writable by the Web server process.
Change permission of directories /protected/runtime and /assets to 777. Test the web, when success change again permission both directories to 775.
Gut lak.

Zend and web hosting - subdirectory appearing as root

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.

/var/www/ folder structure for PHP project

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.

Categories