How to Publish a Website

Once you finish writing the code and organizing the files that make up your website, you need to put it all online so people can find it. This article lays out how to get your simple sample code online with little effort.

What are the options?

Publishing a website isn’t a simple topic, mainly because there are so many different ways to do it. In this article we don’t aim to document all possible methods. Rather, we’ll discuss the pros and cons of three broad strategies from a beginner’s point of view, and then walk you through one method that will work for now.

Getting hosting and a domain name

If you want total control over your published website, then you’ll probably need to spend money to buy:

  • Hosting — rented file space on a hosting company’s web server. You put your website files on this space, and the web server serves the content to web users who request it.
  • A domain name — the unique address where people can find your website, like http://www.mozilla.org, or http://www.bbc.co.uk. You rent your domain name for so many years from a domain registrar.

Many professional websites go online this way.

In addition, you will need an File Transfer Protocol (FTP) program to actually transfer the website files over to the server. FTP programs vary widely, but generally you have to log on to your web server using details provided by your hosting company (e.g. username, password, host name). Then the program shows you your local files and the web server’s files in two windows, so you can transfer them back and forth:

Tips for finding hosting and domains

  • We don’t promote specific commercial hosting companies here. To find hosting companies and domain name registrars, just search for “web hosting” and “domain names” to find a company selling domain name registrations. All such companies will have a feature to allow you to search for the domain name you want.
  • Your home or office Internet service provider may provide some limited hosting for a small website. The available feature set will be limited, but it might be perfect for your first experiments — contact them and ask!
  • There are a few free services available like Neocities, Blogspot, and WordPress. Again, you get what you pay for, but they are ideal for your initial experiments. Free services mostly don’t require FTP software for uploads either — you can just drag and drop right inside their web interface.
  • Sometimes companies provide both hosting and domains in one package.

Using an online tool like GitHub or Dropbox

Some tools let you publish your website online:

  • GitHub is a “social coding” site. It allows you to upload code repositories for storage in the Git version control system. You can then collaborate on code projects, and the system is open-source by default, meaning that anyone in the world can find your GitHub code, use it, learn from it, and improve on it. You can do that with other people’s code too! This is a very important and useful community to get involved in, and Git/GitHub is a very popular version control system — most tech companies now use it in their workflow. GitHub has a very useful feature called GitHub pages, which allows you to expose website code live on the Web.
  • Dropbox is a file storage system that allows you to save your files on the Web and have them available from any computer. Anybody with an Internet connection can access any Dropbox folder that you make publicly accessible. If that folder contains website files, it will be served as a website automatically. See Host websites With Dropbox for more information.

Unlike most hosting, such tools are usually free to use, but you only get a limited feature-set.

Using a web-based IDE such as Thimble

There are a number of web apps that emulate a website development environment, allowing you to enter HTML, CSS and JavaScript and then display the result of that code when rendered as a website — all in one browser tab! Generally speaking these tools are quite easy, great for learning, and free (for basic features), and they host your rendered page at a unique web address. However, the basic features are pretty limited, and the apps usually don’t provide hosting space for assets (like images).

Try playing with some of these examples, and see which one you like the best:

Publishing via GitHub

Now let’s take you through how to publish your site via GitHub pages. We aren’t saying this is the only way or even best way to publish your site, but it is free, fairly simple, and touches upon some new skills that you’ll find useful going forward.

Basic setup

  1. First of all, install Git on your machine. This is the underlying version control system software that GitHub works on top of.
  2. Next, sign up for a GitHub account. It’s simple and easy.
  3. Once you’ve signed up, log in to github.com with your username and password.
  4. Next, you need to create a new repo for your files to go in. Click Plus (+) in the top right of the GitHub homepage, then choose New Repository.
  5. On this page, in the Repository name box, enter username.github.io, where username is your username. So for example, our friend bobsmith would enter bobsmith.github.io.
  6. Click Create repository; this should bring you to the following page:

Uploading your files to GitHub

This is where we will have a go at using the command line to put our repository on GitHub. A command line is a window where you type in commands to do things like create files and run programs, rather than clicking inside a user interface. It will look something like this:

Note: You could also consider using a Git graphical user interface to do the same work, if you feel uncomfortable with the command line.

Every operating system comes with a command line tool:

  • Windows: Command Prompt can be accessed by pressing the Windows key, typing Command Prompt, and choosing it from the list that appears. Note that Windows has its own command conventions differing from Linux and OS X, so the commands below may vary on your machine.
  • OS X: Terminal can be found in Applications > Utilities.
  • Linux: Usually you can pull up a terminal with Ctrl + Alt + T. If that doesn’t work, look for Terminal in an app bar or menu.

This may seem a bit scary at first, but don’t worry — you’ll soon get the hang of the basics. You tell the computer to do something in the terminal by typing in a command and hitting Enter.

  1. Point the command line to your test-site directory (or whatever you called the directory containing your website). For this, use the cd command (i.e. “change directory”). Here’s what you’d type if you’ve put your website in a directory called test-site on your desktop:
    cd Desktop/test-site
  2. When the command line is pointing inside your website directory, type the following command, which tells the git tool turn the directory into a git repository:
    git init
  3. Next, go back to the GitHub site. On the current page, you are interested in the section …or push an existing repository from the command line. You should see two lines of code listed in this section. Copy the whole of the first line, paste it into the command line, and press Enter. The command should look something like this:
    git remote add origin https://github.com/bobsmith/bobsmith.github.io.git
  4. Next, type the following two commands, pressing Enter after each one. These prepare the code for uploading to GitHub, and ask Git to manage these files.
    git add --all
    git commit -m 'adding my files to my repository'
  5. Finally, push the code up to GitHub by going to the GitHub web page you’re on and entering into the terminal the second of the two commands we saw in step 3:
    git push -u origin master
  6. Now when you go to your GitHub pages’ web address in a new browser tab (username.github.io), you should see your site online! Email it to your friends and show off your mastery.

Note: If you get stuck, the GitHub Pages homepage is also really helpful.

Further GitHub knowledge

If you want to make more changes to your test site and upload those to GitHub, you simply need to make the change to your files just like you did before. Then, you need to enter the following commands (pressing Enter after each one) to push those changes to GitHub:

git add --all
git commit -m 'another commit'
git push

You can replace another commit with a more suitable message to describe what change you just made.

We have barely scratched the surface of Git. To learn more, start off with the GitHub Help site.

We will be happy to hear your thoughts

      Leave a Comment

      Web Training Guides
      Compare items
      • Total (0)
      Compare
      0