This is the first part of 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 the 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 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:
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 to 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 "[code]\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'
Before we go further, let’s update the entire system to the latest versions of all packages. This is the best practice.
sudo dnf -y --refresh upgrade
Allow virtual machines that use fusefs to install 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 an overzealous 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
This has a long story to go with it, a tale of patents and Microsoft tomfoolery. 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.
Ubuntu 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
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 conscious are probably going to get triggered.
First we will make a folder in our home directory to store all our development 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 me.
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.