This is my 1st post, so you may not get many things sorted out, but I will try to say it exactly the way I have done or am doing, InshaAllah.
Generally not getting any good post in Bengali I thought how I am deploying laravel site in cPanel using CI/CD and if it is as a post, it will be useful for me later and many people can also benefit my brother. So let's move on to the main task.
At first we need to login to cPanel, and go to FTP Accounts menu. After going there we need to open an FTP account. And if the account is successfully created there, it will look like the picture below.
After the account is created, save the username, server, port, they will be useful later.
After that you create the database, you must know this if you are a developer, so it is not shown.
After that you login to github, and check your project's repository.
And do as below image.
After that you can go to Action menu, and you will see an interface like below, from here click here to set up a workflow yourself, after that it will tell you to write Logic in yml. Copy and paste the following file, give your database name, username, password.
`name: Laravel CI/CD
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
web-deploy:
name: Deploying
runs-on: ubuntu-latest
services: mysql: image: mysql:5.7 ports: - 3306:3306 env: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: dbname MYSQL_USER: username MYSQL_PASSWORD: password options: '--health-cmd="mysqladmin ping --silent" --health-interval=10s --health-timeout=5s --health-retries=3' steps: - uses: actions/checkout@v2.3.2 - name: Setup PHP uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e with: php-version: '8.1.21' - name: Copy .env run: php -r "file_exists('.env') || copy('.env.example', '.env');" - name: Update .env for CI environment run: | sed -i 's/^DB_CONNECTION=.*/DB_CONNECTION=mysql/' .env sed -i 's/^DB_HOST=.*/DB_HOST=127.0.0.1/' .env sed -i 's/^DB_PORT=.*/DB_PORT=3306/' .env sed -i 's/^DB_DATABASE=.*/DB_DATABASE=dbname/' .env sed -i 's/^DB_USERNAME=.*/DB_USERNAME=username/' .env sed -i 's/^DB_PASSWORD=.*/DB_PASSWORD=password/' .env - name: Install Dependencies run: composer install --ignore-platform-reqs - name: Generate key run: php artisan key:generate - name: Wait for MySQL to be ready run: | until mysqladmin ping --host=127.0.0.1 --user=username --password=password --silent; do echo "Waiting for database connection..." sleep 5 done - name: Test Database Connection run: php -r "new PDO('mysql:host=127.0.0.1;dbname=dbname', 'username', 'password');" - name: Rollback Migrations and Seed run: php artisan migrate:fresh --seed --verbose - name: Directory Permissions run: chmod -R 775 storage - name: ? Sync files uses: SamKirkland/FTP-Deploy-Action@4.0.0 with: server: ${{ secrets.FTP_SERVER }} username: ${{ secrets.FTP_USERNAME }} password: ${{ secrets.FTP_PASSWORD }} server-dir: / local-dir: ./ exclude: | vendor/* node_modules/*
`
After that, click on the Commit changes button, then if there is any code in the master branch in your Git, then they will be stored in the public_html folder of your cpanel. And locally you need to be updated with the pool from the master branch. The 1st time will take a lot of time to upload, but from the next time it won't take much time. As soon as a new code is pushed to the master branch, it will automatically go to the server without any trouble, it takes much less time and boosts the work.
I hope you understand. If there is any mistake, please let me know in the comments.
And if you like it, please comment
Thank you.
The above is the detailed content of github CI/CD Pipeline with Laravel. For more information, please follow other related articles on the PHP Chinese website!