Changing directory paths of links in one place - php

I've got a website which I need to move across to another server, however i've got a problem with the directory paths and how they've been setup throughout the whole site.
So on every page, there're includes that look like the following
<?php include($_SERVER['DOCUMENT_ROOT'].'/views/includes/header.php'); ?>
This setup works perfectly fine on its own server because the DOCUMENT_ROOT is fine, however, the issue i've ran into is that i've just brought this down onto my localhost where the DOCUMENT_ROOT is
/Applications/MAMP/htdocs
when i need it to look like this
/Applications/MAMP/htdocs/website-name
Is there anywhere in the Perch CMS or .htaccess where i can perhaps change the DOCUMENT_ROOT or otherwise without having to amend every single link?
Thanks.

If you have mod_rewrite activated in Apache, you could use a rewrite rule in .htaccess.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
$_SERVER is a global variable. You could also override it in an entry point PHP script.

I guess you're using the free MAMP where setting up hosts is a manual task? Now you're running the site in a subdirectory of the root, right?
I strongly recommend always running the CMS in the root. Running CMS in a subdomain is always trouble, in my experience. Also, you want your local and remote setup to be as similar as possible.
With MAMP PRO it's very easy to set up multiple roots, it's a good investment to avoid the hassle with manual apache configs. Works flawlessly.

Related

How to swap from XAMPP to cPanel

I have a php website that I wrote and is functioning with XAMPP. I would like to transfer this to use cPanel. When using xampp, I had to put all of my files in htdocs folder for it to work properly. What is different now that I am using a different server?
I believe that I have finally figured out what my problem is. I am assuming too much.
When working from xammp in eclipse with localhost/project, if I want to add a file "test.php" I simply add it, save it, and then when I type localhost/project/test.php, there is it. This does not seem to be how cPanel works. Do I need to manually update it somehow? If so, how do I do this?
Also I am using mysite.com/~lamar/test.php which is how it is set up in cPanel. test.php is in S:/Lamar/www/test.php. This may also be the source of my problem.
Any ideas? As of right now I cannot even access any page of my project
Depending on your host, you may need to look for a specific folder, although many times you can just put your files in the root directory that you're taken to once you FTP into the system.
If you login and see a www, htdocs, public_html, httpdocs, or html folder, place your files there.
With CPanel you have to put your files into the public_html folder. As said in the comments, depending on your hosts configuration, it might another folder - in your case www.
The problem that I was having is that Eclipse was not updating to the server. So no matter how much I changed in the files, they were not being reflected on the site. I am using Dream Weaver now instead.

Linux : Eclipse PDT and running as PHP Web application

I installed Eclipse PDT for PHP development on my Ubuntu box (running Apache2 as server),
I tried to create a PHP project and run it as "PHP Web Application" as show in the picture:
But when I click "Run" the browser pops out and giving 404 error saying it cant find localhost/test/newfile.php .
Does Eclipe PDT having its own internal webserver? (If so, I tried by shutting down my Apache2 ,but still giving the same error)
Finally, as a work around, I changed my workspace location to "/var/www" and created my projects there. But wondering whether its the best way to develop using PDT?
The questions you ask are not directly related to Eclipse PDT but how to setup the development server.
I suggest not to move the project into the webroot but to make Apache visit your development/project directory instead.
There are multiple ways to do that:
You can create a symlink (softlink) making a URL-Path point to a directory. You need to allow Apache to follow symlinks.
You can make use of the Alias directive to do something similar.
Virtual Hosts to make the webserver point to the location you're looking for via it's domain name. You can then create "fake" domain names within your hosts file like example.com.loc for the local development version of your website.
You can even use mod_rewrite for that (not that good option).
As you can see there are multiple ways to have this in a manageable fashion. Depending on your needs, the symlink variant is probably most easy to accomplish. If you need more security, the Alias Directive is similarly easy to accomplish. Virtual hosts start to make sense if you're more familiar with apache configuration and you need more control of the URLs (some software is that dumb that it needs to reside on the top path / beneath an URL otherwise it just does not work (yeah, crap, but virtual hosts come to the rescue then). The mod_rewrite "solution" is just named for completeness reasons, it's more asking for trouble if you're not firm with mod_rewrite and as you're new to apache configuration, leave it next to your road and ignore that suggestion.
All these ways allow you to have one or more development projects next to static websites on your server. I personally have configured virtual hosts on my devbox, and on my earlier devbox I was just using alias directives.
Keep in mind that you need to restart the apache service if you edited the configuration:
$ sudo /etc/init.d/apache2 restart
And most importantly: Before you edit the configuration file, copy it over to a backup file-name. Always backup configuration files before you edit them. You don't want to loose the working settings, believe me ;)

How to run scripts outside the main web directory effectively?

I have Web-Developer Server Suite, with PHP 5.25, which I downloaded from SourceForge.
My operating system is Windows 7 Home Edition.
I upgraded Apache to the latest version and will be upgrading PHP to 5.38 soon.
It works well, apart from one small problem; virtual hosts outside the main webroot
(C:/www/vhosts) do not display PHP scripts, or indeed any scripts at all; just the plain code. All virtualhosts work within C:/www/vhosts, but not any of the other locations I've declared in vhosts.
The other locations are:
C:/www/
C:/www/vhosts-test/
C:/www/businessweb/
C:/www/newmediasite/public_html/
This is despite the fact I declared the locations in httpd-vhosts.conf !
How would I get the server to understand PHP outside the main webroot, and also ASP.NET
(bear in mind I added mod_aspdotnet as well).
I'd gladly appreciate any advice on this; just spent a day-and-a-half rebuilding my webserver, moving files from a backup (all PHP and MySQL) after reinstalling Web-Developer Server Suite (which, IMHO, is pretty good for a beginner).
I'm not sure where to go with this, but I'll add, just for relevance, that this is strictly a development server for testing.
You can place your scripts in protected directory outside your Webroot so they are not accessible by your visitors.
However you need to place a script in your Webroot, that include these scripts. Most of the Firmwares implement a similar functionality.
<?php
require_once('/var/usr/myConfigDir/config.php');
?>
As I understand, only the directory configured as Webroot will be able to execute scripts. Already Apache adds a security layer for not executing scripts outside Webroot.
So if your target is to protect some of your scripts, you can do that, otherwise, I don't think it's possible.
From my understanding of your question, you want to be able to have your PHP files anywhere on your computer, yet have them still be able to execute. I do not believe this is possible, as PHP files are opened through the webserver i.e 127.0.0.1/foo.php instead of file://foo.php/
The webserver is configured to execute the files in /www, unless there is a setting somewhere (which I am unaware of) all PHP scripts will have to rest in /www.

Switching between Htdoc Webroots - Change my "DocumentRoot" variable in "httpd.conf" or use Symbolic Links?

I've officially reached the end of my wits on this problem. As someone who constantly works on several websites at a time (I'm sure I'm not alone here), it becomes frustrating renaming my "htdocs" directory whenever I want to work on a different site, so I decided to throw together a simple script.
My first approach was to reset the "DocumentRoot" variable in "httpd.conf" based on the directory input I provided, however, having a DocumentRoot outside of the main "/Applications/XAMPP/" directory has proven to be a bigger problem. As you can see, I'm running OSX with an XAMPP installation. Ideally, I'd like to have all my sites located at "/Users/Me/Sites/*". Even when I tried to move my sites within XAMPP's base directory, Apache does not want to load anything other than "htdocs" as my DocumentRoot.
My next approach was to simply add symbolic links to all the files/directories within each site I was working on at the time to "htdocs". This loads fine in the browser for basic html files, however, I work primarily with PHP and this does not appear to want to render (I can see the file but it will not display as a webpage).
Neither of these approaches in themselves sound too difficult, but from learning Xcode, to AppleScript, to Apache's httpd.conf documentation, I feel I've experienced enough headaches. I've played with permissions for each attempt I've gone through and nothing has panned out for me yet.
I'm sure there are plenty of other webdesigners out there who have faced this problem in the past, what's your solution?
This is actually really easily achieved, given that you are using XAMPP, I am not 100% but if you go under /bin/apache2/conf/extras/ you should see a file called httpd-vhosts.conf in this file you can add as many virtual hosts as you want. Make sure you set the ServerName to be something unique. Once that is done, make sure that the Include Vhosts is enabled in the httpd.conf
Now, you just edit your hosts file. I am not sure where this is on OSX, since it is linux based I would say /etc/hosts but google will help you. Add a line for each of your sites like so:
127.0.0.1 site1.dev
127.0.0.1 site2.dev
etc. Now restart apache and in your browser type site1.dev and apache should understand it and take you to that site. Pretty simple.
Brad's solution should work.
If you are on OSX, you might also want to check out MAMP (http://www.mamp.info/en/index.html). There is a free and "Pro" version. I've only used the free version but it's pretty drop dead simple to change the root directory from one project to the other. Only kind of gotcha is the MySQL which uses a socket to connect but if you know what you are doing, this isn't a big deal.
Once you'll understand the virtualHost things, let'say you'll use names based virtualhosts and edit you host file to get all theses names matching your development server IP, once done, you'll see you will have to adjust documentRoot and directory settings on all theses virtualhosts for each new project.
So a generic solution exists: mod_vhost_alias : http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html
All you virtualhosts will be the same, with variables (documentRoot, serverName,etc). If you want specific setting for some projects ensure you have allowed .htaccess files and set the specific things there.

Zendframework link problem

I am very to new to zend frame work , I am trying to set up a project (Done by other programmer) in my local server, but in this project the all links to another are not working?
Plss help me!!!!!!!!1
I don't know where exactly relies your problem but it could be several things
make sure the rewriting is working
properly (Apache settings, IIS
settings, .htaccess). You check that
by adding a die('I am in
index.php'); in your index file and
browse some urls
$frontController->setBaseUrl if your website is not at the root of the server your should set the baseurl to match that.
That's the two main reason that come to my mind now I would be glad to help more if you give more details...
Just a guess. Since I had a problem that is a bit like this. You may need to set up your virtual host for this one. Maybe the old developer used a certain virtual host. That is why it is not working when you transfered it to your local machine
Check your VirtualHost settings, then check .htaccess or post this files.

Categories