create-react-app build deploy on LAMP/XAMPP/WAMP

心不动则不痛 提交于 2019-12-18 15:54:33

问题


How to deploy the build on Apache WAMP/XAMPP server?

I have an app created with create-react-app and I have two pages on this application

When I execute yarn start or npm start it's working fine and all the pages are rendering properly on the URL navigation or button click

I executed the build command

npm run build

It's generating all the static and index.html files on build folder.

I moved this build folder content to www of wamp folder and execute on the url http://localhost its showing only the home page. and the next page gives 404 not found error

But when I am executing the serve module of npm command it's working fine on http://localhost:5000

serve build

Please help me how to resolve this?

I have to deploy my application on wamp server all are static pages there is no rest api contents


回答1:


By default, your react project is built to be deployed directly into your server 'www' (root) folder. Hence you may copy the contents of your project 'build' folder to the WAMP 'www' folder and then go to http://localhost/ in your browser. Your project will be displayed.

Alternatively, you may want to use a WAMP root subfolder, e.g. 'www/react/'. In this case add to your package.json file a homepage key:

"homepage": "http://localhost/react/",

Then build your project again:

npm run build

Finally, copy the contents of your project 'build' folder to 'www/react/'. To display your project visit http://localhost/react/

You may get more information in How to deploy a React App on Apache web server




回答2:


You need to configure homepage for your build.



来源:https://stackoverflow.com/questions/48183494/create-react-app-build-deploy-on-lamp-xampp-wamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!