Configuring Fedora & Localhost Setup

fedora-logo-image

This is the first part in my series of step by step guides to turn Fedora into the ultimate web development platform.

I am going to assume that you have Fedora installed already, or are comfortable installing it yourself. Once you are up and running, just run the terminal application and follow along to set up your perfect development environment.

In this guide we will discover:

  • How to set the host name, and why it’s important.
  • Which repositories to install and how to do it.
  • How to setup subpixel rendering to improve font appearance.
  • How to setup and configure your LAMP environment for localhost development.

If you have not already read my Linux for Web Development Guide please check it out.

Much of the software I will recommend is built into Fedora, but also some important 3rd party software is not. There are many pitfalls to overcome in configuring Fedora, and some seem to change slightly on a release by release basis.

This guide was created using Fedora 29. As Fedora continues to improve, occasionally a 3rd party application is brought into the official repository, or a settings file changes. Mainly bugs are fixed and no longer need workarounds, or a new application arrives that is better and replaces and old one.

Set the host name

It’s a good idea to give your computer a name so it can identify itself to other computers on the network. This will also to make it easy for you to identify your own computer if you are logged in remotely to multiple systems. When you are using the terminal it will show:

[username@hostname ~]$ 

before every command you type. If you have multiple windows open all showing you logged in from @localhost (the default) it will soon become very confusing!

So use this command:

hostnamectl set-hostname yourhostname

Enable extra repositories

Fedora only installs 100% free and open source software from its own official built in repository. It is very strict, sometimes too strict in it’s FOSS definition. We need more software than comes out of the box, and more than is available from the official repo.

The best way to get the software we want is add some extra 3rd party repositories. That way we get the following advantages over just downloading the software from the official website:

  • Time saved looking for updates, going to the site, and downloading them.
  • Automatic updates whenever we update our system.
  • Enhanced security, checksums are used when downloading.

We will install the RPM Fusion and VS Code repos:

sudo dnf -y install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'

Update everything

Before we go further, let’s update the entire system to the latest versions of all packages. This is best practice.

sudo dnf -y --refresh upgrade

Allow virtual machines that use fusefs to intall properly with SELinux

This is just a weird little one I threw in, as it could save you hours of wasted time if you use virtual machines. If you don’t enter this command, then you will enter a over zealous security paranoia hell hole trying to run a virtual machine. Just enter this and thank me later.

sudo setsebool -P virt_use_fusefs 1

Configure subpixel rendering and change desktop settings

subpixel-rendering-heading-image

This has a long story to go with it, a tale of patents and Microsoft tom foolery. You can go and read that all elsewhere if you like. The short version is if your monitor is 1080p or less you will probably benefit from enabling subpixel rendering.

I have debated with people who swear they can’t see the difference, I think they must be half blind. Without subpixel rendering <=1080p text has a slight uneven spidery appearance. With, it looks amazing. If you are lucky enough to have a really high resolution display then you totally don’t want this, it will probably make things look worse for you.

Ubutu has it by default, so do some other Linux distros. Fedora very recently enabled it in Fedora 29. To make sure it is on I recommend:

echo "Xft.lcdfilter: lcdlight" >>"$HOME/.Xresources"

Increase the amount of inotify watchers so live-server works with > 8192 files in a directory

In part 2 of this guide I will suggest you use the awesome live-server software so you can edit HTML/CSS/JS in real time, if you don't intend to follow my advice then you can safely ignore this tweak.

I don’t know if this is a hardware thing, but on my system I run into problems using live-server if I don’t make this little change:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

Setting up the LAMP for localhost Development

lamp-heading-image

This is my way of doing things. I am going to do a bit of a ‘hack’ and run Apache as the user, this saves a lot of bother setting permissions. I think it is fine for a development machine that is not facing out to the internet, but the hyper security concious are probably going to get triggered.

First we will make a folder in our home directory to store all our development sites:

mkdir ~/sites

Make a symbolic link from the Apache web directory to your sites folder:

sudo ln -s ~/sites /var/www/html

Tell SELinux that these files/directories are allowed to be modified by Apache:

chcon -R unconfined_u:object_r:httpd_sys_rw_content_t:s0 ~/sites

Change the "User apache" string in the config file to "User (the username of the current user)". For a development machine, it's more convenient to run Apache as the current user to simplify permissions problems:

sudo sed -i "s/User apache/User $USERNAME/g" /etc/httpd/conf/httpd.conf

For PHP and Fedora 27+ these config file changes are vital. (If you are using Wayland you might not be able to sudo gedit and need another tool)

sudo gedit /etc/php-fpm.d/www.conf
user =$USERNAME (was apache, make sure no space after =)
listen.acl_users = apache,nginx,$USERNAME

You can turn Apache and MySQL server on and off at the same time with this little script I created:

#!/bin/bash
 
if pgrep -x "httpd" >/dev/null; then
    read -rp "Apache is running, would you like to stop Apache and MariaDB? (y/n) " -n 1 run
    echo
    if [ "$run" == n ]; then
        exit
    fi
    echo "Stopping Apache and MariaDB..."
    sudo systemctl stop httpd.service
    sudo systemctl stop mariadb.service
else
    echo "Starting Apache and MariaDB..."
    sudo systemctl start httpd.service
    sudo systemctl start mariadb.service
fi

If Apache is running it asks if you would like to stop Apache and MySQL running, if it’s not it runs both. This works out great if you only ever run them both at once, like myself.

You can finish off by going through the MySQL security setup:

sudo systemctl start mariadb.service
sudo mysql_secure_installation

Now you have everything setup and ready to go, let's install all the software we will need in part two, Linux Web Development Tools.

I hope you have found this guide helpful. If you would like to employ me for any upcoming projects, please do not hesitate to get in contact. Please leave your feedback on this guide below and I will be sure to take it into account for future updates.

4 Replies to “Configuring Fedora & Localhost Setup”

  1. Hi David,

    I almost know everything about this but had some doughts on some issues. These articles made me feel convident to make the right decisions. Also learned some things I didn know. Thanks for the info. The inotify watchers issue f.e. I already experienced. Luckely I fugured that out pretty fast.

    I already use Fedora for some years but just switched to it (from MS) for my working environment. Need some setup and tweaking still, but Iḿ almost there. Love Fedora.

    Gonna read the rest tomorrow and than finalise my setup.

    1. Sorry about the formatting of the article, the new WordPress 5 update messed everything up! I am going to fix the whole site and do a massive update soon.

      If you are setting up localhost for development, and need PHP, then this guide is missing a few things since Fedora 27:

      # – For PHP and Fedora 27+ these config file changes are vital!
      # sudo gedit /etc/php-fpm.d/www.conf
      # —————
      # user =$USERNAME (was apache, put your username here)
      # listen.acl_users = apache,nginx,$USERNAME
      # —————

      Also check out my new fedora-ultimate-setup-script

  2. I just switched some weeks ago definitely from Windows to Linux (Fedora 29). I already have linux experience for some years running some pc’s with Fedora and a couple of VPS’s with Centos.

    I switched to Fedora for my workstation because it’s much better than Windows for so many reasons. But I had trouble setting up a local LAMP server for development. Ran in all kind off issues with Selinux.

    I found your tutorial over a week ago but missed a important part (sudo sed -i “s/User apache/User $USERNAME/g” /etc/httpd/conf/httpd.conf) ;). I now understand that was a dummie mistake.

    I therefore struggled all week with testing and try other things. Than I came back here, learned a lot this week so the commands make more sence now, and it worked within minutes.

    Thanks for the tutorial. Seems nobody has a good tutorial about this topic, not even on YT. Asking for help in Fedora form was no help, nobody answered. Are we that unique ??

    Anyway, I’ll bookmark this page for future reference.

    I could not connect to f.e. update CMS, install plugins etc (can do that by hand but don’t ant to). So I added this:

    # Allow Apache/httpd to connect
    sudo setsebool -P httpd_can_network_connect 1

    Hope this is not an extra security issue, Selinux drives me crazy. Need to learn more of that.

    Cheers.

    1. Fantastic news that my guide helped! It took me a long time to get this information, and I still have no idea why it was so difficult to get. I think quite a few people use Docker for this job, so that means even fewer people setting up localhost for development.

      I had it all working for Fedora 26, and then when Fedora 27 came along everything changed to use PHP FPM, the required settings changed again. Luckily I found the guru of all things PHP and Fedora and he helped me out, Remi has the answer to everything! https://blog.remirepo.net/post/2017/11/17/Fedora-27-changes-in-http-and-php

      Thanks for the extra config info for the CMS. I was not sure if that was needed in Fedora 27, I will add it to the guide when I do another update.

Leave a Reply

Your email address will not be published. Required fields are marked *