最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Running a Laravel project locally with XAMPP and starting automatically on Windows startup without php artisan serve - Stack Ove

programmeradmin4浏览0评论

EDITED So i bought this Laundry POS Application from codeanyon and want to run it on stand alone computer ( not server) or hosting online This is the app purchased.

Also this is their documenation which seems to be obselete and old Here.

while discussing with them, they said i can use XAMPP, however with all the support shared by stackoverflow fellow professionals, it was adviced not to. thus ill do as adviced after having help to deploy.

As i understood, the app uses artisan to install requiremnts. i have done that with no sucess.

** Can anyone help me properly run the application as when i reach php artisan serve and open http://127.0.0.1:8000/install and provide the required settings and click next, nothing happens although in backgroup i see db create in myphp

EDITED So i bought this Laundry POS Application from codeanyon and want to run it on stand alone computer ( not server) or hosting online This is the app purchased.

Also this is their documenation which seems to be obselete and old Here.

while discussing with them, they said i can use XAMPP, however with all the support shared by stackoverflow fellow professionals, it was adviced not to. thus ill do as adviced after having help to deploy.

As i understood, the app uses artisan to install requiremnts. i have done that with no sucess.

** Can anyone help me properly run the application as when i reach php artisan serve and open http://127.0.0.1:8000/install and provide the required settings and click next, nothing happens although in backgroup i see db create in myphp

Share Improve this question edited Mar 17 at 6:35 First Major asked Mar 15 at 17:39 First MajorFirst Major 298 bronze badges 8
  • The php artisan serve command opens a direct port to your Laravel project so that it can be easily accessed. I'm not entirely sure what you're trying to automate. For production code, you should point your domain to the /public directory. This way, example , which points to the public folder, will route all incoming requests to /public/index.php due to the .htaccess file in that folder. – rozsazoltan Commented Mar 15 at 17:43
  • Whats the point of running Laravel with the command 'php artisan serve'? – rozsazoltan Commented Mar 15 at 17:44
  • Thank you fo rthe quick reply. to be honest i am a compelte newbie and stubborn person that wants to do the solution myself. The app is a POS app for a restaurnt i own ( actually mini cafe) and i liked the challange to do it myself without a developer as i come from an IT background, but it appaers i defenetly lack development tech skills. can you guide please – First Major Commented Mar 15 at 17:46
  • XAMPP is outdated software. For development, you don't need anything extra, just PHP and an SQL server. With PHP, you can then open a port to any folder: php -S $host:$port -t public/ – rozsazoltan Commented Mar 15 at 17:47
  • 1 I understand eveyones professionalism , especially mentinoning prod enviroment , which is good practive to have an admin startup the server , service, app server etc while debugging. Ill ask the question directly as adviced by rozsazoltan. But i am a small one person business, and would like the POS app to startup when windows starts , as simple as that. in return i would just pop up the broweer and login – First Major Commented Mar 15 at 18:03
 |  Show 3 more comments

2 Answers 2

Reset to default 1

I see that your project is located in the htdocs folder by default. In this case, without any modifications, you can access the public folder on port 80 using:

http://localhost/AppName/public/index.php

If the goal is to make your application secure locally and prevent direct access to files belonging to other projects (e.g., http://localhost/AppName/.env), then it is necessary to change the htdocs folder so that it points to your project's public folder. This is a huge security vulnerability, as the database password, for example, is stored in the .env file.

This way, you can access the public folder via http://localhost, and there will be no possibility to load content outside of the public folder. (Yes, in this case http://localhost/../.env will invalid request.)

Note: In my answer, I am not using the exact paths you provided, as I am trying to generalize the instructions. However, C:\path\to\laravelproject refers to your D:\xampp\htdocs\AppName directory.

Requirements

To host a website from your own machine on an internal network, you need a web server. XAMPP can be a great option for this, especially if you configure it to start automatically when Windows boots up.

  • Set your xampp.exe to start automatically on Windows startup.
  • In XAMPP, configure it to automatically start the web server and MySQL when the app launches (so you don't have to start them manually).

After that, you just need to manipulate the default root directory of the localhost:80 web address started by XAMPP - which is set to .\xampp\htdocs by default -; so that it points to the Laravel's public folder.

Set public directory with XAMPP

Solution #1: Change XAMPP default htdocs folder path (recommended)

Find and open the C:\path\to\xampp\apache\conf\httpd.conf file.

Look for a line where the DocumentRoot is set to C:\path\to\xampp\htdocs. Change it to:

DocumentRoot C:\path\to\laravelproject\public

If you want to continue using PHPMyAdmin, you will need an additional alias as well.

Find and open the C:\path\to\xampp\apache\conf\extra\httpd-xampp.conf file.

Look or create a new line where the Alias /phpmyadmin is set to C:\path\to\xampp\htdocs\phpMyAdmin. If not exists create this new line:

Alias /phpmyadmin "C:\path\to\xampp\htdocs\phpMyAdmin"

After that should restart XAMPP webserver.

Solution #2: Copy project's public folder to htdocs

By default, it will host the C:\path\to\xampp\htdocs folder. You should place the contents of your Laravel project's public folder inside the C:\path\to\xampp\htdocs folder.

If you choose to copy, you will need to make edits in the copied index.php file. You will find some relative paths that look for files in a parent directory. These need to be rewritten to point to your Laravel project.

Solution #3: Create a symlink from htdocs to project's public

On Windows, creating a symlink could also work, like C:\path\to\xampp\htdocs --> C:\path\to\laravelproject\public).

# By default htdocs existed, remove it by rename
ren "C:\path\to\xampp\htdocs" "C:\path\to\xampp\htdocs.bak"

# Run as administrator from cmd
mklink /D "C:\path\to\xampp\htdocs" "C:\path\to\laravelproject\public"

Note: I would not apply the descriptions of Solution #2 and #3 directly to the htdocs folder, but rather to the .\htdocs\myproject folder. In this case, however, the URL for your web application would not be http://localhost, but rather http://localhost/myproject.

Call project from browser

After this, you can load your Laravel project in the browser via the http://localhost port. (If there is no port specified, it refers to port 80, meaning by default, XAMPP is accessible via localhost:80.)

In your Laravel project's .env file, change the default paths from http://localhost:8000 to http://localhost. If you're not using this machine directly, I recommend using your computer's internal network IP address instead of localhost: http://192.168.0.100.

Note: If the machine from which you want to access the locally hosted website is not on the same network as the "server" machine, you can set up a virtual LAN network, for example, using RadminVPN or similar services. But in this case, you would need to set your VPN address in the .env file.

Installation as production

If you do not intend to develop or modify this application, it is advisable to set it up as a "production" version.

  • Laravel - What steps should one take to make a Laravel app ready for production mode

You can just change xamp to Laravel herd. When you use Laravel Herd, you don't need to run any command, just keep the project in the Herd folder and in your browser hit project__name.test this will work for every project.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论