²î±ðÇéÐÎÏÂthinkphpÓ¦¸Ã·ÅÔÚÄÇÀï
ÔÚ¿ª·¢webÓ¦ÓóÌÐòµÄʱ¼ä£¬ÎÒÃǾ³£Ê¹ÓóÉÊìµÄphp¿ò¼ÜÀ´¼ÓËÙÏîÄ¿µÄ¿ª·¢£¬ÆäÖÐthinkphpÊÇÒ»¸öÆÕ±éʹÓõĿò¼ÜÖ®Ò»¡£È»¶ø£¬Ðí¶à³õѧÕß²»ÖªµÀthinkphpÓ¦¸Ã·ÅÔÚÄÇÀï²Å»ªÈÃÆäÕý³£ÊÂÇé¡£±¾ÆªÎÄÕ½«ÏÈÈÝÔÚ²î±ðÇéÐÎÏÂthinkphpÓ¦¸Ã·ÅÔÚÄÇÀÒÔ¼°ÔõÑùÉèÖÃÆä·¾¶ÐÅÏ¢¡£
Ò»¡¢ÍâµØÇéÐÎ
ÔÚÍâµØÇéÐÎÏ£¬ÎÒÃÇͨ³£Ê¹ÓÃXAMPP¡¢WAMPµÈ¼¯³É¿ª·¢ÇéÐΣ¬½«Apache WebЧÀÍÆ÷ºÍPHPÇéÐδò°üÔÚÒ»Æð¡£ÔÚÕâÖÖÇéÐÎÏ£¬ÎÒÃÇ¿ÉÒÔ½«thinkphpÎļþ¼ÐÖ±½Ó°²ÅÅÔÚWebЧÀÍÆ÷µÄ¸ùĿ¼Ï£¬ÀýÈçXAMPPÖеÄhtdocsĿ¼£¬WAMPÖеÄwwwĿ¼µÈ¡£ÕâÑù£¬ÎÒÃǾͿÉÒÔÔÚä¯ÀÀÆ÷ÖÐͨ¹ýlocalhost»ò127.0.0.1À´»á¼ûÍøÕ¾¡£±ðµÄ£¬ÈôÊÇÄúµÄÏîÄ¿ÐèҪʹÓÃÊý¾Ý¿â£¬Äú»¹ÐèÒªÔÚphpMyAdminµÈÊý¾Ý¿âÖÎÀí¹¤¾ßÖн¨ÉèÒ»¸öÊý¾Ý¿â£¬²¢ÔÚÄúµÄ³ÌÐòÖÐͨ¹ýÉèÖÃÎļþÅþÁ¬µ½¸ÃÊý¾Ý¿â¡£
¶þ¡¢ÐéÄâÖ÷»ú
ÔÚ¹²ÏíÖ÷»ú»òÕßVPS£¨ÐéÄâרÓÃЧÀÍÆ÷£©ÉÏ£¬ÎÒÃÇͨ³£Ê¹ÓÃÐéÄâÖ÷»úÀ´ÍйÜÍøÕ¾¡£Æ¾Ö¤ÐéÄâÖ÷»úµÄ²î±ðÉèÖã¬PHPÎļþµÄ´æ·ÅλÖÃÒ²»áÓÐËù²î±ð¡£Ò»Ñùƽ³£À´Ëµ£¬ÐéÄâÖ÷»úµÄÎĵµ¸ùĿ¼ÊǸÃÖ÷»úÏÂËùÓÐÍøÕ¾µÄ¹«¹²¸ùĿ¼£¬Ò²³ÆΪÖ÷Ŀ¼£¨home directory£©¡£¼ÙÉèÄãÐèÒª½«thinkphp·ÅÔÚÒ»¸öÃûΪmyappµÄ×ÓĿ¼Ï£¬Äã¿ÉÒÔ½«Õû¸öthinkphpÎļþ¼ÐÉÏ´«µ½myappĿ¼Ï£¬È»ºóÔÚ¸ÃĿ¼Ï½¨ÉèÒ»¸öindex.phpÎļþ£¬ÄÚÈÝÈçÏ£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
<?php define('APP_PATH', __DIR__ . '/../thinkphp/'); define('BIND_MODULE','index'); require __DIR__ . '/../thinkphp/start.php';
µÇ¼ºó¸´ÖÆ
ÔÚÕâÀÎÒÃÇͨ¹ýdefineº¯Êý½ç˵ÁËAPP_PATH³£Á¿£¬ËüÖ¸ÏòÁËthinkphpÎļþ¼ÐµÄÉϼ¶Ä¿Â¼¡£È»ºó£¬ÎÒÃǽ«ÔËÐÐindexÄ£¿é£¬²¢Í¨¹ýstart.phpÎļþÆô¶¯ÁËÕû¸ö¿ò¼Ü¡£ÕâÑù£¬ÎÒÃǾͿÉÒÔÔÚä¯ÀÀÆ÷ÖÐͨ¹ý»á¼ûhttp://ÄãµÄÓòÃû/myappÀ´»á¼ûÍøÕ¾¡£
¸ü½øÒ»²½£¬ÈôÊÇÄãÐèҪΪ²î±ðµÄÓ¦ÓóÌÐò½¨Éè²î±ðµÄ×ÓĿ¼£¬Äã¿ÉÒÔ½«Ã¿¸öÓ¦ÓóÌÐòµÄÖ÷Ŀ¼ÉèÖÃΪ¸ÃĿ¼ÏµÄpublicĿ¼¡£Ò²¾ÍÊÇ˵£¬ÄãÐèÒªÔÚÿ¸öÓ¦ÓóÌÐòÖн¨ÉèÒ»¸öpublicĿ¼£¬½«ÄãµÄÓ¦ÓóÌÐòµÄÈë¿ÚÎļþ·ÅÔÚÆäÖУ¬È磺
/project1 /application /controller /model /view /... /public /index.php /assets /css /js /images /... /... /project2 /application /public /index.php /project3 /application /public /index.php
µÇ¼ºó¸´ÖÆ
ÕâÊÇÒ»¸ö½ÏÁ¿Í¨Óõķ½·¨£¬ÓÉÓÚpublicĿ¼ÖеÄËùÓÐÄÚÈݶ¼¿ÉÒÔͨ¹ýWebЧÀÍÆ÷Ö±½Ó»á¼û£¬¶øapplicationĿ¼ÖеĴúÂëÎļþÔò²»¿É±»Ö±½Ó»á¼û¡£
Èý¡¢Ô¶³ÌЧÀÍÆ÷
ÔÚÔ¶³ÌЧÀÍÆ÷ÉÏÍйÜÄúµÄÓ¦ÓóÌÐòʱ£¬Ç뽫Æä·ÅÔÚ¹«¹²Ä¿Â¼Ï¡£ÈôÊÇÄúʹÓõÄÊÇLinuxЧÀÍÆ÷£¬Äú¿ÉÒÔ½«thinkphpÎļþ¼ÐÖ±½Ó·ÅÔÚ/var/www/htmlĿ¼Ï¡£ÈôÊÇÄúʹÓõÄÊÇWindowsЧÀÍÆ÷£¬Ôò¿ÉÒÔ½«Æä·ÅÔÚC:\inetpub\wwwrootĿ¼Ï¡£ËäÈ»£¬ÈôÊÇÄúʹÓõÄÊÇ×Ô¼º´î½¨µÄÐéÄâÖ÷»úЧÀÍÆ÷£¬Ôò¿ÉÒÔƾ֤ÄúÔÚÐéÄâÖ÷»ú¿ØÖÆÃæ°åÖÐÉèÖõÄĿ¼À´È·¶¨Ó¦ÓóÌÐòµÄ´æ·ÅλÖá£
ÔÚÔ¶³ÌЧÀÍÆ÷ÉÏ£¬Äú»¹ÐèÒªÉèÖÃthinkphp·¾¶ÐÅÏ¢ÒÔÈ·±£¿ò¼ÜÄܹ»Õý³£ÔËÐС£¼ÙÉèÄú½«¿ò¼ÜĿ¼·ÅÔÚÁË/var/www/html/thinkphpÏ£¬ÄúÐèÒªÐÞ¸ÄÖ÷ÉèÖÃÎļþconfig.php£¬ÔöÌíÒÔÏÂÄÚÈÝ£º
'url_common_param' => true, 'url_route_on' => true, 'url_route_must' => false, 'url_html_suffix' => '', 'app_debug' => true, 'unix_socket' => '/var/run/mysqld/mysqld.sock', 'app_path' => realpath(__DIR__.'/../application') . '/',
µÇ¼ºó¸´ÖÆ
ÔÚÕâÀÎÒÃǽ«app_pathÉèÖÃΪthinkphpÎļþ¼ÐËùÔڵķ¾¶£¬Õâ¸æËß¿ò¼ÜÒªÔÚÄÇÀï²éÕÒÓ¦ÓóÌÐòµÄ´úÂëÎļþ¡£Çë×¢ÖØ£¬ÔÚPHPÖУ¬½«__DIR__£¨Ë«Ï»®Ïߣ©ÓÃÓÚ»ñÈ¡Ä¿½ñÎļþµÄĿ¼£¬¶ø²»ÊÇÓÃÓÚ»ñÈ¡Ä¿½ñÊÂÇéĿ¼¡£Òò´Ë£¬realpath(__DIR__.’/../application’)±í´ïµÄÊÇthinkphpÉϼ¶Ä¿Â¼ÏµÄapplicationĿ¼·¾¶¡£
ËÄ¡¢×ܽá
ÎÞÂÛÊÇÔÚÍâµØÇéÐΡ¢ÐéÄâÖ÷»úÕÕ¾ÉÔ¶³ÌЧÀÍÆ÷ÉÏ£¬ÎÒÃǶ¼ÐèҪ׼ȷµØ°²ÅÅthinkphpÎļþ¼Ð£¬²¢ÉèÖúÃËüµÄ·¾¶ÐÅÏ¢À´È·±£¿ò¼ÜµÄÕý³£ÔËÐС£ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÌṩÁËһЩ½ÏÁ¿Í¨ÓõÄ×ö·¨£¬µ«Æ¾Ö¤ÏÖÕæÏàÐΣ¬Äú¿ÉÄÜÐèÒª¶ÔËüÃǾÙÐÐһЩ΢µ÷¡£ÎÞÂÛÔõÑù£¬Çë¼Ç×Å£¬×¼È·°²ÅÅthinkphpÊÇÒ»¸ö¿ª·¢Àú³ÌÖÐÊ®·ÖÖ÷ÒªµÄ°ì·¨£¬Ëü½«È·±£Äú¿ª·¢µÄÓ¦ÓóÌÐòÄܹ»Õý³£ÔËÐС£
ÒÔÉϾÍÊDzî±ðÇéÐÎÏÂthinkphpÓ¦¸Ã·ÅÔÚÄÇÀïµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡