Deployment using Jenkins
Doing the steps in Webserver without ssh-access can be quite cumbersome. Since this is my normal situation, I have created a simple script solution for my Jenkins CI-server, which you can also use:
- Create a new job in your Jenkins CI, e.g. "Vereniging-deploy"
- Make sure that a git client and composer are installed. Composer can be installed from https://getcomposer.org.
# Check git client git --version # Check composer composer --version
- Unpack the source code into the Jenkins workspace:
cd /var/lib/jenkins/workspace/Vereniging-deploy # Do the following steps as jenkins user sudo -u jenkins git clone https://gitlab.com/LucHamers/vereniging.git . # This will take some time, because this downloads all additional libraries sudo -u jenkins composer install
- Set some key parameters, e.g. the database connection settings for your hosting provider. Important: do change the APP_ENV in the following file to "prod", otherwise all users will see the debug toolbar, which can be a security risk!
sudo -u jenkins cp .env .env.local # and then: sudo -u jenkins vi .env.local
- In Jenkins, select the Vereniging-deploy job and click on configure
- Under Source Code Management, enter https://gitlab.com/LucHamers/vereniging.git for the repository URL, and */master at branches to build.
- Under Build, add an Excecute shell block with the following command: php deploy.php <FTP user name> <FTP password> <FTP server URI> <FTP server web directory> <vereniging install directory> <web URI> <path to php executable>, where you enter YOUR data for the variables:
FTP user name User name to be used for the FTP server FTP password User password for the ftp server FTP server URI Address for the FTP server, e.g. ftp.myserver.com FTP server web directory Directory on the FTP server in which the directory for the vereniging software has to be copied, e.g httpdoc vereniging install directory Sub directory in FTP server web directory, in which the files for the vereniging software are to be copied, e.g. member_system web URI Address of the web server under which the vereniging install directory is found on the web server, e.g. https://www.myserver.com path to php executable Path the the php executable in the correct version, e.g. /opt/php/7.3/bin/php
- Now when building this job, Jenkins will update the code locally, zip it, copy it to the FTP-server into a temp directory, remove the current directory, move the temp to the current directory, migrate the database, delete the deploy.php file.
Now you should be able to access the software on your web server. In your browser, use https://www.my-server.com/member_system/public. For a first login, use the username "firstname1.lastname1" and the password "secret1".