Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter 4 by composer and deployment
#1

Hi everybody,
I must say that although I have been in love with CodeIgniter for many years, I am a beginner. So please be patient with me ;-)
I am trying CodeIgniter 4 into development environment on my PC to understand the differences with CI3 and to evaluate, in the future, the porting of my web application. I am not being very experienced with repository, Git and composer: I've always preferred manual installation; but now I'd like to better understand the potential of composer.
In the local machine I installed, as in the guide, CodeIgniter 4 through composer, together with Translations and Myth:Auth by @kilishan. Everything works like a charm! :-)
But what I would like to understand, now, is how to deploy my web application on the production machine (Ubuntu server on which currently are present Apache, PHP, MySQL and the web application CI3) in a correct way (I don't think it's copy the whole root directory...); I know that I should study and understand a bit composer... But could someone give me a quick help? In the CI 4 documentation is explained very well how to install it all, but I didn't find anything about deploying it in a production environment.
Thank you for all your fantastic work, which I have been silenty appreciating for years, and thank you in advance for any help you can give me :-)
My best regards
Reply
#2

Hi, that part are under "Running Your App".
https://codeigniter.com/user_guide/insta...nning.html

TLDR: Create a virtual host and point it to CodeIgniter 4 public folder.
Reply
#3

(04-17-2020, 12:18 PM)jreklund Wrote: Hi, that part are under "Running Your App".
https://codeigniter.com/user_guide/insta...nning.html

TLDR: Create a virtual host and point it to CodeIgniter 4 public folder.

Thank you for your reply :-)
I had read that page of the guide, but it did not contain the answers to my questions; I probably not explain myself.
I am able to configure Apache; what I wanted to understand is how I bring my local application (installed via composer) to the production server. Do I copy the entire root of the application (pointing the webroot to "public")? Or is there a way to recreate the entire application on the production server via composer?
I was wondering if someone could give me some suggestions, without having to study composer in depth.
I saw that the /composer.json file already contains the references to the repositories I installed locally, so I guess I need to copy it to the production server (via a Git repository or by copying it via ftp) and recompile it with composer. But I'm not sure what to do with the rest of the content (/app, /public ...).
Thanks again. Obviously, a "you have to learn how to use composer" is also fine as an answer... ;-)
Reply
#4

You can't download your own code with composer, it only download /vendor folder.

Manual and boring install: Transfer all files with FTP / SFTP (with or without /vendor).

Use GIT: You can use git to download / update your code that you developed elsewhere. And use Composer to download the /vendor folder*.

First time you have used git to download your code:
Code:
composer install

If you have used composer update on your local development server (and the new Codeigniter version works), you can use composer update on production server, to also download all new dependencies (after you have made a git pull for the new composer.lock**).
Code:
composer update

You should commit all your code. And use git in:
/var/www/example.com/

You will end upp with:
/var/www/example.com/public

And that's the folder apache should point to.

* You can of course upload everything except /vendor with FTP and use "composer install" as well.
** This file are ignored in .gitignore and should be removed from there, in the Appstarter. If you want to make sure your app stays exact the same.
Reply
#5

(04-17-2020, 02:02 PM)jreklund Wrote: You can't download your own code with composer, it only download /vendor folder.

Manual and boring install: Transfer all files with FTP / SFTP (with or without /vendor).

Use GIT: You can use git to download / update your code that you developed elsewhere. And use Composer to download the /vendor folder*.

First time you have used git to download your code:
Code:
composer install

If you have used composer update on your local development server (and the new Codeigniter version works), you can use composer update on production server, to also download all new dependencies (after you have made a git pull for the new composer.lock**).
Code:
composer update

You should commit all your code. And use git in:
/var/www/example.com/

You will end upp with:
/var/www/example.com/public

And that's the folder apache should point to.

* You can of course upload everything except /vendor with FTP and use "composer install" as well.
** This file are ignored in .gitignore and should be removed from there, in the Appstarter. If you want to make sure your app stays exact the same.

Thank you so much for the explanation and the time you took to write it.
Now I'm starting to get it all clearer! :-)
I think I'll opt for manual installation (as I've always done, zipping the whole application directory and with some scripts on server is a quick thing anyway).
I thought it was essential to use composer also to do some sort of deployment. Forgive my ignorance, please.

Thanks again, see you soon.
P.S. Congratulations for the great job you did: CodeIgniter 4 looks really great! I'm excited about it :-D
Reply
#6

Composer are the recommended way to get it to your machine in the first place, as you can update CodeIgniter much faster. You can always use the manual method, but that means going to our website, download, unpack etc etc. With Composer, you can open a terminal and use "composer update" and BAM Codeigniter are updated.

But after that you can deploy your files to your server any way you like. But please do consider using Git, at least for storing your changes. And for deployment, you can also revert your code faster with Git in case it broke your server. No need to unzip a whole file again.

Good luck developing your application. :-)
Reply
#7

(This post was last modified: 04-17-2020, 11:01 PM by Leo.)

Wait, I downloaded it and unpacked the zip - but I'm still able to use composer. At least it installed my plugins and updated them fine. I'm not sure if it updates Codeigniter core files this way. Does it?

edit: err, nvm, I found clear explanation in this post: https://forum.codeigniter.com/thread-757...t=composer
You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB