Apache: Difference between revisions

From Piszczynski
 
(2 intermediate revisions by the same user not shown)
Line 69: Line 69:
install mb-string extenstion for mediawiki
install mb-string extenstion for mediawiki
<syntaxhighlight lang="bash">sudo apt install php7.4-mbstring</syntaxhighlight>
<syntaxhighlight lang="bash">sudo apt install php7.4-mbstring</syntaxhighlight>
== Update Certificate ==
Use openssl to extract any certs required from .pfx:<syntaxhighlight lang="bash">
#install ssl
sudo apt install openssl
#extract certs in directory containing .pfx
openssl pkcs12 -in *.pfx -nokeys -out new_certificate.crt
#Extract the private key
openssl pkcs12 -in *.pfx -nocerts -out privatekey.pem
#remove encryption from private key
openssl rsa -in priv.pem -out new_certificate_privatekey.key
</syntaxhighlight>then check the location that the certificates are located from the .conf files, usually the default site:<syntaxhighlight lang="bash">
cat /etc/apache2/sites-enabled/000-default.conf
</syntaxhighlight>place the new certificates in the location where the .conf specifies with the same file names or place in a different location and update the .conf files
Then restart apache:<syntaxhighlight lang="bash">
sudo service apache2 restart
</syntaxhighlight>

Latest revision as of 13:51, 25 March 2024

Apache web server details

Ref

main directory: /etc/apache2

There are a number of plaintext files and some subdirectories within this directory. Here are some useful locations to be familiar with:

  • apache2.conf:

This is the main configuration file for the server. Almost all configuration can be done from within this file, although it is recommended to use separate, designated files for simplicity. This file will configure defaults and be the central point of access for the server to read configuration details.

  • ports.conf:

This file is used to specify the ports that virtual hosts should listen on. Be sure to check that this file is correct if you are configuring SSL.

  • sites-available/ and sites-enabled/:

The sites-available directory contains virtual host file configurations. Configurations within this folder will establish which content gets served for which requests. This is enabled through linking to the sites-enabled directory, which stores activated virtual host configuration files. When Apache starts or reloads, it reads the configuration files and links from within the sites-enabled directory as it compiles a full configuration.

  • conf-available/ and conf-enabled/:

These directories house configuration fragments that are unattached to the virtual host configurations files.

  • mods-enabled/ and mods-available/:

These directories define modules that can be optionally loaded. The directories contain two components: files ending in .load, which contain fragments that load particular modules, and files ending in .conf, which store the configurations of these modules. Apache configuration does not take place in a single monolithic file, but instead happens through a modular design where new files can be added and modified as needed.

Apache2.conf file

  • /etc/apache2/apache2.conf

The main configuration details for your Apache server are held in the /etc/apache2/apache2.conf file. This file is divided into three main sections:

  • Configuration for the global Apache server process
  • Configuration for the default server
  • Configuration of virtual hosts.

Virtual Host File

  • /etc/apache2/sites-available/000-default.conf

Contains the configuration for the virtual hosts and what ports they will respond to. The default is set to respond on port 80 on any interface

Commands

Restart Apache service

sudo systemctl restart apache2


Disable default website

sudo a2dissite 000-default.conf

Enable website

sudo a2ensite your_site.conf

Troubleshooting

Check logs:

sudo less /var/log/apache2/error.log

Install PHP

Install basic components

sudo apt install php7.4 php7.4-common php7.4-cli


Install the Apache PHP Module:

install the libapache2-mod-php package to enable PHP support in Apache:

sudo apt install libapache2-mod-php7.4

Enable the PHP Module:

sudo a2enmod php7.4

install mb-string extenstion for mediawiki

sudo apt install php7.4-mbstring

Update Certificate

Use openssl to extract any certs required from .pfx:

#install ssl
sudo apt install openssl

#extract certs in directory containing .pfx
openssl pkcs12 -in *.pfx -nokeys -out new_certificate.crt

#Extract the private key
openssl pkcs12 -in *.pfx -nocerts -out privatekey.pem

#remove encryption from private key
openssl rsa -in priv.pem -out new_certificate_privatekey.key

then check the location that the certificates are located from the .conf files, usually the default site:

 cat /etc/apache2/sites-enabled/000-default.conf

place the new certificates in the location where the .conf specifies with the same file names or place in a different location and update the .conf files Then restart apache:

sudo service apache2 restart