Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Deploy Laravel App Using GitHub Actions

Posted on Oct 5 it's very nice to build a CI/CD for your app after you finish developing or for staging to check your project on a Server, so we get the best way to do that.you can follow this lesson's steps to get your app live.to start working on the new server you need to install a lot of packages, or use a docker container, the easy way to start deploying a Laravel php app is to get a VPS from any service provider like AWS EC2 or Hetziner Cloud ...etc, after you got your VPS and it must be Ubuntu 22.01 you can follow this lesson.CloudPanel is a free and modern server control panel to configure and manage a server with an obsessive focus on simplicity.Run PHP, Node.js, Static Websites, Reverse Proxies, and Python Applications in no time on a High-Performance Technology Stack.Quick launch support for:login to your server using your terminal with SSHIf you are using a password to log in, the SSH command would be:If you are using a private key to log in, the SSH command would be:Login via SSH to the Server.now you are on the server root and the server is empty, to install the panel we need some packages to be installed first and the system to be updated.This command will update the system packages, and add the required packages.now you can start installing the CloudpanelSECURITYFor security reasons, access CloudPanel as fast as possible to create the admin user. There is a small time window where bots can create the user. If possible, open port 8443 only for your IP via the firewall.You can now access CloudPanel via Browser: https://yourIpAddress:8443Ignore the self-signed certificate warning click on Advanced and Proceed to continue to CloudPanel.we believe that the security and cache are better for any app, so we need to secure our server by using Cloudflare DNS reverser and its power of caching.it's easy to create a new Cloudflare account like any website out to this link and create a new accountto add your domain to Cloudflare, on the dashboard of Cloudflare you will find the Websites tab you can click on it and click on the right button to Add a siteafter that I will ask you to add your domain and give you a namespace to change it on your domain then go to your domain service provider and change the namespace to the Cloudflare namespace, this process can take 24 hours for some providers, I use Google Domains it takes just 10min, and now your domain is ready on the Cloudflare.now get to your domain after activating it, you will find the DNS tab click on it and add a new A Record with your server IP make sure that your Proxy status is DNS only and that can be pointed to cp. now go to your Cloudpanel click on Admin Area and then select Settings and change CloudPanel Custom Domain to cp.YOUR_DOMAIN it will generate auto SSL for you and link the domain for you, you can access the Cloudpanel using your domainto connect your project domain you need to add a new website, from the Website tab click on the Add Site button, select Create PHP Site App, fill in the details, and click on Create.now Cloudpanel will redirect and add an nginx template and PHP-FPM to point your domain, go to Cloudflare and add a new DNS A Record and point it to your server domain, then go to SSL/TLS tab and create a new Origin Server SSL, it will give you a 15 years SSL for free, copy it and go to Cloudpanel and select your new Website app and from the tab of SSL/TLS Click on actions and then Import Certificate and add the Cloudflare SSL.now your domain is linked and secured by SSL, you can access your domain with SSL and make sure that the domain is working.login to your server using your terminal with SSH with the user of a created project If you are using a password to log in, the SSH command would be:If you are using a private key to log in, the SSH command would be:Login via SSH to the Server.you are on the server user and you can generate an SSH key to link it with your GitHub Project to generate this key use this command lineand you can just click enter after finishing you will get a path ending with .pub copy the path and then use this command to view the path SSH key content and then copy itwhere.ssh/rsa.pub is the path of your keynow go to your GitHun Repo and on the Settings Tab, select Deploy keys and then add deploy Key and then select a name add your SSH key then save it.now your server has access to this repo and you can clone it so go back to your server and then on the path of the project it can look like thisand clone your repo like thisit will clone the project on the current directorynow it's time to install the composer packages and set up the project .env file follow these steps use this command to copy .env.examplenow update your details and create a new database from Cloudpanel on the Database Tab create a new database, then add the details of the database to .envchange the main URL in .env fileto install composer packages just use this commandthen you can run your project command and the important one isnow your app is ready for Frontend assets to make this work you need to install npmInstall nvm with the following command:Update the current shell environment:Install your required Node.js version e.g. 18:Activate the installed Node.js version:Done! Check the Node.js version:now you can install Yarn using this commandnow you can easily run yarn to build assetsyour project is ready now and you can view it on your browser.the next step to build your CI/CD is to create a Workflow yaml file on your project repo, on your project file create a new folder with the name .github inside this folder create another one with the name workflows In this folder create a file with the name ci.yamlnow on your yaml file add this scriptthis script takes fire when any push comes to master branch, and after testing everything on your app it will run the Script using SSH on your server by using details on the server on GitHub Secrets to change these details go to your GitHub repo and then the Settings tab, and then select Actions secrets and variables and then add a new secret with key SSH_HOST with your server IP, and you must add details like thisthen make sure you change these details on .env.examplenow it's time to create a Deploy Script on the next stepthe deploy script is the script that runs every time you make a push, so you must add a selected command when it runs every time you make a push.to add a script make a folder with the name .scripts and then create a file deploy.sh and make sure you give the file permissions to run with 755.now your deploy script is ready add to this file this script and you can custom it as you likenow push all of these updates to your GitHub repo and you will find on the Actions tab that the action is run after that, you will find the updates on your server.Templates let you quickly answer FAQs or store snippets for re-use.Amazing Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse Anurag Vishwakarma - Sep 24 Seth Phat - Sep 24 Jack - Sep 14 Bruce Simiyu - Aug 21 Once suspended, 3x1io will not be able to comment or publish posts until their suspension is removed. Once unsuspended, 3x1io will be able to comment and publish posts again. Once unpublished, all posts by 3x1io will become hidden and only accessible to themselves. If 3x1io is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to Fady Mondy. They can still re-publish the post if they are not suspended. Thanks for keeping DEV Community safe. Here is what you can do to flag 3x1io: 3x1io consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging 3x1io will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Deploy Laravel App Using GitHub Actions

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×