You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何无需localhost:8000及php artisan serve运行Laravel 5.5项目?

How to Access Laravel Project lms_manager via localhost/lms_manager

Got it, let's get your Laravel project lms_manager accessible through localhost/lms_manager instead of relying on php artisan serve or the default localhost:8000 port. I’ll walk you through setup steps for both Apache and Nginx—the two most common web servers.

Apache Configuration

If you’re using XAMPP, WAMP, or a standard Apache setup:

  • Move your project to Apache’s root directory

    • For XAMPP: Copy the lms_manager folder into htdocs
    • For WAMP: Drop it into www
    • For Linux (Ubuntu/Debian): Place it in /var/www/html
  • Enable mod_rewrite (critical for Laravel routing)

    • Open Apache’s httpd.conf file (location varies: XAMPP/WAMP have it in their Apache config folders; Linux uses /etc/apache2/apache2.conf)
    • Find the line #LoadModule rewrite_module modules/mod_rewrite.so and remove the # to uncomment it
    • On Linux, run sudo a2enmod rewrite to enable the module, then restart Apache with sudo systemctl restart apache2
  • Allow .htaccess overrides

    • In the same httpd.conf file, locate the <Directory> block for your root folder (e.g., <Directory "C:/xampp/htdocs"> or <Directory /var/www/html>)
    • Change AllowOverride None to AllowOverride All—this lets Laravel’s .htaccess file handle routing
  • Route traffic to the public folder (no need for localhost/lms_manager/public)

    • Create a new .htaccess file in the root of your lms_manager folder (not inside public) with this content:
      <IfModule mod_rewrite.c>
          RewriteEngine On
          RewriteRule ^(.*)$ public/$1 [L]
      </IfModule>
      
    • This redirects all requests for localhost/lms_manager to the project’s public directory (Laravel’s actual entry point)
  • Fix file permissions (Linux only)

    • Run these commands to give Apache write access to critical Laravel folders:
      sudo chown -R www-data:www-data /var/www/html/lms_manager/storage
      sudo chown -R www-data:www-data /var/www/html/lms_manager/bootstrap/cache
      sudo chmod -R 775 /var/www/html/lms_manager/storage
      sudo chmod -R 775 /var/www/html/lms_manager/bootstrap/cache
      
  • Restart Apache

    • XAMPP/WAMP: Use the control panel to restart Apache
    • Linux: sudo systemctl restart apache2

Nginx Configuration

If you’re using Nginx (common on Linux servers or local setups):

  • Move your project to Nginx’s root directory

    • Linux: Place lms_manager in /usr/share/nginx/html
    • Windows: Drop it into nginx/html
  • Update Nginx’s site configuration

    • Open your Nginx config file (Linux: /etc/nginx/sites-available/default; Windows: conf/nginx.conf)
    • Add this location block inside the existing server block:
      location /lms_manager {
          alias /path/to/your/lms_manager/public; # Replace with your actual path, e.g., /usr/share/nginx/html/lms_manager/public
          try_files $uri $uri/ /lms_manager/index.php?$query_string;
      
          # Handle PHP files
          location ~ \.php$ {
              fastcgi_pass unix:/run/php/php8.2-fpm.sock; # Adjust PHP version (e.g., php8.1-fpm.sock)
              # For Windows: use fastcgi_pass 127.0.0.1:9000;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME $request_filename;
              include fastcgi_params;
          }
      }
      
  • Test and restart Nginx

    • Linux: Run sudo nginx -t to check for config errors, then sudo systemctl restart nginx
    • Windows: Use the command prompt to restart Nginx (e.g., nginx -s reload)
  • Fix permissions (Linux only)

    • Same as the Apache steps: grant write access to storage and bootstrap/cache folders using the chown and chmod commands

Final Check

  • Open your Laravel project’s .env file and set APP_URL=http://localhost/lms_manager—this ensures all generated links (like assets or routes) point to the correct URL
  • Now visit http://localhost/lms_manager in your browser—it should load your project without issues!

If you hit snags with permissions, config syntax, or routing, feel free to share details—I’m happy to troubleshoot further.

内容的提问来源于stack exchange,提问作者Harsha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:59:13