Welcome Guest, Not a member yet? Register   Sign In
How to run codeigniter4 in shared hosting ?
#5

Hey
there is nothing or not much in here because CI has nothing to do with server administration.
I strongly recommend to search the web for (what you probably mean and want to do) virtual hosting.
There are plenty of good sources out there, even a few almost ready to go configuration examples you can modify for your needs. I'd strongly recommend to NOT TO put your public folder into the root folder of the application.
So far I can judge it are your abilities to deal with access rights and the like not sufficient to deal with such a delicate task.

Here I put you my localhost configuration which is easy to transfer onto a distant server.
The naming can be different depending on what kind of OS you are using.

httpd.conf

Code:
#
# /etc/httpd/conf/httpd.conf
#

# --------------------------------------------------------------------------- #
# --- CGI ------------------------------------------------------------------- #
# --------------------------------------------------------------------------- #
# IMPORTANT: If you do choose to place your CGI scripts in a directory already
#            accessible from the web, DO NOT USE 'ScriptAlias'.
#            Instead, use <Directory>, SetHandler, and Options like in:
#
#            <Directory "/usr/local/apache2/htdocs/cgi-bin">
#                SetHandler cgi-script
#                Options ExecCGI
#            </Directory>

# (Example) configuration:
LoadModule cgid_module modules/mod_cgid.so
ScriptSock /var/run/cgid.sock

<IfModule cgid_module>
</IfModule>

<IfModule alias_module>
    <Directory "/srv/http/cgi-bin">
        SetHandler cgi-script
        Options ExecCGI
    </Directory>
</IfModule>

# --------------------------------------------------------------------------- #
# --- Dynamic Shared Object (DSO) Support ----------------------------------- #
# --------------------------------------------------------------------------- #
# NOTE: Further modules can be found in '/etc/httpd/modules'.
# --- Authentication --- #
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so

# --- Authorization --- #
LoadModule access_compat_module modules/mod_access_compat.so

# --- (Content) Filter --- #
LoadModule negotiation_module modules/mod_negotiation.so

# --- Logging/Status --- #
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule status_module modules/mod_status.so

# --- Multithreading and processes --- #
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

# --- Others --- #
LoadModule env_module modules/mod_env.so
LoadModule filter_module modules/mod_filter.so
LoadModule include_module modules/mod_include.so
LoadModule mime_module modules/mod_mime.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule version_module modules/mod_version.so

#--- PHP --- #
LoadModule php7_module modules/libphp7.so
AddHandler php7-script .php

# --- URL, header and file control/manipulation/redirections --- #
LoadModule alias_module modules/mod_alias.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule headers_module modules/mod_headers.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
#LoadModule userdir_module modules/mod_userdir.so

# --------------------------------------------------------------------------- #
# --- (Default) Directory Security Model ------------------------------------ #
# --------------------------------------------------------------------------- #
# NOTE: AllowOverride are types of directives allowed in .htaccess files
#       Defaults to 'all'. For security and performance reasons, do not set
#       AllowOverride to anything other than None in your <Directory /> block.

<Directory />
    AllowOverride None
    Options None
    Order Deny,Allow
    Deny from all
</Directory>

<Directory /srv/http/>
    AllowOverride All
    Options All -Indexes
    Order Allow,Deny
    Allow from all
</Directory>

Alias /public "/srv/http/public/"
<Directory /srv/http/public/>
    AllowOverride None
    Options None +SymLinksIfOwnerMatch +Indexes +MultiViews
    IndexOptions Charset=UTF-8 DescriptionWidth=64 FoldersFirst HTMLTable SuppressIcon VersionSort
    Require all granted
</Directory>

# --- Symfony Test Enfironment --- #
<Directory /srv/http/symfony.tld/myProject/public/>
    AllowOverride All
    Require all granted
</Directory>

<Directory /srv/http/symfony.tld/myProject/bundles>
    FallbackResource disabled
</Directory>

# Files description(s)
# NOTE: only for files, folder are not implemented in apache.
AddDescription "Contact" public/README
AddDescription "PGP Key" public/pubkey

Alias /error "/srv/http/error/"
<Directory /srv/http/error/>
    AllowOverride None
    Options None
    Require all granted
</Directory>

# Prevent .htaccess and .htpasswd remote access.
<Files ".ht*">
    Require all denied
</Files>

# --------------------------------------------------------------------------- #
# --- Error handling -------------------------------------------------------- #
# --------------------------------------------------------------------------- #
# Error responses come in three flavors:
# plain text, local redirects and external redirects.

#ErrorDocument 400 /error/bad_request.html
#ErrorDocument 401 /error/unauthorized.html
ErrorDocument 403 /error/forbidden.html
ErrorDocument 404 /error/not_found.html
#ErrorDocument 500 /error/internal_server_error.html
#ErrorDocument 502 /error/bad_gateway.html
#ErrorDocument 503 /error/service_unavailable.html
#ErrorDocument 505 /error/http_version_not_supported.html
#ErrorDocument 511 /error/network_authentication_requiered.html

# --------------------------------------------------------------------------- #
# --- Global configuration -------------------------------------------------- #
# --------------------------------------------------------------------------- #
AccessFileName .htaccess
AddDefaultCharset UTF-8
DefaultLanguage en
DocumentRoot /srv/http/

# NOTE: ServerRoot should be specified before this directive is used, otherwise
#       the default value of ServerRoot is used to set the base directory.
#DefaultRuntimeDir /etc/httpd

EnableMMAP Off
EnableSendfile Off
#HostnameLookups Off
#KeepAlive On
KeepAliveTimeout 5

Listen 80

#MaxKeepAliveRequests 500
#MaxRanges 200
PidFile /var/run/apache.pid
ServerRoot /etc/httpd
#Timeout 60

# --------------------------------------------------------------------------- #
# --- Module configuration -------------------------------------------------- #
# --------------------------------------------------------------------------- #
# Set the file Apache will serve if a directory is requested.
<IfModule dir_module>
    DirectoryIndex index.html index.php /index.php
</IfModule>

<IfModule headers_module>
    RequestHeader unset Proxy early
</IfModule>

<IfModule mime_module>
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType audio/ogg .ogg .ogv
    AddType text/html .shtml
    AddEncoding x-compress .Z
    AddEncoding x-gzip .gz .tgz
    AddHandler cgi-script .cgi
    AddHandler type-map var
    AddOutputFilter INCLUDES .shtml
    TypesConfig conf/mime.types
</IfModule>

#<IfModule !mpm_prefork_module>
#LoadModule cgid_module modules/mod_cgid.so
#</IfModule>

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

#<IfModule mpm_worker_module>
#    StartServers          8
#    MaxClients          150
#    MinSpareThreads      25
#    MaxSpareThreads      75
#    ThreadsPerChild      25
#    MaxRequestsPerChild   0
#</IfModule>

# Configure mod_proxy_html to understand HTML4/XHTML1.
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>

#<IfModule ssl_module>
#SSLRandomSeed startup builtin
#SSLRandomSeed connect builtin
#</IfModule>

<IfModule unixd_module>
User http
Group http
</IfModule>

# --------------------------------------------------------------------------- #
# --- Logging --------------------------------------------------------------- #
# --------------------------------------------------------------------------- #
CustomLog "/var/log/httpd/access.log" common
ErrorLog /var/log/httpd/error.log
LogLevel warn

<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>

# --------------------------------------------------------------------------- #
# --- Supplemental configuration -------------------------------------------- #
# --------------------------------------------------------------------------- #
# Configuration files in conf/extra/ directory can be included to add extra
# features/to modify default configuration of the server.

# Fancy directory listings
#Include conf/extra/httpd-autoindex.conf

# Language settings
Include conf/extra/httpd-languages.conf

# Multi-language error messages
#Include conf/extra/httpd-multilang-errordoc.conf

# php
Include conf/extra/php7_module.conf

# Server-pool management (MPM specific)
Include conf/extra/httpd-mpm.conf

# User home directories
#Include conf/extra/httpd-userdir.conf

# Various default settings
Include conf/extra/httpd-default.conf

# --------------------------------------------------------------------------- #
# --- ssl/tls --------------------------------------------------------------- #
# --------------------------------------------------------------------------- #
#LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
#LoadModule ssl_module modules/mod_ssl.so
#Include conf/extra/httpd-ssl.conf

# --------------------------------------------------------------------------- #
# --- vhosts ---------------------------------------------------------------- #
# --------------------------------------------------------------------------- #
Include conf/vhosts/codeigniter.conf
Include conf/vhosts/drupal.conf
Include conf/vhosts/ph7cms.conf
Include conf/vhosts/symfony.conf


The CI vhost file:

Code:
#
# /etc/httpd/conf/vhosts/codeigniter.conf
#

# --------------------------------------------------------------------------- #
# --- http port 80 ---------------------------------------------------------- #
# --------------------------------------------------------------------------- #
# --- default landing page port 80 --- #
<VirtualHost *:80>
DocumentRoot /srv/http/public/
HostnameLookups Off
ServerName localhost.public:80
#Redirect "https://localhost.public:443"
</VirtualHost>

# --- http://localhost.codeigniter.tld:80 --- #
<VirtualHost *:80>
CustomLog /var/log/httpd/80/codeigniter.tld.log combined
DirectoryIndex index.html index.php
DocumentRoot /srv/http/sites/codeigniter.tld/myProject/public/
ErrorLog /var/log/httpd/80/codeigniter.tld.error.log
HostnameLookups Off
LogLevel error
RewriteEngine On
RewriteOptions inherit
#ServerAdmin
#ServerAlias www.localhost.codeigniter.tld *.localhost.codeigniter.tld
ServerName localhost.codeigniter.tld:80
ServerSignature Email
UseCanonicalName On
#Redirect "https:localhost.codeigniter.tld:443*
</VirtualHost>

# --------------------------------------------------------------------------- #
# --- tls/ssl port 443 ------------------------------------------------------ #
# --------------------------------------------------------------------------- #
# Global options
#SSLCipherSuite "HIGH:MEDIUM:!SSLv3:!kRSA"                               <TODO>
#SSLProxyCipherSuite HIGH:MEDIUM:!SSLv3:!kRSA                            <TODO>
#SSLHonorCipherOrder On
#SSLProtocol all -SSLv3
#SSLProxyProtocol all -SSLv3
#SSLPassPhraseDialog  builtin
#SSLSessionCache "dbm:/run/httpd/ssl_scache"
#SSLSessionCache "shmcb:/run/httpd/ssl_scache(512000)"
#SSLSessionCacheTimeout 300
#SSLUseStapling On
#SSLStaplingCache "shmcb:/run/httpd/ssl_stapling(32768)"
#SSLStaplingStandardCacheTimeout 3600
#SSLStaplingErrorCacheTimeout 600

# --- default landing page port 443 --- #
#<VirtualHost *:443>
#DocumentRoot /srv/http/public/
#ServerName localhost.public:443
#SSLEngine on
#</VirtualHost>

# --- http://localhost.codeigniter.tld:443 --- #
#<VirtualHost *:443>
#CustomLog /var/log/httpd/443/codeigniter.tld.log combined
#DirectoryIndex index.html index.php
#DocumentRoot /srv/http/sites/codeigniter.tld/myProject/public/
#ErrorLog /var/log/httpd/443/codeigniter.tld.error.log
#HostnameLookups Off
#LogLevel error
#RewriteEngine On
#RewriteOptions inherit
#ServerAdmin
#ServerAlias www.localhost.codeigniter.tld *.localhost.codeigniter.tld
#ServerName  localhost.codeigniter.tld:443
#ServerSignature Email
#SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
#SSLCACertificateFile
#SSLCACertificatePath
#SSLCARevocationPath /srv/ssl/revoke/codeigniter.tld/revoke.crl
#SSLCARevocationFile
#SSLCARevocationCheck chain
#SSLCertificateChainFile
#SSLCertificateFile /srv/ssl/                                            <TODO>
#SSLCertificateKeyFile /srv/ssl/                                         <TODO>
#SSLEngine on
#SSLRandomSeed startup file:/dev/urandom 512
#SSLRandomSeed connect file:/dev/urandom 512
#SSLVerifyClient require
#SSLVerifyDepth  10
#UseCanonicalName On
#</VirtualHost>

Don't forget to modify your /etc/hosts file:

Code:
#
# /etc/hosts
#

# IP             Hostname              Alias

# --- localhost --- #
127.0.0.1        localhost             localhost
127.0.0.1        localhost.localdomain localhost
127.0.1.1        Arch-Linux

# --- Virtual Hosts --- #
127.0.0.1        localhost.codeigniter.tld
127.0.0.1        localhost.drupal.tld
127.0.0.1        localhost.ph7CMS.tld
127.0.0.1        localhost.symfony.tld

# --- Redirections/blocking --- #
#127.0.0.1      http://google.com

# --- IPv6 --- #
::1             ip6-localhost
fe00::0         ip6-localnet
ff00::0         ip6-mcastprefix
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters


Hope it helps and I understood your question right.
Reply


Messages In This Thread
RE: How to run codeigniter4 in shared hosting ? - by bitshifter - 03-24-2020, 03:55 PM



Theme © iAndrew 2016 - Forum software by © MyBB