Hi
I am using Ubuntu linux 8.10

I have installed Apache, PHP and MySQL on my pc and testing all scripts on my localhost by http://localhost/ .

Currently I am creating directories for each web projects to test on my localhost. So my project can be access by http://localhost/project01/ and so on.
Example
http://localhost/project01 will access /var/www/project01
http://localhost/project02 will access /var/www/project02


There is some problems with server path in coding. When I would use file copy/paste process on my localhost, it requre path from root to work. And the path is different on my localhost and on sever.

So I think to use different domain name for different projects.
Example :
will access /var/www/project01
will access /var/www/project02

... or any other solution will be also welcome, so my localhost files and servers files are perfectly same.

Any guide for this?
Thank you.

Dani AI

Generated

Short summary and practical steps to make each local project use its own hostname (and to avoid path mismatches between localhost and a remote server). As pointed out, separate hostnames + virtual hosts are the usual fix; below are concrete, low-friction steps and a few code-level practices so ’s files stay portable when copied to the live server.

Add local names to the hosts file:

127.0.0.1   project01.test project02.test

Create one Apache virtual host per project (example for modern Apache; older 2.2 uses the older Order/Allow syntax inside the Directory block):

<VirtualHost *:80>
    ServerName project01.test
    DocumentRoot /var/www/project01

    <Directory /var/www/project01>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Enable the site (Debian/Ubuntu) and reload Apache:

sudo a2ensite project01.conf
sudo systemctl reload apache2   # or: sudo service apache2 reload

Avoid using real TLDs like .dev (modern browsers may force HTTPS) and prefer .test or .localhost to prevent DNS/mDNS conflicts.

Code-level recommendations so paths work identically on local and remote:

define('BASE_DIR', realpath(__DIR__ . '/..'));   // filesystem root for includes
define('BASE_URL',  'http://' . $_SERVER['HTTP_HOST'] . '/'); // URL root
require BASE_DIR . '/includes/init.php';

Prefer filesystem-aware includes (use __DIR__/realpath) and root-relative URLs for assets (e.g. /assets/style.css). Keep one small environment config file (BASE_DIR/BASE_URL) per host so deployments don’t require code changes.

Quick troubleshooting: ping the hostname to confirm hosts file resolution, check Apache error log (/var/log/apache2/error.log), confirm the correct DocumentRoot, and clear browser cache. These steps replicate production behavior while keeping local layout simple and portable.

if you are okay with the apache name based vhost config (see end of the default httpd.conf for an example)

The name resolution (so your server knows its got other names) is also fairly simple.

You can add the extra names to your /etc/host file. This is generally used to find names for servers before DNS is touched (which is configurable) so you can use the same technique for testing actual domains locally if required.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.