Keeping the project on GIT

Categories
Table of contents
  1. The general principle of the project on GIT
  2. How to work through GIT
  3. Create a local database
  4. Setting up a local config

Previously, we strongly recommended running projects with Git. Now, this is a required parameter for any project, at least a medium size. This makes it easier to update the site and implement improvements on it.

A lot of questions began to come to us, how exactly we recommend to conduct projects on GIT. The result of these questions was this article.

Clarification:

All the software provided in the article is recommended, but this does not mean that it is necessary to use it. The same is with the mechanism for managing projects on GIT. There are a lot of options for running projects, we worked out this option, we liked it and we decided to share it with you. Remember, you can always choose a different approach, method, or option.

The general principle of the project on GIT

We already know that to post work for verification, we need a local machine and a test server (most often this is a subdomain of the dev. Or test. Site) and the main server on which the production site is located.

The work is initially performed on the local machine, and then, when it is already possible to send something for testing to the test server, from the local machine we write the code to the repository and use the git push command in the branch that is associated with the test server (dev).

The scripts then have to push the code from the remote repository to the dev / production servers. You can also transfer manually via FTP / SSH.

For OkayCMS, there is a module specially developed by us https://okay-cms.com/products/git_project that does this.

How to work through GIT

First, we need to set up a local environment for working with the project. We will need LAMP or WAMP (Linux / Windows, Apache, MySQL, PHP), a text editor (in the example, the PhpStorm IDE will be used),

GIT itself installation instructions and composer .

GIT must be installed on the local machine and on the server.

Tip: As a fairly convenient WAMP option, you can install OpenServer ( https://ospanel.io/download/ ), it contains Apache, MySQL, PHP.

Next, we create a remote repository (a repository where the code will be permanently stored). You can use any of the resources to create a repository: github.com , bitbucket.org , gitlab.com , etc.

<> In this article, we look at running a project at bitbucket.org .

To create a repository, you need to register at bitbucket.org (or any other resource). Then, in the cabinet on the left, click + -> create -> repository . In the Project and Repository name fields, enter a meaningful name (you can use the site's domain) and check the "Private repository" option (this means that you cannot view the contents of the repository without entering a password).

After creating the repository, you will see approximately the following instructions, you will need it later.

Next, we create a local domain on the local machine, where work with the project will take place. It all depends on the LAMP / WAMP you choose and is beyond the scope of this article.

Create a local database

Next, you need to add the project files. Let's assume this is a new project. In this case, you need to install via the installer or clone the official repository https://github.com/OkayCMS/Okay3.git . In the case of cloning a repository, you need to delete the .git directory inside the project (this is a hidden directory, to see it you need to enable the display of hidden files and folders).

If OkayCMS was added via the installer, the database dump has already been loaded into the database. If it was cloned, you need to additionally load a dump from 1DB_changes / okay_clean.sql into the database.

Standard access to the admin area after a clean installation:

login - admin

password - 1234

For security reasons, we recommend changing the standard username and password or deleting the administrator account after installing via GIT

Setting up a local config

To do this, you need to create a file config / config.local.php and in it, by analogy with config / config.php, register access to the local database and the license of local domains.

License key for domains localhost, local, okay, ok, okaycms, okcms, okay-cms, ok-cms, okaycms3 :

6krnbqvtld bcwcejpzgj nvwnxosqyt ovrztnqqr1 xutb9nhlsl ik7a6y9z zqwhhrtwdx gihygryqik sxknuyr6xn qus8rtylvl fzzrotobdm 9qjpshflqm xwhjoxhmyn rumsknsnnl rdpcqnplvm rnavvrbt6f qsqs8zhofs hymnurdttq mzyfvryc kwwbrqqozk povbqn8kpx dmvkswonpz 9trlkmtwvy vnevholswk k6zvmqlzxd nppptcvivx mtkyzxxztq rmdxpympvt i9pgr7tvko nmpsklravr mtudvsskxl wwumxjcmxz fwyvktgywo gibfedydq9 ezjrhtsrzg ovjiqevq vooqyktn zp7z4wo2lx y8ylkeghxr yjsevsjvsn zikgnljhoh puvlswwsxy xvf2dlzobk obyvhepz pbvapwoyhq xwozmqqmiz skntlxuutx rfqny5xpf6 i7pp9ewg8a bzbhrlelmn kitumtymls vywouvlqpk ycostvrmsp xegu9xpifu ogay9zweyp dvxnenvnfq qwirwpyuj1 lgupzbwot6 q8xe7uixwz hegzfiqg9i qzfkfntzdu hyxpyulqsy zsxjvqvvvs xjxnptvvjm 4tkwavel6n 9xrnjokzjr nyflrlttxx sty9weslnh rjtdztqrsg yhyi3i9lhz modrzqtpou a2xjj6mlks syx6pmmhsq pkwwsvopsw vnvnznmzov 9seonrdom4 9bvdtebnom l8erpzsjpf xpndqrqjuf nhwousuyyr ux7vewsut9 6u677ypnhe shswghomud woxnwiojru nwlwwuvrvs tywtcarl74 9dp7eom9jp bzovmvjehy vvfnxuxtql stvnpyolot yvv8pmx97h xm57ukciw n zbjwnugxzh cflvpnoovo uympwotxor pbpwzevzw7 rldr88ef8v fjdw

We run the composer install command and after installing all the dependencies, the project should work.

Now open up GIT-bash (installed with the git) on Windows or bash on Linux, go to the project directory and run the git init command. This will create an empty repository. Then you need to tweak .gitignore to exclude unneeded files from version control.

Example .gitignore

compiled / * / *. php
Okay / xml / compiled / *. Php
/ vendor /
backend / design / compiled / *. php
backend / files /*/*.*

files /**/*.*
! files / ** / *. phtml

! files / ** / *. php *
! files / ** / *. cgi
! files / ** / *. exe
! files / ** / *. pl
! files / ** / *. asp
! files / ** / *. aspx
! files / ** / *. shtml
! files / ** / *. shtm
! files / ** / *. fcgi
! files / ** / *. fpl
! files / ** / *. jsp
! files / ** / *. htm
! files / ** / *. html
! files / ** / *. wml
! files / lang /*.*
cache /

Okay / log / *. Log
config / config.local.php
design / * / lang / local. *. php

! *. keep_folder
! *. htaccess
robots.txt

If you are using IDE PhpStorm or another that creates temporary files in the project directory, you need to add this directory to ignore.

It is recommended to take .gitignore from the module https://okay-cms.com/products/git_project , which maintains an up-to-date example of .gitignore for the latest version of Okay.

You need to configure the user.name and user.email parameters , this data will be displayed next to the commit as the author of the commit. To configure this, you need to run the commands:

git config --global user.name “<userName>”

git config --global user.email “<userEmail>”

In order not to enter the full path to the repository with each push or pull, you can add an alias to it. To do this, run the command from the instructions that Bitbucket gave you (the screen above) git remote add origin [email protected]/ zyxer / test_repo.git . With this, you will add a link to the repository under the alias origin.

After setting up gitignore, you need to add the files to the git add index (this command will add all project files that are not described in .gitignore) and make the first commit using the git commit -m "Init project <okayVersion>" command (the -m switch means that a comment will be added to the commit) doc .

Tip : At this point, you need to create a branch okay_clean, in which we will maintain the Okay versions, to update the project.

The update will take place like this: after the release of the new version of OkayCMS, you will need to switch to this branch, delete all files except .git and .idea (this is the PhpStorm directory, if you have a different IDE and the directory may be different), config / config.local .php and copy a completely new version of OkayCMS here (as an option, clone the public repository into a temporary directory), git will see the difference only in the files that have changed, make a commit, specify the version of OkayCMS as a comment, then go to the branch where the project is underway and merge the branch okay_clean (git merge command). Thus, even if you edited the kernel, GIT will either automatically merge branches, or offer to resolve the conflict.

Next, you need to install the Auto-build module on GIT in the master branch and make another commit. Create a dev branch from the master branch and push the master and dev branches to the remote repository using the command git push origin master (means pushing the master branch to the repository with the alias origin) and git push origin dev (it is important to push master first).

With the code already in the remote repository, you need to create a main domain and a test subdomain. It is advisable to create them on the same server so that the work is tested in conditions close to combat. The test domain usually looks like dev.domain.com . After creating the domains, you need to configure SSH key authorization between the server and bitbucket.org and clone the project from the remote repository to your server. You need to clone via SSH. This mechanism is described in more detail in the instructions for the module for managing projects on OkayCMS via git

To connect to the server via SSH from a Windows machine, you can use git bash (will work like on linux) or use

After cloning the project, you need to install all dependencies on the server using the composer install command, set up the local config and upload the database dump to the database on the server (for dev and production servers, you should keep different databases). Everything is exactly the same as on the local machine (described above).

Since the robots.txt file was excluded from GIT, on the dev server it should be created with the following content:

User-agent: *

Disallow: /

On the production server, you need to create in accordance with the latest version of OkayCMS .

It is also recommended to turn off the site on the dev server (in the site settings) so that search robots or other users "do not go" on this site.

Next, you need to configure hooks in accordance with the instructions for the module and after subsequent pushes to this repository from the local machine, the project will be automatically updated on the server.

It is impossible to edit files that are not under version control, otherwise after the next project build through the module, all changes will be erased.

Comments 1
Вася
23.09.2022, 15:51
Можна було і покрокову відео інструкцію створити...
OkayCMS
27.09.2022, 13:54
Вася, Дякую можливо зробимо
Write your comment
log in
Download OkayCMS
version 4.5.0
Subscribe to the newsletter
You will receive a selection of useful articles on working with the site on OkayCMS, discounts on modules and templates