Automatically use sub domain pointed to folder

Laravel, Drupal, etc use public folder, for other php project without public folder, just create public folder and put the project inside public folder, this is how to configure web server

For Apache

<VirtualHost *:80>
  ServerAlias localhost * #wildcard catch all
  VirtualDocumentRoot /path/to/your/workspace/%1/public
  UseCanonicalName Off
  <Directory "path/to/your/workspace">
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
To make the VirtualDocumentRoot work, you also need to uncomment the following line in .htaccess:
# RewriteBase /

For Nginx

server {
    listen 80;

    server_name "~^(?.+)\.ibnux\.org";
    access_log /var/log/nginx/access_$sub.log;
    error_log  /var/log/nginx/error_$sub.log;

    set $root /path/to/your/workspace/$sub/public/;
    root $root;
    index index.php index.html index.htm;