This is a short guide for those who are already familiar with Silverstripe development. This will allow you to set up a Gitlab project, repository and a locally configured Silverstripe installation on which you can commit and push code.
Before you begin
This guide assumes you already have:
Getting started from scratch?
If you do not yet have an existing project, you should first review the following guide: Maintaining your code.
Checking out an existing project?
When accessing GitLab you'll see a page like this (below). On the right-hand side is a listing of the projects you have access to. Access a project from here to find more information including the repository URL details:
GitLab projects overview
- Now that you have the repository URL for the project, you can check it out in your development environment with the following command:
- git clone https://gitlab.cwp.govt.nz/my-agency/my-project.git /path/to/webroot/myproject
- Replace /path/to/webroot/myproject with the path on your computer where you wish to store the project code.
- Then navigate to your project folder: cd /path/to/webroot/myproject
- To install the Silverstripe CMS packages required for the project to run, use the following command:
- composer install
This may take some time to run.
Making your first project commit
You will need to make your first commit to Git and push your project into your Git repository provided on GitLab when you signed up.
As mentioned you should not commit the packages of code managed by Composer to your project. To ensure this you need to use a .gitignore file stored in the root of your project (you should already have one of these files from the installation process).
.gitignore you store references to the folders in your project you DON'T want committed to your project Git repository.
For example, a
.gitignore for a recipe codebase might include:
/.env /resources/ /silverstripe-cache/ /themes/simple/ /vendor/ ...
Next, turn your project folder into a Git repository and commit all project files:
git init git add --all git commit -m "Create project"
Now configure your Git remote (the repository on GitLab you'll be eventually deploying your project to servers from):
git remote add origin https://gitlab.cwp.govt.nz/you/your-repo.git
Finally, push the master branch into your repository and set your local copy to watch the remote copy for changes.
git push -u origin master
Your team should now be able to commence development on the project.
Accessing the site
At this stage, you should be able to run the website on the default theme included in this recipe locally by visiting it in your browser (assuming that your LAMP stack is properly configured).
You might need to configure your admin access credentials in the
.env file to be able to access the site (see environment management docs).
Q: I can't complete the composer install command. PHP says: "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes) in phar:///usr/bin/composer"
A: Some of the modules that composer needs e.g. "framework" and "cms" are rather large and composer needs more memory to complete the requests.
memory_limit setting in php.ini to something higher than the default of 128Mb e.g. 256Mb or 512Mb and then re-try.
Q: I can't run "git remote add". git says: "fatal: remote origin already exists"
A: If you've installed via the cwp-installer package and answered "no" the question if the repository should be removed, the git remote named "origin" still exists and points at its git repository. You have two options:
- Option A: Change origin to point at your Gitlab repository:
git remote set-url origin https://gitlab.cwp.govt.nz/my-project.git
- Option B: Set a new remote, called e.g. "my-project":
git remote add my-project https://gitlab.cwp.govt.nz/my-project.git
Q: I get an error message "error: The requested URL returned error: 401 Unauthorised while accessing..." when cloning an existing GitLab repository
A: If you get this error message you can work around it by including your GitLab username in the repository URL. For example:
git clone https://email@example.com/your-organisation/your-repo.git