This is a Next.js application for HDM Xperts, a platform to connect clients with expert consultants.
This project was developed by Abdselam Kedir, an Xpert at HDM.
Follow these steps to get the project running on your local machine for development and testing purposes.
- Node.js (v18.x or later recommended)
- npm or yarn
-
Clone the repository (if you haven't already):
git clone <your-repository-url> cd <repository-directory>
-
Install dependencies: Using npm:
npm install
Or using yarn:
yarn install
-
Run the development server:
npm run dev # or yarn devThis will start the Next.js development server, typically on
http://localhost:3000(orhttp://localhost:9002as specified in yourpackage.json). Open this URL in your web browser to see the application. -
(Optional) Running Genkit Dev Server: If you are working with Genkit AI flows, you might need to run the Genkit development server in a separate terminal:
npm run genkit:dev # or for watching changes npm run genkit:watch
To create an optimized production build:
npm run build
# or
yarn buildThis command generates a .next folder containing the production-ready application.
Deploying a Next.js application to a cPanel hosting environment typically involves setting up a Node.js application server.
- Your cPanel hosting must support Node.js applications (often via "Setup Node.js App" or a similar interface).
- SSH access might be helpful for troubleshooting but is not always strictly necessary if cPanel's tools are comprehensive.
-
Build the Project: Ensure you have a production build of your application. Run the following command locally or on your build server:
npm run build
-
Prepare
server.js: This project includes aserver.jsfile in the root directory. This file is a custom Node.js server script to run your Next.js application. Ensure this file is present in your project root. -
Upload Project Files to cPanel:
- Compress your project directory into a
.zipfile. Make sure to include:- The
.nextfolder (from the production build) - The
publicfolder package.jsonpackage-lock.json(oryarn.lock)next.config.jsserver.js- Any other necessary configuration files (e.g.,
.env.productionif used, though environment variables are better managed via cPanel's interface).
- The
- Do NOT include the
node_modulesfolder in your zip. - Upload the
.zipfile to your desired application directory on the server (e.g.,/home/your_cpanel_user/your_next_app) using cPanel's File Manager. - Extract the
.zipfile in the File Manager.
- Compress your project directory into a
-
Set Up Node.js Application in cPanel:
- Log in to your cPanel.
- Find and open the "Setup Node.js App" (or similar named) tool.
- Click "Create Application":
- Node.js version: Select a recent LTS version (e.g., 18.x, 20.x).
- Application mode: Set to "Production".
- Application root: Enter the path to the directory where you uploaded your project files (e.g.,
/home/your_cpanel_user/your_next_app). - Application URL: Select the domain or subdomain you want your application to be accessible from.
- Application startup file: Enter
server.js.
- Click "Create".
-
Install Dependencies on the Server:
- Once the application is created in the cPanel interface, scroll down to the section for your app.
- There should be an option to "Run NPM Install". Click this to install the production dependencies defined in your
package.json. This will create thenode_modulesfolder on the server.
-
Set Environment Variables (if needed):
- If your application requires environment variables (e.g., for API keys, database connections), add them using the "Environment Variables" section in the cPanel Node.js app interface.
- For example,
PORTis often automatically provided by cPanel, but you might needNODE_ENV=production.
-
Start/Restart the Application:
- In the cPanel Node.js app interface, click "Restart" (or "Start" if it wasn't started automatically).
- Check the logs provided in the cPanel interface for any startup errors.
-
.htaccessConfiguration (if needed for routing):- cPanel often uses Apache with Phusion Passenger. Passenger might automatically configure routing.
- However, if your application is not at the root of the domain or if you face routing issues, you might need to add an
.htaccessfile in the public-facing directory that your "Application URL" points to (e.g.,public_htmlorpublic_html/your_app_subdirectory). - A common
.htaccessconfiguration for proxying to a Node.js app (whereYOUR_APP_PORTis the port your Node.js app is internally running on, often managed by Passenger and not explicitly set by you in this cPanel setup):Often, the "Setup Node.js App" tool in cPanel handles the necessary Passenger configuration, and you might only need to ensure your Application URL is correctly mapped to the public directory.# This .htaccess might not be strictly necessary if Passenger handles routing correctly. # PassengerEnabled on # PassengerAppRoot /home/your_cpanel_user/your_next_app # PassengerAppType node # PassengerStartupFile server.js
-
Verify:
- Open your application URL in a browser to ensure it's working correctly.
- Check Logs: The cPanel Node.js app interface usually provides access to
stderrandstdoutlogs. These are crucial for diagnosing issues. - Node.js Version: Ensure the Node.js version selected in cPanel is compatible with your project and its dependencies.
- File Paths: Double-check all paths in your cPanel configuration (Application Root, Startup File).
package.json: Ensure yourstartscript inpackage.jsonis suitable (e.g.,next start) or that yourserver.jscorrectly starts the Next.js production server. For this project,server.jshandles it.- Hosting Provider Documentation: Consult your hosting provider's specific documentation for deploying Node.js applications, as they may have unique configurations or recommendations.
This guide provides a general approach. Specific steps might vary slightly based on your cPanel version and your hosting provider's setup.