在apache linux中将子文件夹设置为子域

I am creating sub folders on my domain in this format:

http://example.com/f1.

I'm creating the folders like this. I want to access their contents with the url in this format:

http://f1.example.com not in http://example.com/f1.

I am using apache linux OS with php as server language. Please help with this. How can I do this?

If your hosting provider supports cPanel you can easily create sub domains. Go to your hosting cPanel. Find the option named "Sub Domains". In there, you will be able to create sub domains under your domain.

The apache http server offer the "virtual hosts" feature for exactly this purpose. The feature offers a very good documentation as typical for apache projects:
http://httpd.apache.org/docs/2.4/en/vhosts

That documentation also offers a convenient section "Virtual Host examples for common setups". In there you can see a perfect example for your setup:

Basically you define one "virtual host" per such folder:

Listen 80
<VirtualHost *:80>
    DocumentRoot "/var/www/hosts/f1"
    ServerName f1.example.com

    # Other directives here
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/var/www/hosts/f2"
    ServerName f2.example.com

    # Other directives here
</VirtualHost>

This obviously requires that you have control over the http server, so access to the configuration. If that is not the case, for example because you do not operate the system yourself but use some cheap shared hosting provider, then you should consult their documentation how to achieve this. They might offer some tool for the purpose which grants you limited access to the above feature.

With that setup you can now make requests to the two separate hosts:

Note that for this to work you additionally have to take care of the domain name resolution. The host names must be resolved to IP addresses, there is no way around that if you want to use different host names. The distinction which host is requested if both host names ("subdomains") resolve to the same IP address is done via the HOST header in the http request. This also means that requests to the raw IP address will be served by the default host which is the first host defined in the above setup.