Skip to content

Instantly share code, notes, and snippets.

@taras-d
Last active January 27, 2024 20:47
Show Gist options
  • Save taras-d/b4302e3320d42e7b440dbacf6863de86 to your computer and use it in GitHub Desktop.
Save taras-d/b4302e3320d42e7b440dbacf6863de86 to your computer and use it in GitHub Desktop.
Add site to Apache web server on Ubuntu

Add site to Apache web server on Ubuntu

(tested on Ubuntu 14.04 and Apache 2.4.7)

1. Add site configration

  • Go to /etc/apache2/sites-available, open terminal and execute sudo cp 000-default.conf MySite.conf.
  • Open site config sudo gedit MySite.conf and change content to:
Listen 8022
<VirtualHost *:8022>
	ServerAdmin webmaster@localhost
	DocumentRoot /path/to/MySite
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
	<Directory /path/to/MySite>
		Require all granted
	</Directory>
</VirtualHost>

2. Enable site and restart apache

  • Enable site - sudo a2ensite MySite.conf (to disable site use sudo a2dissite MySite.conf)
  • Restart Apache - sudo service apache2 restart

3. Browse site

Open localhost:8022 in the browser.

If you get 403 error while loading site content files, open terminal in your site folder and execute sudo chmod -R 755 .

If you get 404 error with "javascript" subfolder, open terminal and run sudo apt-get remove javascript-common

4. (optional) Configure local hosts file

  • Open your site config file (MySite.conf), add line ServerAlias mysite.com after ServerAdmin and change port to 80.
  • Go to /etc, open terminal and execute sudo gedit hosts.
  • Add line 127.0.0.1 mysite.com.
  • Restart Apache.
@rcorsari
Copy link

I would add a TIP: if a white page shows when browsing the site could be you have wrong permissions
e.g. in linux you should run chown to user www-data (apache2 user) the whole site tree
#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