To automate the compilation of your React theme on cPanel or Siteworx, you need to create a script that will run the build process.
Step 1: Create the Auto Compile Script
- Access the File Manager
- Log in to your cPanel or Siteworx account.
- Navigate to the "File Manager" from the dashboard.
- Create a New Script File
- In the directory where you want to manage your React theme (usually
public_html
or a subdirectory), create a new file. You can name itcompile-react-theme.sh
.
- In the directory where you want to manage your React theme (usually
- Edit the Script File
- Open the newly created file for editing.
- Add the following script to compile your React theme:
#!/bin/bash
# Navigate to the project directory
cd /home/yourusername/public_html/yourproject
# Pull the latest changes from the repository (if using version control)
git pull origin main
# Install dependencies
npm install
# Run the build script
npm run build
-
- Replace
/home/yourusername/public_html/yourproject
with the actual path to your React project. - If you're not using a version control system like Git, you can omit the
git pull
line.
- Replace
- Save and Close the File
- Set File Permissions
- Ensure the script is executable. You can do this via the File Manager or by using an SSH terminal:
chmod +x /home/yourusername/public_html/yourproject/compile-react-theme.sh
Step 2: Running the Script Manually
- Access the Terminal
- If your hosting provides SSH access, log in via SSH.
- Navigate to the directory where the script is located:
cd /home/yourusername/public_html/yourproject
- Execute the Script
- Run the script manually:
./compile-react-theme.sh
-
- This will compile your React theme based on the latest code.
Step 3: Setting Up a Cron Job
To automate the process of compiling your React theme at regular intervals or after specific events, you can set up a cron job.
- Access the Cron Jobs Section
- In your cPanel or Siteworx dashboard, locate and click on the "Cron Jobs" icon.
- Create a New Cron Job
- In the Cron Jobs interface, you will see a form to add a new cron job.
- Set the schedule for your cron job using the provided fields (Minute, Hour, Day, Month, and Weekday). For example, to run the job every hour, you can set:
Minute: 0
Hour: *
Day: *
Month: *
Weekday: *
- Enter the Command to Run
- In the "Command" field, enter the path to your script:
/home/yourusername/public_html/yourproject/compile-react-theme.sh
-
- Replace
/home/yourusername/public_html/yourproject/compile-react-theme.sh
with the actual path to your script.
- Replace
- Save the Cron Job
- Click "Add New Cron Job" to save it. The cron job will now run automatically at the specified intervals, compiling your React theme.
Testing and Verification
- Manual Execution
- Manually run the script as described in Step 2 to ensure it works correctly.
- Cron Job Verification
- Wait for the next scheduled run of your cron job or manually trigger it via your cPanel/Siteworx interface to ensure it compiles the React theme as expected.
Automating the process of compiling your React theme on cPanel or Siteworx ensures your site is always up-to-date with the latest changes.