Hi Guys, this time I want to share how to deploy react web app on apache server.
We don’t need a node.js server to deploy a react app, with a running Apache Server we can deploy a react web app, so, in this post I will try to explain how to accomplish it.
1. In your react project go to your package.json file and adjust this line of code to match your destination domain address + folder:
[json]”homepage”: “https://yourwebsite.com/your_folder_name/”,[/json]
2. Go to terminal in your react project and type:
npm run build
3. Copy the build folder to your apache server i.e /var/www/html/your_folder_name
4. Open the Apache configuration: /etc/apache2/apache2.conf
sudo nano /etc/apache2/apache2.conf
5. Add the following snippet:
<Directory /var/www/html/your_folder_name> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
6. Make a .htaccess file inside /var/www/html/your_folder_name
sudo nano .htaccess
7. Add the following content
Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.html [QSA,L]
8. Restart Apache server:
sudo service apache2 restart
With the previous steps the react app with its urls works normally .
I hope this post can help you, and don’t forget to visit my previous post: Execute EFCore Migrations with different settings
Best Regards!