Installing Apache2 (2022)
< MySQL - Mariadb 2021 | Configuring a small home server in 2021 with openSUSE Leap 15.3 | Peering with me (dodin.fr.nf, 2021) >
Updated from August 2022. May be also for Debian.
Apache2
Install
Install Apache2 with yast and configure it as a running service in yast, system, run levels. or simply:
systemctl start apache2.service systemctl enable apache2.service
You need to restart apache after any setup change. The best way to do it is "apache2ctl restart", because apache2ctl makes a syntax check and report very useful infos.
apache2ctl restart apache2ctl -t
only check the config files syntax (very useful to fix typos)
File location
In openSUSE, files are located at /srv. I don't like this place because I don't want to share data and system on the same partition.
On Leap 15.3, /srv is a subvolume. After moving the content to /home/srv, I had to remove /srv with:
btrfs subvol delete /srv
And comment out the "srv" line in fstab. May be it's not the best btrfs way to do, but it works.
Of course, later, you have to give the real place in apche2 config files, beginning with /etc/apache2/default-server.conf.
You can also use, for example, in /etc/fstab:
/home/srv /srv/ none bind
to get the file at default place.
Manually it's:
mount --bind /home/srv /srv/
Test
Locally, you can test apache with w3m a CLI browser, installed by default. Write in /srv/www/htdocs an index.html file with, for example "index de /srv/www/htdocs" (no need for any html syntax). Then, "w3m localhost" should read this very file.
External setup
Setup your Domain Name Zone for your domain name (that is make your domain name equivalent to your IP). If you have only one domain name and you need to keep contact to the old server, use subdomain. If not you can type the IP in the URL window.
Don't forget many web applications use mysql, so mysql have to be configurerd before.
Default setup
Index file
You need an index file. I advice you to place an "index.html" file in any htdocs folder you have on your computer, with a small text giving clue where it is. For example "nemo root" for /srv/www/htdocs/index.html. I couldn't make links work at the beginning of the setup, so why I need to know what is apache displaying if any. No html tag necessary at the moment.
Calling your domain name on a browser should display "nemo listening".
Modules activation
Apache modules are the mod_XXX, for example mod_rewrite, and give access to system variables like RewriteEngine.
The way these modules are setup varies among linux distributions, so what is done for openSUSE do not match necessary what is done for Debian.
openSUSE installs all (or most) modules by default, but do not activate all of them. The activation is done by adding the module name in /etc/sysconfig/apache, but this is not carved in stone, so better use the prefered way, that is
a2enmod
to enable the module or
a2dismod
to disable it.
This changes the file /etc/apache2/sysconfig.d/loadmodule.conf. It's seriously discouraged to manipulate this file yourself, as things may change and this file desapear without notice.
It's also possible to use YaST, but I found the YaST httpd module very agressiven that is if you use it, do not try to change anything by hand. Do not mix YaST and vi on a config.
Vhosts
openSUSE
The Apache config is tightly tied to virtual hosts. openSUSE places virtual hosts in /etc/apache2/vhosts. Any file ending by .conf is read, in alphabetical order. To move a server, copy these files to the new position. There is no "validation" folder as you can find in Debian based distros. Rename the file (for example remove the "f" of conf) to invalidate a file.
I don't think the read order matters. The files are read in alphabetical order. However, it seems than if the web server is called by IP (numérical) and not by name the default file used is the first read. So it may be a good idea to name local.conf "__local.conf" if it's to be the default
"local.conf" file can be setup as:
# forbid access to the entire filesystem by default <Directory /> Options None AllowOverride None Order deny,allow Deny from all </Directory> # Configure the default DocumentRoot # <Directory "/home/data/srv/www/htdocs"> Options FollowSymLinks Includes AllowOverride All Order allow,deny Allow from all </Directory>
Debian
The Debian way is to have two folders,
sites-available sites-enabled
The first one is where config files are stored. The second hold only links to the previous.
to enable a site, it's better to use a provided script
a2ensite example.com.conf a2dissite example.com.conf
to disable the same site
Web Site
The default Apache Web site is in "htdocs" (very confusing for beginners).
.htaccess
For these files to work you have to keep "AllowOverride All" or similar to make .htaccess with "Order Deny,Allow Deny from all" to work and hide data files.
Testing
apache2ctl configtest
test the syntax.
apache2ctl start
also allows to test the web site, but then you have to use
apache2ctl stop
before the normal
systemctl start apache.service
to make the system works normally.
< MySQL - Mariadb 2021 | Configuring a small home server in 2021 with openSUSE Leap 15.3 | Peering with me (dodin.fr.nf, 2021) >