Installing Apache2 (2021)
Updated feb 2021
Install Apache2 with yast and configure it as a running service in yast, system, run levels. or simply:
systemctl start apache2.service q 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.
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 /data/galleries/ galleries/ none bind
to get the file at default place.
- mount --bind /home/srv /srv/
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.
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.
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".
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
to enable the module or
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.
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>
The default Apache Web site is in "htdocs" (very confusing for beginners).
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.
test the syntax.
also allows to test the web site, but then you have to use
before the normal
systemctl start apache.service
to make the system works normally.