Difference between revisions of "Installing The LAMP Stack On A Server"

From Nick's Personal Wiki
Jump to navigation Jump to search
(Initial content commit, through configuring Apache)
(Content added through Completed Apache)
Line 31: Line 31:
  
 
=== Configuring Apache ===
 
=== Configuring Apache ===
 +
Before doing anything further, it is a good best practice to back up the Apache configuration file located at '/etc/httpd/conf/httpd.conf' by default and storing that default somewhere just to be safe:
 +
<nowiki>cp /etc/httpd/conf/httpd.conf /home/EXAMPLE_USER/httpd.conf.backup</nowiki>
 +
 
Create an Apache config file, httpd-mpm.conf, using the template provided below. These are settings typical for use on a smaller cloud server running on something like Linode, DigitalOcean, AWS, or Azure:
 
Create an Apache config file, httpd-mpm.conf, using the template provided below. These are settings typical for use on a smaller cloud server running on something like Linode, DigitalOcean, AWS, or Azure:
 
  <nowiki>nano httpd-mpm.conf</nowiki>
 
  <nowiki>nano httpd-mpm.conf</nowiki>
Line 44: Line 47:
 
     MaxRequestsPerChild 4500
 
     MaxRequestsPerChild 4500
 
</IfModule></nowiki>
 
</IfModule></nowiki>
 +
 +
==== Configure Name-based Virtual Hosts ====
 +
Create directories to store the files and logs for the site the server will be hosting:
 +
<nowiki>sudo mkdir -p /var/www/html/EXAMPLE/{public, logs}</nowiki>
 +
This will create a 'public' and a 'logs' directory at once, replace EXAMPLE with the domain name of the server or the IP address of the server, whichever will be used.
 +
 +
Create directories for the virtual hosts files for the server, 'sites-available' and 'sites-enabled':
 +
<nowiki>sudo mkdir -p /etc/httpd/sites-available/</nowiki>
 +
<nowiki>sudo mkdir -p /etc/httpd/sites-enabled/</nowiki>
 +
 +
Tell Apache where to look for the 'sites-enabled' directory to find the virtual hosts by adding the below to the config file '/etc/httpd/conf/httpd.conf' that was copied earlier:
 +
<nowiki>sudo nano /etc/httpd/conf/httpd.conf</nowiki>
 +
Append the below to 'httpd.conf' file:
 +
<nowiki>IncludeOptional sites-enabled/*.conf</nowiki>
 +
 +
Now that Apache knows where to look, create a virtual hosts file for it to find, replacing EXAMPLE with the name of the domain or IP address of the server again:
 +
<nowiki>cd /var/www/html/EXAMPLE
 +
sudo nano /etc/httpd/sites-available/EXAMPLE.conf</nowiki>
 +
 +
Add the below to the contents of that file:
 +
<nowiki><Directory /var/www/html/EXAMPLE/public_html>
 +
    Require all granted
 +
</Directory>
 +
<VirtualHost *:80>
 +
    ServerName EXAMPLE
 +
    ServerAdmin webmaster@localhost
 +
    DocumentRoot /var/www/html/EXAMPLE/public_html
 +
    ErrorLog /var/www/html/EXAMPLE/logs/error.log
 +
    CustomLog /var/www/html/EXAMPLE/logs/access.log combined
 +
</VirtualHost></nowiki>
 +
 +
Create a symbolic (or soft) link between the 'sites-available' directory created earlier and the 'sites-enabled' directory created at the same time:
 +
<nowiki>sudo ln -s /etc/httpd/sites-available/EXAMPLE.conf /etc/httpd/sites-enabled/EXAMPLE.conf</nowiki>
 +
 +
Reload the Apache service for all the above changes to take effect:
 +
<nowiki>sudo systemctl restart httpd.service</nowiki>
 +
  
 
== MariaDB ==
 
== MariaDB ==

Revision as of 11:28, 21 December 2023

LAMP Stack refers to the following software tools all running on the same server together:

L - Linux

A - Apache (replaceable with Nginx)

M - MySQL or MariaDB (replaceable with other database tools)

P - PHP or Python

For this page, Linux, Apache, MariaDB, and PHP will be used.


Prerequisites

Ensure that you have created, configured, and secured a remote server at least at a basic level and that all the software packages installed are up to date. A Wiki page to do so can be found here.


Apache

Installing Apache

Install Apache using the command below:

sudo dnf install httpd

Enable the Apache service, httpd.service, to start at boot:

sudo systemctl start httpd.service
sudo systemctl enable httpd.service

Check that the service has been started and is enabled:

sudo systemctl status httpd.service

Configuring Apache

Before doing anything further, it is a good best practice to back up the Apache configuration file located at '/etc/httpd/conf/httpd.conf' by default and storing that default somewhere just to be safe:

cp /etc/httpd/conf/httpd.conf /home/EXAMPLE_USER/httpd.conf.backup

Create an Apache config file, httpd-mpm.conf, using the template provided below. These are settings typical for use on a smaller cloud server running on something like Linode, DigitalOcean, AWS, or Azure:

nano httpd-mpm.conf

Inside httpd-mpm.conf, place the following -- adjust as needed for use-case:

KeepAlive Off

<IfModule prefork.c>
    StartServers        4
    MinSpareServers     20
    MaxSpareServers     40
    MaxClients          200
    MaxRequestsPerChild 4500
</IfModule>

Configure Name-based Virtual Hosts

Create directories to store the files and logs for the site the server will be hosting:

sudo mkdir -p /var/www/html/EXAMPLE/{public, logs}

This will create a 'public' and a 'logs' directory at once, replace EXAMPLE with the domain name of the server or the IP address of the server, whichever will be used.

Create directories for the virtual hosts files for the server, 'sites-available' and 'sites-enabled':

sudo mkdir -p /etc/httpd/sites-available/
sudo mkdir -p /etc/httpd/sites-enabled/

Tell Apache where to look for the 'sites-enabled' directory to find the virtual hosts by adding the below to the config file '/etc/httpd/conf/httpd.conf' that was copied earlier:

sudo nano /etc/httpd/conf/httpd.conf

Append the below to 'httpd.conf' file:

IncludeOptional sites-enabled/*.conf 

Now that Apache knows where to look, create a virtual hosts file for it to find, replacing EXAMPLE with the name of the domain or IP address of the server again:

cd /var/www/html/EXAMPLE
sudo nano /etc/httpd/sites-available/EXAMPLE.conf

Add the below to the contents of that file:

<Directory /var/www/html/EXAMPLE/public_html>
    Require all granted
</Directory>
<VirtualHost *:80>
    ServerName EXAMPLE
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/EXAMPLE/public_html
    ErrorLog /var/www/html/EXAMPLE/logs/error.log
    CustomLog /var/www/html/EXAMPLE/logs/access.log combined
</VirtualHost>

Create a symbolic (or soft) link between the 'sites-available' directory created earlier and the 'sites-enabled' directory created at the same time:

sudo ln -s /etc/httpd/sites-available/EXAMPLE.conf /etc/httpd/sites-enabled/EXAMPLE.conf

Reload the Apache service for all the above changes to take effect:

sudo systemctl restart httpd.service


MariaDB

PHP