LAMP Setup
Setting up the LAMP stack (Linux, Apache, MariaDB/MySQL, PHP) on Arch Linux involves installing each component separately using pacman
and then configuring them to work together.
1. Update the System
Always start by ensuring your system is fully updated.
2. Install and Start Apache (Web Server)
Install the Apache web server package, which is named apache
on Arch.
-
Install Apache:
-
Enable and Start the Service:
enable
: Configures the service to start automatically on boot.--now
: Starts the service immediately.- The Apache service on Arch is named
httpd
.
-
Verify Apache:
- Open your web browser and navigate to
http://localhost
. You should see the default Apache "It works!" page. The default web root directory is typically/srv/http
.
- Open your web browser and navigate to
3. Install and Configure MariaDB (Database)
MariaDB is the default MySQL implementation in the Arch repositories.
-
Install MariaDB:
-
Initialize the Data Directory:
- You must initialize the database directories before starting the service for the first time.
-
Enable and Start the Service:
-
Secure the Installation:
- Run the security script to set the root password and remove test users/databases. Note: The MariaDB root password is not your system root password.
- Press Enter for the current root password (as it's the first time), then follow the prompts to set a new root password and answer 'Y' to the security questions.
4. Install and Configure PHP
Install PHP and the necessary Apache module (php-apache
).
-
Install PHP and Module:
-
Configure Apache to Use PHP:
- Edit the main Apache configuration file:
- A. Change the Multi-Processing Module (MPM):
- Comment out
mpm_event_module
(add#
to the start of the line). - Uncomment
mpm_prefork_module
(remove#
from the start of the line).
- Comment out
- B. Load the PHP Module:
- Add the following lines to the end of the file:
- Save the file (
Ctrl+O
, thenEnter
) and exit (Ctrl+X
).
-
Enable Database Extensions (Optional but Recommended):
- For PHP to interact with MariaDB, edit the main PHP configuration file:
- Search for the following lines and uncomment them (remove the
;
at the start of the line):
-
Restart Apache:
- The web server must be restarted for all changes to take effect.
5. Test PHP
- Create a Test File:
- Create a file named
info.php
in the web root directory (/srv/http
).
- Create a file named
- Add PHP Code:
- Paste the following content:
- Verify Installation:
- Open your web browser and navigate to
http://localhost/info.php
. If you see the detailed PHP configuration page, the LAMP stack is correctly installed and configured.
- Open your web browser and navigate to