skip to Main Content

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:

enter image description here

But as you can see it’s pointing to that index.html file in the Sites folder.

enter image description here

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


  1. If you use the .htaccess functionality, you’ll need mod_rewrite enabled on your Apache server. To check for this, run the following command:

    sudo apache2ctl -M
    

    If you see rewrite_module in the list, you are good to go. If not, just enable it with the following command:

    sudo a2enmod rewrite
    

    And restart Apache for the changes to take effect:

    sudo service apache2 restart
    
    Login or Signup to reply.
  2. You have to declare virtual host where You define hostname and document root.

    Add following to the end of httpd.conf and restart apache:

    <Directory "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/"> 
      Options Indexes MultiViews
      AllowOverride All
    </Directory>
    
    NameVirtualHost *:80 
    
    <VirtualHost *:80>
      DocumentRoot "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera"
      ServerName fragrances.christinaaguilera
      ServerAlias www.fragrances.christinaaguilera
    </VirtualHost>
    
    Login or Signup to reply.
  3. Apache will route a request to a VirtualHost that matches ServerName or ServerAlias first, or the one labeled _default_ or the first VirtualHost defined if there isn’t one. Based on that, serves whatever file was requested, from the DocumentRoot directory for that VirtualHost or the DirectoryIndex defined if there is no file.

    So, up to this point, given your (known) directory structure, you need the following configuration:

    NameVirtualHost *:80
    
    <VirtualHost *:80>
        ServerName localhost
        DocumentRoot /Users/antonio-pavicevac-ortiz/Sites/
        <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 None
            DirectoryIndex rootfile.php
            Require local
        </Directory>
    </VirtualHost>
    

    Note that I changed the MultiViews, AllowOverride and DirectoryIndex settings.

    Now, when you access http://fragrances.christinaaguilera Apache would normally try to serve index.html or similar file, but with DirectoryIndex will serve that file instead. With AllowOverride 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 defined VirtualHosts. If there is none, make sure your virtual host config file is being included in your main httpd.conf server config by looking for Include directives like:

    Include /private/etc/apache2/extra/httpd-vhosts.conf
    Include /private/etc/apache2/extra/*.conf
    

    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 change AllowOverride back and get rid of the DirectoryIndex directive, leaving the Directory for the VirtualHost like this:

    <Directory  "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/">
        Options +Indexes +Includes +FollowSymLinks -MultiViews
        AllowOverride All
        Require local
    </Directory>
    

    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:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /rootfile.php/$1 [L]   
    

    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 following RewriteRule 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 the lang/home$ redirections in there, just to be safe.

    Finally the three potentially problematic lines:

    RewriteBase /restage/
    RewriteCond %{REQUEST_URI} !microsite
    RewriteRule ^(.*)v_([0-9]*)/(.*)$ /restage/$3 [L]
    

    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 the rootfile.php redirection too. So it should be a restage directory inside your project with (mostly) the same files for this rules to make sense.
    • The following two rules translate to “any request that is not a microsite and contains the string “v_” followed by numbers and a slash and any string, redirect to /restage/restage/any_string”. There are two /restages in the translation because of the RewriteBase. 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.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search