Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Adding a Web Site to Apache on Local Development Server (Ubuntu)

  1. #1
    Join Date
    Sep 2003
    Posts
    3,040

    Default Adding a Web Site to Apache on Local Development Server (Ubuntu)

    Add Web Site To Local Dev Server

    There is 2 parts to setup a web site in local dev server

    1. Add Web Site to Apache
    2. Add Web Site to /etc/hosts file.


    Add Web Site To Apache

    When we develop a web site, we need to add it to local web server. We also want to see the live web site also.

    For example, we are developing web site

    Code:
    http://ImageHostNow.com
    We add a web site

    Code:
    http://ImageHostNow.dev
    To local Apache web server. So we can access developement version of the site and live site same time

    To Add web site ImageHostNow.dev to local Apache web server, edit

    Code:
    subl ~/conf/vhosts.conf
    Add following to end of the file and save and quit editor.


    Code:
    <VirtualHost 127.0.0.1:80>
        ServerName imagehostnow.dev
        SetEnv APP_ENV "dev"
        DocumentRoot /home/YOUR_USER_NAME_HERE/www/imagehostnow.com/public
        CustomLog ${APACHE_LOG_DIR}/imagehostnow.dev.log combined
        <Directory "/home/YOUR_USER_NAME_HERE/www/imagehostnow.com/public">
            Options All
            AllowOverride All
            Require all granted
            Order allow,deny
            allow from all
        </Directory>
    </VirtualHost>
    In the above, VirtualHost entry, you need to change YOUR_USER_NAME_HERE with your actual username.

    Now you will need to create the folder for your web site

    Code:
    mkdir ~/www/imagehostnow.com
    mkdir ~/www/imagehostnow.com/public
    Now restart Web Server

    Code:
    sudo service apache2 restart
    Now Apache is ready to serve your web site. If you go to

    Code:
    http://ImageHostNow.dev
    You get web site not found error. This is because, when you go to a web site, first web site IP address is found using DNS server. In out case, ImageHostNow.dev, there is no such real site, so public DNS servers don't know about this site. So we have to point the web site to local Apache IP address (127.0.0.1)

    Setting Local DNS

    Edit /etc/hosts file.

    Code:
    subl /etc/hosts
    Now add following

    Code:
    127.0.0.1 imagehostnow.dev
    Save and exit editor. Now you will be able to see web site

    Code:
    http://ImageHostNow.dev
    Since our document root directory

    Code:
    /home/YOUR_USER_NAME_HERE/www/imagehostnow.com/public
    Is empty, no web page will be displayed. So go to that folder, create a file index.php (or index.html). Now the site will display the content.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  2. #2
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    I have done everything. An index.html file also created.

    When I take http://imagehostnow.dev in my browser, I get following page:


  3. #3
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Looks good. That is because DirectoryIndex is not set properly. So Apache don't know index.html should be displayed..

    Can you make index.php and see if it works ?
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  4. #4
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    i got same result


  5. #5
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Post result of following command

    Code:
    cat /etc/apache2/mods-available/dir.conf
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  6. #6
    Join Date
    Nov 2009
    Posts
    76,596

    Default


  7. #7
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    That looks good. Not sure why it is not showing index.php Anyway lets try following

    Update your VirtualHost entry in ~/conf/vhosts.conf as follows


    Code:
    <VirtualHost 127.0.0.1:80>
        ServerName imagehostnow.dev
        SetEnv APP_ENV "dev"
        DocumentRoot /home/YOUR_USER_NAME_HERE/www/imagehostnow.com/public
        CustomLog ${APACHE_LOG_DIR}/imagehostnow.dev.log combined
        DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
        <Directory "/home/YOUR_USER_NAME_HERE/www/imagehostnow.com/public">
            Options All
            AllowOverride All
            Require all granted
            Order allow,deny
            allow from all
        </Directory>
    </VirtualHost>
    The change is, we added the line

    Code:
        DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
    Below CustomLog line.


    Restart Apache. Go to web site and see if it shows index.php file instead of directory listing.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  8. #8
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    I have done the same, restarted apache.But still same.

  9. #9
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Run following command and post result

    Code:
    sudo a2enmod dir
    Also, restart apache, see if problem fixed.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  10. #10
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    I have done this too. But same result.


Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •