Simple replacement for XAMPP stack using Arch Linux and systemd-nspawn container. There is no easy to use graphical control panel nor installer. Basic Linux, container and systemd knowledge is required.
- Apache, PHP-FPM and MariaDB are installed and will start on container boot.
127.0.0.1
/localhost
is served from/srv/.default
directory.<some-string>.localhost
is served from/srv/<some-string>
directory.- There is
root
user with empty password. - Also, there is
user
user with empty password and with enabledsudo
command. - PHP-FPM service is ran as
user
user./srv
directory is owned byuser
too. - MariaDB has
root
user with empty password. - Useful utilities like composer, git, 7zip, wget, bat are included.
- systemd-nspawn security features like private users and private network are disabled for convenience.
- Download container image:
sudo machinectl pull-tar https://github.com/TomaszGasior/webserver/releases/latest/download/webserver.tar.xz webserver --verify checksum
. You can changewebserver
name if you want. - Enable container settings file:
sudo ln -s /var/lib/machines/webserver.nspawn /etc/systemd/nspawn/
. It's good idea to read it and optionally adjust directory bindings. - Run container:
sudo machinectl start webserver
. If are you going to use it often, you may want to start it automatically on system boot:sudo machinectl enable webserver
. - Login into container:
sudo machinectl shell user@webserver
. Of course you can login asroot
but it's not recommended because files created this way will be read-only for PHP-FPM service. - If your UID is different than 1000 it might be good idea to change UID of
user
user inside container to match your own UID:sudo usermod --uid 1001 user; sudo chown user -R /srv /home/user
.
Let's imagine that you have WordPress theme in ~/projects/some-wp-theme
directory and you want to work on it.
- Login into container:
sudo machinectl shell user@webserver
. - Inside the container, create MariaDB database for WordPress:
sudo mysqladmin create wordpress
. - Create directory for WordPress in
/srv
:mkdir /srv/wordpress
. Go to that directory. - Download and extract WordPress files:
wget https://wordpress.org/latest.tar.gz; tar -xf latest.tar.gz --strip-components=1
. - Go to
http://wordpress.localhost
and install WordPress. - Outside of the container, bind your theme directory to container's file system:
sudo machinectl bind webserver ~/projects/some-wp-theme /srv/wordpress/wp-content/themes/some-wp-theme --mkdir
. You may want to consult container settings file to make this binding persistent. - Change theme in WordPress administration panel. Now, you can start your work.
The easiest way is to build this container on Arch Linux or Arch-based distribution but it might be possible also on different Linux distributions. See: Using pacman from different OS.
Keep in mind that it's unlikely that you will create exactly the same tar archive as mine because Arch Linux is rolling release distribution which means that packages version and contents may be different. (Base OS may be changed in the future.)
- Install required tools:
sudo
,systemd-nspawn
,pacman
(Arch Linux package manager),pacstrap
(included inarch-install-scripts
package in Arch Linux),reflector
(mirrors list generator, available in Arch Linux repositories). - Run
./build-container.sh
script. Read it to understand how it works, it's short. Generated files will be placed in newly createdbuild-*
directory. - You can import your tar archive using
machinectl import-tar
. Don't forget to copy*.nspawn
configuration file to/etc/systemd/nspawn
directory!