Welcome Guest, Not a member yet? Register   Sign In
Tutorial first app issues when not installed in doc root
#7

(This post was last modified: 05-06-2020, 11:23 AM by jreklund.)

OK, thanks for all the help.  I wanted to summarize below to make it easier for folks trying to solve the same issue:

GOAL:  Install Codeigniter 4.x using Composer on an existing website where you'd like the new Codeigniter application accessible via a URL referencing a sub directory, e.g.

Existing website: www.yoursite.org,  Apache DocumentRoot: /pub/users/you/yoursite

Desire to have new Codeigniter app accessible as: www.yoursite.org/ci-news

Follow the CodeIgniter 4.x install instructions for the demo app, briefly:


Code:
# go to your DocumentRoot
$ cd /pub/users/you/yoursite

# Install codeigniter, app framework.
$ composer create-project codeigniter4/appstarter ci-news --no-dev

# You'll then have a fully populated directory
$ ls /pub/users/you/yoursite/ci-news

app/     composer.json  env          phpunit.xml.dist  README.md  tests/   writable/
builds*  composer.lock  license.txt  public/           spark*     vendor/

NEXT - move stuff around since we want to reference via subdirectory in URL.  Create a higher level directory outside the Document Root.  It will hold all the application files and the Codeigniter install - inaccessible from Apache!

Code:
$ mkdir /pub/users/you/ci-news
$ cd /pub/users/you/yoursite/ci-news

# move everything but public to the new directory
$ mv app composer.json env phpunit.xml.dist README.md tests writable uilds* composer.lock license.txt spark* vendor  /pub/users/you/ci-news

# move everything in public up
$ mv public/* public/.htaccess .

# Once you're done you should have the following contents:

$ ls -al /pub/users/you/yoursite/ci-news
favicon.ico  .htaccess  index.php  robots.txt

$ ls -al /pub/users/you/ci-news
app composer.json  env spark  vendor builds composer.lock license.txt phpunit.xml.dist README.md  tests writable

Almost done!  Now edit a few files/permissions.

Code:
# Rename env to .env
$ cd /pub/users/you/ci-news
$ mv env .env

# Uncomment the CI_ENVIRONMENT and app.baseURL and change to:
CI_ENVIRONMENT = development
app.baseURL = 'https://www.yoursite.org/ci-news/'

# Change the ownership of the writable directory to be accessible
# by whatever user is used to execute your webserver, e.g.

$ chown -R apache.apache /pub/users/you/ci-news/writable

# IMPORTANT - change the Paths entry in the default home page

$ cd /pub/users/yoursite/ci-news/

# edit index.php
$pathsPath = FCPATH . '../../ci-news/app/Config/Paths.php';

# to check your path above, while you're in that directory, this should work
# using that path

$ ls -l ../../ci-news/app/Config/Paths.php
-rw-r--r-- 1 yoursite www 2821 May  1 01:01 ../../ci-news/app/Config/Paths.php

# one minor change in the tutorial instructions for the file
# app/Views/news/create.php

The original 'action' according to the tutorial was:
<form action="/news/create" method="post">

Change it to the below:
<form action="<?=site_url('news/create');?>" method="post">

You should then see the Codeigniter welcome page at
https://www.yoursite.org/ci-news

and be able to complete the first app tutorial!
Reply


Messages In This Thread
RE: Tutorial first app issues when not installed in doc root - by jmurtari - 05-06-2020, 06:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB