# Code customization and local setup

## Access your GitHub repository

{% hint style="warning" %}
Code changes can only be done by making commits to your GitHub repository. It is not possible to make code changes through SSH or SFTP.
{% endhint %}

{% hint style="info" %}
All your environment source code is managed in a single GitHub repository.  Each environment has its own branch.
{% endhint %}

1. Log into your User Portal account by following the instructions [here](/user-portal/user-portal-access.md).
2. Select the instance you would like to know access details for in the instance drop-down.
3. Open the [GitHub Management](/application-management/github-repository-and-user-management.md) tab in the Application Management section.
4. Here you will find the URL to your project GitHub repository and the branch name where the source code for the selected instance is managed.

{% hint style="info" %}
Only GitHub users added to the [GitHub Management](/application-management/github-repository-and-user-management.md) tab can access, clone, and make changes to the repository. You can select the access level of the user - Write, Read, or Triage.
{% endhint %}

1. Add a user by clicking Add User button in the GitHub Management tab in the Application Management section.
2. Enter the existing Git username and a select role that will control the access level of the user:<br>

   **Write**: Recommended for contributors who actively push code changes to your project\
   **Read**: Recommended for non-code contributors who want to view or discuss your project

   **Triage**: Recommended for contributors who need to proactively manage issues and pull requests without writing access\
   \
   If you plan to make code changes select the Write role.<br>
3. Click Add User.

## Set up Git locally

{% hint style="info" %}
You must have Git set up locally to perform the local setup.
{% endhint %}

1. Go to the directory where you will perform the local setup.
2. Run the following commands:\
   `git init`

   `git config user.name “YOUR-GITHUB-USERNAME”`

   `git config user.email “YOUR-EMAIL-ADDRESS”`

   `ssh-keygen -t rsa -C "YOUR-EMAIL-ADDRESS"`
3. Enter the file name in which to save the generated key.
4. Copy the content from the generated file with .pub type and save it in your GitHub profile following [these instructions](https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account).

## Local setup

Local setup is supported by Linux and Mac operating systems.

{% hint style="warning" %}
**Important!** You must use your project GitHub repository when following the instructions.
{% endhint %}

### Installing prerequisites

1. Make sure that you have Node.js with a version higher or equal to 12.20 installed on your local development machine. You can check it by running this command from the terminal: `node -v`
2. Install the following [prerequisites](https://docs.create-magento-app.com/getting-started/prerequisites).

### Cloning repository

1. Clone project from your ReadyMage GitHub repository, for example:\
   `git clone git@github.com:scandipwacloud/readymage-help-demo-1119750197.git`\
   \
   **IMPORTANT!** Make sure to clone the repository to an empty directory path.

### How to set ScandiPWA locally

1. Open a terminal and navigate to cloned repository folde&#x72;**: `cd scandipwa`**
2. Run command `npm install`  and wait for this process to finish.
3. Run command `BUILD_MODE=magento npm run start`. Wait for this process to finish.

### Setting up Magento 2 locally and connecting it with ScandiPWA

1. Open a new terminal window and navigate to the cloned repository folder.
2. Run command `npm install` Wait for this process to finish.
3. Run command `npm i @scandipwa/magento-scripts@latest` Wait for this process to finish.
4. Run command `npm run start`
5. Run commands:\
   `npm run cli`\
   `magento in:rei`\
   `magento c:c`

You should now have URLs given in the terminal using which you can access Frontend and Admin Panel.

Import environment database and media in your local setup by following these instructions:

{% content-ref url="/pages/-MVHFaqQlaXr6gJWLn3o" %}
[Database and media migration](/project-development/database-and-media-migration.md)
{% endcontent-ref %}

### **Known Issues and Solutions**

**fileinfo extension not available.**\
Follow this [guide](https://docs.create-magento-app.com/usage-guide/configuring-php#installing-php-extensions) to install the missing extension.

Add fileinfo to you cma.js file like this:

```
configuration: {
  extensions: {
    fileinfo: {}
  }
}
```

Run `npm start` command.

## Making code changes

{% hint style="info" %}
Code changes can only be done by making commits to your GitHub repository. It is not possible to make code changes through SSH or SFTP.
{% endhint %}

{% hint style="warning" %}
Git must be installed on your local machine and you must have a Git account created. Follow these [instructions](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) to install Git.
{% endhint %}

1. Once the local setup is done you can make changes to your project files. Learn more on how to develop the ScandiPWA theme [here](https://docs.scandipwa.com/).
2. Before making changes make sure to switch to the specific environment branch you want to make changes to by running the following commands.\
   \
   Switch to your environment branch (replace `master` with branch name you want to make changes to):\
   `git checkout master`\
   Pull the latest code from the GitHub repository:\
   `git pull`
3. When you are happy with your changes locally you must push them to your environment branch using the following instructions:

To add all changes to your commit:

```
git add .
```

To add specific files to your commit you need to specify a path to it, for example,

```
git add app/etc/config.php
```

Commit your changes (replace Commit Message description for your changes):

```
git commit -m "Commit Message"
```

Push your changes to GitHub:

```
git push
```

4\. After you push your changes to GitHub they will be deployed automatically to your environment. Automatic deployments can be disabled and manual deployments can be used instead if you don't want to deploy on every code push. Follow the instructions [here](/project-development/code-customization-and-local-setup.md#deployments) to do it.\
5\. If you see a blank page on your frontend after deployment run the Magento cache clear command through SSH:

```
bin/magento c:c
```

{% content-ref url="/pages/-MVHFBi3IpTnJ3seuJjd" %}
[SSH Access for Magento CLI, database and media](/project-development/ssh-access-for-magento-cli-database-and-media.md)
{% endcontent-ref %}

Follow these instructions to install extensions:

{% content-ref url="/pages/-MVHFNuDs9HMqYZWZW9I" %}
[Extension installation](/project-development/extension-installation.md)
{% endcontent-ref %}

## Deployments

ReadyMage provides 2 ways to deploy code changes to your environment - automatic and manual.

### **Automatic deployments**

Automatic deployments are enabled by default. Code changes are deployed automatically to your environment on every push GitHub. You can disable or enable deployments by following these instructions:

1. Log into your User Portal account following these [instructions](/user-portal/user-portal-access.md).
2. Select the instance you would like to know access details for in the instance drop-down.
3. Open the Deployments tab in the Application Management section.
4. Use the Automatic Deployments toggle to enable or disable them.

### Manual deployments

If you have disabled automatic deployments only way to deploy code changes is by initiating manual deployment.

1. Log into your User Portal account following these [instructions](/user-portal/user-portal-access.md).
2. Select the instance you would like to know access details for in the instance drop-down.
3. Open the Deployments tab in the Application Management section.
4. Click the Start Deployment button.
5. You can check your deployment status in the Deployments tab.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.readymage.com/project-development/code-customization-and-local-setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
