--- title: Build FSFE websites locally date: 2016-11-13T23:00:44+00:00 aliases: build-fsfe-websites-locally categories: - English tags: - bash - fsfe - guide - tools --- _Note: This guide is also available [in FSFE’s wiki][1] now, and it will be the only version maintained. So please head over to the wiki if you’re planning to follow this guide._ Those who create, edit, and translate [FSFE websites][2] already know that the source files are XHTML files which are build with a XSLT processor, including a lot of custom stuff. One of the huge advantages from that is that we don’t have to rely on dynamic website processors and databases, on the other hand there are a few drawbacks as well: websites need a few minutes to be generated by the central build system, and it’s quite easy to mess up with the XML syntax. Now if an editor wants to create or edit a page, she needs to wait a few minutes until the build system has finished everytime she wants to test how the website looks like. So in this guide I will show how to build single websites on your own computer in a fraction of the FSFE’s system build time, so you’ll only need to commit your changes as soon as the file looks as you want it. All you need is a bit hard disk space and around one hour time to set up everything. _The whole idea is based on what FSFE’s webmaster Paul Hänsch has coded and written. [On his blog][3] he explains the new build script. He explains how to build files locally, too. However, this guide aims to make it a bit easier and more verbose._ Before we’re getting started, let me shortly explain the concept of what we’ll be doing. Basically, we’ll have three directories: `trunk`, `status`, and `fsfe.org`. Most likely you already have `trunk`, it’s a clone of the FSFE’s main SVN repository, and the source of all operations. All those files in there have to be compiled to generate the final HTML files we can browse. The location of these finished files will be `fsfe.org`. `status`, the third directory, contains error messages and temporary files. After we (1) created these directories, partly by downloading a repository with some useful scripts and configuration files, we’ll (2) build the whole FSFE website on our own computer. In the next step, we’ll (3) set up a local webserver so you can actually browse these files. And lastly we’ll (4) set up a small script which you can use to quickly build single XHTML files. Last but not least I’ll give some real-world examples. ### 1. Clone helper repository Firstly, clone a [git repository][4] which will give you most needed files and directories for the further operations. It has been created by me and contains configuration files and the script that will make building of single files easier. Of course, you can also do everything manually. In general, this is the directory structure I propose. In the following I’ll stick to this scheme. Please adapt all changes if your folder tree looks differently. ``` trunk (~700 MB): ~/subversion/fsfe/fsfe-web/trunk/ status (~150 MB): ~/subversion/fsfe/local-build/status/ fsfe.org (~1000 MB): ~/subversion/fsfe/local-build/fsfe.org/ ``` (For those not so familiar with the GNU/Linux terminal: `~` is the short version of your home directory, so for example `/home/user`. `~/subversion` is the same as `/home/USER/subversion`, given that your username is `USER`) To continue, you have to have `git` installed on your computer (`sudo apt-get install git`). Then, please execute via terminal following command. It will copy the files from [my git repository][4] to your computer and already contains the folders `status` and `fsfe.org`. ```bash git clone https://src.mehl.mx/mxmehl/fsfe-local-build.git ~/subversion/fsfe/local-build ``` Now we take care of `trunk`. In case you already have a copy of `trunk` on your computer, you can use this location, but please do a `svn up` beforehand and be sure that the output of `svn status` is empty (so no new or modified files on your side). If you don’t have `trunk` yet, download the repository to the proposed location:
svn --username $YourFSFEUsername co https://svn.fsfe.org/fsfe-web/trunk ~/subversion/fsfe/fsfe-web/trunk### 2. Build full website Now we have to build the whole FSFE website locally. This will take a longer time but we’ll only have to do it once. Later, you’ll just build single files and not >14000 as we do now. But first, we have to install a few applications which are needed by the build script (**Warning**: it’s possible your system lacks some other required applications which were already installed on mine. If you encounter any `command not found` errors, please report them in the comments or by mail). So let’s install them via the terminal: ``` sudo apt-get install make libxslt ``` Note: `libxslt` may have a different name in your distribution, e.g. `libxslt1.1` or `libxslt2`. Now we can start building.The full website build can be started with ``` ~/subversion/fsfe/fsfe-web/trunk/build/build_main.sh --statusdir ~/subversion/fsfe/local-build/status/ build_into ~/subversion/fsfe/local-build/fsfe.org/ ``` See? We use the build routine from `trunk` to launch building `trunk`. All status messages are written to `status`, and the final website will reside in `fsfe.org`. Mind differing directory names if you have another structure than I do. This process will take a long time, depending on your CPU power. Don’t be afraid of strange messages and massive walls of text ;-) After the long process has finished, navigate to the `trunk` directory and execute `svn status`. You may see a few files which are new: ``` max@bistromath ~/s/f/f/trunk> svn status ? about/printable/archive/printable.en.xml ? d_day.en.xml ? d_month.en.xml ? d_year.en.xml ? localmenuinfo.en.xml [...] ``` These are leftover from the full website build. Because `trunk` is supposed to be your productive source directory where you also make commits to the FSFE SVN, let’s delete these files. You won’t need them anymore. ```bash rm about/printable/archive/printable.en.xml d_day.en.xml d_month.en.xml d_year.en.xml localmenuinfo.en.xml rm tools/tagmaps/*.map ``` Afterwards, the output of `svn status` should be empty again. It is? Fine, let’s go on! If not, please also remove those files (and tell me which files were missing). ### 3. Set up local webserver After the full build is completed, you can install a local webserver. This is necessary to actually display the locally built files in your browser. In this example, I assume you don’t already have a webserver installed, and that you’re using a Debian-based operating system. So let’s install `lighttpd` which is a thin and fast webserver, plus `gamin` which `lighttpd` needs in some setups: ``` sudo apt-get install lighttpd gamin ``` To make Lighttpd running properly we need a configuration file. This has to point the webserver to show files in the `fsfe.org` directory. You already downloaded my recommended config file (`lighttpd-fsfe.conf.sample`) by cloning the git repository. But you’ll have to modify the path accordingly and rename it. So rename the file to `lighttpd-fsfe.conf`, open it and change following line to match the actual and absolute path of the `fsfe.org` directory (~ does not work here): ``` server.document-root = "/home/USER/subversion/fsfe/local-build/fsfe.org" ``` Now you can test whether the webserver is correctly configured. To start a temporary webserver process, execute the next command in the terminal: ``` lighttpd -Df ~/subversion/fsfe/local-build/lighttpd-fsfe.conf ``` Until you press Ctrl+C, you should be able to open your local FSFE website in any browser using the URL http://localhost:5080. For example, open the URL
` tag starting in line 41 isn’t closed properly. ### Drawbacks The presented process and script has a few drawbacks. For example you aren’t able to preview certain very dynamic pages or parts of pages, or those depending on CGI scripts. In most cases you’ll never encounter these, but if you’re getting active with the FSFE’s webmaster team it may happen that you’ll have to fall back on the standard central build system. Any other issues? Feel free to report them as they will help to improve FSFE’s editors to work more efficiently :-) ##### Changelog 29 November 2016: Jonas has pointed out a few bugs and issues with a different GNU/Linux distribution. Should be resolved. [1]: https://wiki.fsfe.org/TechDocs/Mainpage/BuildLocally [2]: https://fsfe.org [3]: http://blog.plutz.net/The_FSFE_org_buildscript.html [4]: https://src.mehl.mx/mxmehl/fsfe-local-build [5]: https://fsfe.org/contribute/contribute.en.html