Skip to content

Instantly share code, notes, and snippets.

@rcorsari
Last active January 27, 2024 21:54
Show Gist options
  • Save rcorsari/158e9ef2bf33900270d428d93b7ee0e3 to your computer and use it in GitHub Desktop.
Save rcorsari/158e9ef2bf33900270d428d93b7ee0e3 to your computer and use it in GitHub Desktop.
How To Add Codeigniter App Site to Apache2 2.4.x on linux

Add Codeigniter app site to Apache2 web server on Ubuntu

(tested on Ubuntu 22.04 and Apache 2.4.52)

PREMISES:

  • here the website is a PHP framework app called appname which has a /appname/public folder which is the one to browse
  • I want also a virtual host appaname.box which later will allow to browse to http://appname.box
  • It will listen on port 80

1. Add site configration

  • Go to /etc/apache2/sites-available
  • Open terminal and execute sudo cp 000-default.conf appname.box.conf
  • Open site config sudo nano appname.box.conf and change content to:
<VirtualHost *:80>

	ServerAdmin [email protected]

	ServerName appname.box

	ServerAlias appname.box

	DocumentRoot "/var/www/appname/public"

	ErrorLog ${APACHE_LOG_DIR}/error.log

	CustomLog ${APACHE_LOG_DIR}/access.log combined

	<Directory "/var/www/appname/public">
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all
	</Directory>

</VirtualHost>

2. Enable site and restart apache

  • Enable site - sudo a2ensite appname.box.conf
  • Restart Apache - sudo service apache2 restart

to disable site use sudo a2dissite appname.box.conf

3. Configure local hosts file

In the file appname.box.conf the line ServerAlias appname.box after ServerAdmin creates the virtual host

  • Go to /etc, open terminal and execute sudo nano hosts.
  • Add line 127.0.0.1 appname.box
  • Configure hosts on each computer of your LAN that should use the app
  • Restart Apache

4. Browse site

Open http://appname.box in the browser.

5. Possible issues with permissions

if browsing to http://appname.box results in a blank empty webpage, change user owner at the app site tree to Apache2 www-data user with chown -R www-data:www-data /path/to/MySite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment