So I have been given a static site. It was built with php. Unfortunately I am not familiar with it. However, I thought that shouldn’t be much of a concern as my goal is just trying to serve it locally so I can update it.
This is the directory where the site lives…
/Users/antonio-pavicevac-ortiz/Sites/
I configured Apache with the following. (I am on a macOS High Sierra 10.13.6.)
private/etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
#127.0.0.1 localhost
127.0.0.1 fragrances.christinaaguilera
127.0.0.1 www.fragrances.christinaaguilera
255.255.255.255 broadcasthost
::1 localhost
/private/etc/apache2/httpd.conf
This is what I figured is the most important part to change… Am I wrong?
DocumentRoot "/Users/antonio-pavicevac-ortiz/Sites/"
<Directory "/Users/antonio-pavicevac-ortiz/Sites/">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options FollowSymLinks Multiviews
MultiviewsMatch Any
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
/private/etc/apache2/users/antonio-pavicevac-ortiz.conf
<Directory "Users/antonio-pavicevac-ortiz/Sites/">
Options Indexes MultiViews
AllowOverride None
Require all granted
</Directory>
And finally the config.php file:
<?php
// error_reporting(E_ALL);
// ini_set("display_errors", 1);
session_start();
$validLanguages = array('EN'=>'en','DE'=>'de'/*,'RU'=>'ru','PT'=>'pt','HU'=>'hu','NL'=>'nl'*/);
switch ($_SERVER['SERVER_NAME'])
{
case 'fragrances.christinaaguilera' || 'www.fragrances.christinaaguilera':
{
error_reporting(E_ALL);
ini_set("display_errors", 1);
if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
{
$_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
}
define('ROOT_PATH', '/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera.dev');
define('TEMPLATE_PATH', ROOT_PATH.'templates/');
define('XML_PATH', ROOT_PATH.'xml/');
define('ROOT_URL', $_SERVER['HTTP_HOST'].'/');
define('MEDIA_ROOT_URL','/');
define('CSS_ROOT_URL', MEDIA_ROOT_URL.'css/');
define('JS_ROOT_URL', MEDIA_ROOT_URL.'js/');
define('IMG_ROOT_URL', MEDIA_ROOT_URL.'images/');
break;
}
// case'192.168.0.206':
// {
// error_reporting(E_ALL);
// ini_set("display_errors", 1);
//
// if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
// {
// $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
// }
//
// define('ROOT_PATH', '/media/sf_public_html/aguilera-microsite/branches/20141007_responsive/');
// define('TEMPLATE_PATH', ROOT_PATH.'templates/');
// define('XML_PATH', ROOT_PATH.'xml/');
// define('ROOT_URL', $_SERVER['HTTP_HOST'].'/aguilera-microsite/branches/20141007_responsive/');
// define('MEDIA_ROOT_URL','http://192.168.0.206/aguilera-microsite/branches/20141007_responsive/');
// define('CSS_ROOT_URL', ROOT_URL.'css/');
// define('JS_ROOT_URL', ROOT_URL.'js/');
// define('IMG_ROOT_URL', ROOT_URL.'images/');
//
// break;
// }
// case'137.183.87.135':
// {
// error_reporting(E_ALL);
// ini_set("display_errors", 1);
//
// if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
// {
// $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
// }
//
// define('ROOT_PATH', '/content/aguilera/docs/responsive/');
// define('TEMPLATE_PATH', ROOT_PATH.'templates/');
// define('XML_PATH', ROOT_PATH.'xml/');
// define('ROOT_URL', $_SERVER['HTTP_HOST'].'/responsive/');
// define('MEDIA_ROOT_URL','http://137.183.87.135:4064/content/aguilera/docs/responsive/');
// define('CSS_ROOT_URL', ROOT_URL.'css/');
// define('JS_ROOT_URL', ROOT_URL.'js/');
// define('IMG_ROOT_URL', ROOT_URL.'images/');
//
// break;
// }
//case'137.183.87.139':
//{
// // error_reporting(E_ALL);
// // ini_set("display_errors", 1);
//
// if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
// {
// $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
// }
//
// define('ROOT_PATH', '/content/aguilera/docs/restage/');
// define('TEMPLATE_PATH', ROOT_PATH.'templates/');
// define('XML_PATH', ROOT_PATH.'xml/');
// define('ROOT_URL', $_SERVER['HTTP_HOST'].'/restage/');
// define('MEDIA_ROOT_URL','http://137.183.87.139:4064/restage/');
// define('CSS_ROOT_URL', MEDIA_ROOT_URL.'css/');
// define('JS_ROOT_URL', MEDIA_ROOT_URL.'js/');
// define('IMG_ROOT_URL', MEDIA_ROOT_URL.'images/');
//
// break;
//}
//case'137.183.87.140':
//{
// // error_reporting(E_ALL);
// // ini_set("display_errors", 1);
//
// if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
// {
// $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
// }
//
// define('ROOT_PATH', '/content/aguilera/docs/restage/');
// define('TEMPLATE_PATH', ROOT_PATH.'templates/');
// define('XML_PATH', ROOT_PATH.'xml/');
// define('ROOT_URL', $_SERVER['HTTP_HOST'].'/restage/');
// define('MEDIA_ROOT_URL','http://137.183.87.140:4064/restage/');
// define('CSS_ROOT_URL', MEDIA_ROOT_URL.'css/');
// define('JS_ROOT_URL', MEDIA_ROOT_URL.'js/');
// define('IMG_ROOT_URL', MEDIA_ROOT_URL.'images/');
// break;
//}
default:
{
// error_reporting(E_ALL);
// ini_set("display_errors", 1);
if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
{
$_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
}
if(!preg_match('~elizabetharden~',$_SERVER['HTTP_HOST'])){
// PROD instance root path
define('ROOT_PATH', 'D:/Sites/wwwroot/fragrances.christinaaguilera.com/content/aguilera/docs/restage/');
} else {
// DEV instance root path
define('ROOT_PATH', 'D:/Sites/wwwroot/christinaaguilera.elizabetharden.net/content/aguilera/docs/restage/');
}
define('TEMPLATE_PATH', ROOT_PATH.'templates/');
define('XML_PATH', ROOT_PATH.'xml/');
define('ROOT_URL', $_SERVER['HTTP_HOST'].'/');
if(isset($_SERVER["HTTP_SSL"])){
// define('MEDIA_ROOT_URL','https://secure.footprint.net/perfumes-christinaaguilera-com/restage/v_23/');
} else {
// define('MEDIA_ROOT_URL','http://media.perfumes.christinaaguilera.com/restage/v_23/');
}
define('MEDIA_ROOT_URL','/');
define('CSS_ROOT_URL', MEDIA_ROOT_URL.'css/');
define('JS_ROOT_URL', MEDIA_ROOT_URL.'js/');
define('IMG_ROOT_URL', MEDIA_ROOT_URL.'images/');
break;
}
}
UPDATE October 2nd
So I have the alias working now:
But as you can see it’s pointing to that index.html file in the Sites folder.
And I updated the /private/etc/apache2/httpd.conf
<Directory "Users/antonio-pavicevac-ortiz/Sites/">
AddLanguage en .en
AddHandler perl-script .pl
PerlHandler ModPerl::Registry
Options Indexes MultiViews FollowSymLinks ExecCGI
AllowOverride None
Require host localhost
</Directory>
- Now I can run pearl scripts… 🙂
UPDATE October 2nd as per msg…
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/
<Directory "/Users/antonio-pavicevac-ortiz/Sites/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/"
ServerName fragrances.christinaaguilera
ServerAlias www.fragrances.christinaaguilera
<Directory "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
My latest config.php
<?php
// error_reporting(E_ALL);
// ini_set("display_errors", 1);
session_start();
$validLanguages = array('EN'=>'en','DE'=>'de'/*,'RU'=>'ru','PT'=>'pt','HU'=>'hu','NL'=>'nl'*/);
switch ($_SERVER['SERVER_NAME'])
{
case 'fragrances.christinaaguilera' || 'www.fragrances.christinaaguilera':
{
error_reporting(E_ALL);
ini_set("display_errors", 1);
if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
{
$_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
}
define('ROOT_PATH', '/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/');
define('TEMPLATE_PATH', ROOT_PATH.'templates/');
define('XML_PATH', ROOT_PATH.'xml/');
define('ROOT_URL', $_SERVER['HTTP_HOST'].'/');
define('MEDIA_ROOT_URL','/');
define('CSS_ROOT_URL', MEDIA_ROOT_URL.'css/');
define('JS_ROOT_URL', MEDIA_ROOT_URL.'js/');
define('IMG_ROOT_URL', MEDIA_ROOT_URL.'images/');
break;
}
// case'192.168.0.206':
// {
// error_reporting(E_ALL);
// ini_set("display_errors", 1);
//
// if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
// {
// $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
// }
//
// define('ROOT_PATH', '/media/sf_public_html/aguilera-microsite/branches/20141007_responsive/');
// define('TEMPLATE_PATH', ROOT_PATH.'templates/');
// define('XML_PATH', ROOT_PATH.'xml/');
// define('ROOT_URL', $_SERVER['HTTP_HOST'].'/aguilera-microsite/branches/20141007_responsive/');
// define('MEDIA_ROOT_URL','http://192.168.0.206/aguilera-microsite/branches/20141007_responsive/');
// define('CSS_ROOT_URL', ROOT_URL.'css/');
// define('JS_ROOT_URL', ROOT_URL.'js/');
// define('IMG_ROOT_URL', ROOT_URL.'images/');
//
// break;
// }
// case'137.183.87.135':
// {
// error_reporting(E_ALL);
// ini_set("display_errors", 1);
//
// if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
// {
// $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
// }
//
// define('ROOT_PATH', '/content/aguilera/docs/responsive/');
// define('TEMPLATE_PATH', ROOT_PATH.'templates/');
// define('XML_PATH', ROOT_PATH.'xml/');
// define('ROOT_URL', $_SERVER['HTTP_HOST'].'/responsive/');
// define('MEDIA_ROOT_URL','http://137.183.87.135:4064/content/aguilera/docs/responsive/');
// define('CSS_ROOT_URL', ROOT_URL.'css/');
// define('JS_ROOT_URL', ROOT_URL.'js/');
// define('IMG_ROOT_URL', ROOT_URL.'images/');
//
// break;
// }
//case'137.183.87.139':
//{
// // error_reporting(E_ALL);
// // ini_set("display_errors", 1);
//
// if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
// {
// $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
// }
//
// define('ROOT_PATH', '/content/aguilera/docs/restage/');
// define('TEMPLATE_PATH', ROOT_PATH.'templates/');
// define('XML_PATH', ROOT_PATH.'xml/');
// define('ROOT_URL', $_SERVER['HTTP_HOST'].'/restage/');
// define('MEDIA_ROOT_URL','http://137.183.87.139:4064/restage/');
// define('CSS_ROOT_URL', MEDIA_ROOT_URL.'css/');
// define('JS_ROOT_URL', MEDIA_ROOT_URL.'js/');
// define('IMG_ROOT_URL', MEDIA_ROOT_URL.'images/');
//
// break;
//}
//case'137.183.87.140':
//{
// // error_reporting(E_ALL);
// // ini_set("display_errors", 1);
//
// if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
// {
// $_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
// }
//
// define('ROOT_PATH', '/content/aguilera/docs/restage/');
// define('TEMPLATE_PATH', ROOT_PATH.'templates/');
// define('XML_PATH', ROOT_PATH.'xml/');
// define('ROOT_URL', $_SERVER['HTTP_HOST'].'/restage/');
// define('MEDIA_ROOT_URL','http://137.183.87.140:4064/restage/');
// define('CSS_ROOT_URL', MEDIA_ROOT_URL.'css/');
// define('JS_ROOT_URL', MEDIA_ROOT_URL.'js/');
// define('IMG_ROOT_URL', MEDIA_ROOT_URL.'images/');
// break;
//}
default:
{
// error_reporting(E_ALL);
// ini_set("display_errors", 1);
if(substr($_SERVER['HTTP_HOST'],0,7)!='http://')
{
$_SERVER['HTTP_HOST']='http://'.$_SERVER['HTTP_HOST'];
}
if(!preg_match('~elizabetharden~',$_SERVER['HTTP_HOST'])){
// PROD instance root path
define('ROOT_PATH', 'D:/Sites/wwwroot/fragrances.christinaaguilera.com/content/aguilera/docs/restage/');
} else {
// DEV instance root path
define('ROOT_PATH', 'D:/Sites/wwwroot/christinaaguilera.elizabetharden.net/content/aguilera/docs/restage/');
}
define('TEMPLATE_PATH', ROOT_PATH.'templates/');
define('XML_PATH', ROOT_PATH.'xml/');
define('ROOT_URL', $_SERVER['HTTP_HOST'].'/');
if(isset($_SERVER["HTTP_SSL"])){
// define('MEDIA_ROOT_URL','https://secure.footprint.net/perfumes-christinaaguilera-com/restage/v_23/');
} else {
// define('MEDIA_ROOT_URL','http://media.perfumes.christinaaguilera.com/restage/v_23/');
}
define('MEDIA_ROOT_URL','/');
define('CSS_ROOT_URL', MEDIA_ROOT_URL.'css/');
define('JS_ROOT_URL', MEDIA_ROOT_URL.'js/');
define('IMG_ROOT_URL', MEDIA_ROOT_URL.'images/');
break;
}
}
3
Answers
If you use the .htaccess functionality, you’ll need mod_rewrite enabled on your Apache server. To check for this, run the following command:
If you see rewrite_module in the list, you are good to go. If not, just enable it with the following command:
And restart Apache for the changes to take effect:
You have to declare virtual host where You define hostname and document root.
Add following to the end of httpd.conf and restart apache:
Apache will route a request to a
VirtualHost
that matchesServerName
orServerAlias
first, or the one labeled_default_
or the firstVirtualHost
defined if there isn’t one. Based on that, serves whatever file was requested, from theDocumentRoot
directory for thatVirtualHost
or theDirectoryIndex
defined if there is no file.So, up to this point, given your (known) directory structure, you need the following configuration:
Note that I changed the
MultiViews
,AllowOverride
andDirectoryIndex
settings.Now, when you access
http://fragrances.christinaaguilera
Apache would normally try to serveindex.html
or similar file, but withDirectoryIndex
will serve that file instead. WithAllowOverride All
, it’ll check for existence of.htaccess
and apply the rules in there but I’ve disabled it for now. We’ll take it one step at a time.You can check if apache is picking up your configuration by executing
apachectl -D DUMP_VHOSTS
. It should show you the definedVirtualHosts
. If there is none, make sure your virtual host config file is being included in your mainhttpd.conf
server config by looking forInclude
directives like:Make sure the path match and restart the service.
Once we get the
VirtualHost
up and running it’s time to get the.htaccess
. For that, we need to changeAllowOverride
back and get rid of theDirectoryIndex
directive, leaving theDirectory
for theVirtualHost
like this:And now, we should see the same redirection behaviour when accessing the site. With a bit of luck, we’ll see the site. If not, we’ll begin by commenting out the line
RewriteBase /restage
.Most of the file should not be necessary for our purposes. I think we can get by with this minimal version to start:
That’s a quite standard clean url router setup. It translates to “redirect any request that is not a physical file or directory on disk to rootfile.php/uri”.
Now try to access
http://fragrances.christinaaguilera/en/
.Here’s a breakdown for the rest of the file:
The
AddType
directives tell apache to send mime headers for those specific file extensions. You might not need them if running a modern version of apache, but just to be sure…The
RewriteCond %{HTTP_HOST}
lines and followingRewriteRule
redirect to a canonical url (the www. version). Doesn’t make much sense in development, unless it’s to make sure there are no extra redirections.All the
RewriteRule hu/$ /en/ [R=301,L]
you shouldn’t ever need, as it’s handled on the php side (if(!in_array($language, $validLanguages))
). They redirect to the english version. Except for the/de/
one, that’s still in use. Also leave thelang/home$
redirections in there, just to be safe.Finally the three potentially problematic lines:
Can’t say for sure what they do without more info in the internal links, but here is what they translate to:
RewriteBase
basically says “for any rewriting that occurs, prepend/restage/
to it”. This is file wide, so it would affect therootfile.php
redirection too. So it should be a restage directory inside your project with (mostly) the same files for this rules to make sense./restages
in the translation because of theRewriteBase
. That behaviour is what worries me the most, but as I said, need more info on the project structure. Looks like someone was working on adding some features to a copy of the site.