Product docs and API reference are now on Akamai TechDocs.
Search product docs.
Search for “” in product docs.
Search API reference.
Search for “” in API reference.
Search Results
 results matching 
 results
No Results
Filters
How to Install a LAMP Stack on Fedora, AlmaLinux, or Rocky Linux
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
The most common web architecture for Linux-based systems is the LAMP Stack. This stack includes all necessary components for a web application, including an operating system, web server, relational database, and programming language. This guide explains how to install and test a LAMP stack on the Fedora Linux platform and the related AlmaLinux and Rocky Linux distributions.
What is a LAMP Stack?
The LAMP stack is a core architecture for the open source Linux environment. LAMP is an acronym standing for Linux, Apache, MySQL or MariaDB, and PHP, Perl, or Python. This software stack is sufficient to support most modern web sites and applications, including WordPress.
The main LAMP stack components are as follows:
Linux: Linux is a free and open source UNIX-based operating system. It is available in several distinct implementations, called distributions. This guide uses Fedora, one of the most popular distributions. The same instructions in this guide are also applicable to the similar AlmaLinux and Rocky Linux platforms. Both of these alternatives are binary-compatible with Fedora. Each distribution of Linux has its own software library which includes the other LAMP stack components.
Apache: The open source Apache web server is the most common Linux web server. The Apache Software Foundation produces the free standard edition, containing all components required to host a web site. However, extra modules enable additional features such as authentication and programming language APIs.
MariaDB/MySQL: MySQL and MariaDB are free and open source relational database management systems (RDBMS). They can be used interchangeably in the LAMP Stack. MariaDB is a fork of the original MySQL code with additional features, higher scalability, and faster query speed.
PHP/Perl/Python: PHP is the main server-side scripting and programming language for the LAMP stack. PHP commands can be efficiently embedded within an HTML page, making it a very useful language for web development. It also powers many common open source web applications. PHP is available for free under the PHP License. See the PHP documentation for usage instructions. Alternatives to PHP include Perl and Python.
All of these applications are available in the core Fedora software library.
Before You Begin
If you have not already done so, create a Linode account and Compute Instance. See our Getting Started with Linode and Creating a Compute Instance guides.
Follow our Setting Up and Securing a Compute Instance guide to update your system. You may also wish to set the timezone, configure your hostname, create a limited user account, and harden SSH access.
sudo
. If you are not familiar with the sudo
command, see the Users and Groups guide.The commands, file contents, and other instructions provided throughout this guide may include placeholders. These are typically domain names, IP addresses, usernames, passwords, and other values that are unique to you. The table below identifies these placeholder values and explains what to replace them with:
Placeholders: | Replace With: |
---|---|
EXAMPLE_DOMAIN | Your custom domain name. |
EXAMPLE_USER | Your MariaDB (or MySQL) username. |
EXAMPLE_PASSWORD | Your MariaDB (or MySQL) user password. |
RELEASE_NUMBER | The desired release number of PHP (optional). |
How to Install a LAMP Stack on Fedora
These instructions are designed for Fedora 38, but work for AlmaLinux and Rocky Linux as well. The guide provides alternate commands whenever the process differs between distributions.
How to Install the Apache Web Server
Ensure the system is updated:
sudo dnf upgrade sudo dnf update
Install the Apache web server:
sudo dnf install httpd -y
Start and enable the web server. The
enable
command automatically launches Apache when the system reboots.sudo systemctl enable httpd sudo systemctl start httpd
Use
systemctl
to ensure the web server isactive (running)
:systemctl status httpd
● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: di> Drop-In: /usr/lib/systemd/system/service.d └─10-timeout-abort.conf Active: active (running) since Mon 2023-08-28 12:20:09 EDT; 47s ago
Press the Q key to exit the
systemctl status
output and return to the terminal prompt.Configure the firewall settings to allow HTTP and HTTPS connections:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https
success success
Reload the firewall:
sudo firewall-cmd --reload
success
Open a Web browser and navigate to the IP address of the Fedora system. It should display the default “Fedora Webserver Test Page”:
This indicates the web server is working but has not been fully configured yet. The AlmaLinux and Rocky Linux distributions have their own web server test pages which are similar but slightly different.
Note If the connection is blocked, it could be due to the default Security-Enhanced Linux (SELinux) settings. SELinux is a kernel security module packaged with several Linux distributions. The default security setting is the fairly restrictive
enforcing
mode. To reduce the security level, change the mode topermissive
using the following command:sudo setenforce 0 sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config
Optional If a domain name is pointing to the server, it can be added to the
/etc/httpd/conf/httpd.conf
file for better performance.Open the
/etc/httpd/conf/httpd.conf
in a text editor with root permissions:sudo nano /etc/httpd/conf/httpd.conf
Add the following information to the end of file and be sure to replace
EXAMPLE_DOMAIN
with your fully-qualified domain name:- File: /etc/httpd/conf/httpd.conf
1 2
ServerAdmin admin@EXAMPLE_DOMAIN ServerName EXAMPLE_DOMAIN:80
When done, press CTRL+X, followed by Y then Enter to save the file and exit
nano
.Restart the web server:
sudo systemctl restart httpd
Open a Web browser and navigate to your domain name. The browser should now display the default Fedora web server page.
How to Install the MariaDB Database
This guide installs MariaDB as the database, but the LAMP stack can also use MySQL. MariaDB is an increasingly popular fork of the original MySQL application with some performance advantages.
sudo dnf install mysql-server
, then follow the other instructions. To run the mysql_secure_installation
script in MySQL, first add a new password for the root account.Install the MariaDB server:
sudo dnf install mariadb-server -y
Enable and start MariaDB:
sudo systemctl enable mariadb sudo systemctl start mariadb
Verify the status of MariaDB by running the
systemctl status
command to confirm it isactive
:sudo systemctl status mariadb
● mariadb.service - MariaDB 10.5 database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset:> Drop-In: /usr/lib/systemd/system/service.d └─10-timeout-abort.conf Active: active (running) since Mon 2023-08-28 13:20:57 EDT; 24s ago
Press the Q key to exit the status output and return to the terminal prompt.
To secure the database, use the interactive
mysql_secure_installation
utility:sudo mysql_secure_installation
Provide the following responses to the questions in the script:
- For
Enter current password for root
, press the Enter key. Because the command is run usingsudo
privileges, a password is not required. - For
Switch to unit_socket authentication
, answer n. - For
Change the root password?
, answer n. It is safe to permit localsudo
access with the standardroot
password. - For
Remove anonymous users?
, answer y. - For
Disallow root login remotely?
, answer y`. - For
Remove test database and access to it?
, answer y. - For
Reload privilege tables now?
, answer y to apply the changes.
- For
Access the database using
sudo
:sudo mysql
MariaDB displays background information about the application along with the
>
prompt:Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 9 Server version: 10.5.21-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
Create the
webdata
database and a user account for web application access. In theCREATE USER
query, provide a secure password in place ofEXAMPLE_PASSWORD
and a more meaningful username in place ofEXAMPLE_USERNAME
. Finally, grant full rights to the user.CREATE DATABASE webdata; CREATE USER 'EXAMPLE_USERNAME' IDENTIFIED BY 'EXAMPLE_PASSWORD'; GRANT ALL ON webdata.* TO 'EXAMPLE_USERNAME'; FLUSH PRIVILEGES;
MySQL should respond with
Query OK
after each line.Exit the SQL shell and return to the terminal prompt:
quit
How to Install PHP
Install the main PHP component, including the
php-mysqlnd
package for database integration:sudo dnf install php php-common php-mysqlnd -y
Optional: Install a selection of other commonly-used PHP extensions. Different applications might require additional PHP packages. Consult the application documentation for details.
Note AlmaLinux and Rocky Linux do not support thephp-mcrypt
component. The omission of this package is the only difference from the Fedora version of the command above.Verify the PHP release to confirm a successful installation:
php -v
On Fedora, the current PHP release is
8.2.9
. AlmaLinux and Rocky Linux currently install release8.0.27
.PHP 8.2.9 (cli) (built: Aug 3 2023 11:39:08) (NTS gcc x86_64) Copyright (c) The PHP Group Zend Engine v4.2.9, Copyright (c) Zend Technologies with Zend OPcache v8.2.9, Copyright (c), by Zend Technologies
Note To determine if a more recent release of PHP is available, use the commanddnf module list php
. To select a non-default release, use the commanddnf module enable php:RELEASE_NUMBER
. Substitute the desired release number forRELEASE_NUMBER
.Restart Apache to activate the PHP Apache API:
sudo systemctl restart httpd
How to Verify the LAMP Stack Installation
To verify the stack components, embed a PHP code block containing a database connection inside an HTML page. PHP code can be integrated into an HTML file using the <?php
tag. The PHP code block can then connect to an SQL-based database using the mysqli_connect
command. Provide the appropriate database credentials to connect.
To fully test all components of the LAMP stack, follow these steps.
Change into the
var/www/html
directory and create a newphptest.php
file:cd /var/www/html sudo nano phptest.php
Add the following contents to the file. Ensure the
servername
variable is set tolocalhost
. ReplaceEXAMPLE_USERNAME
andEXAMPLE_PASSWORD
with the credentials for the database web user account.- File: /var/www/html/phptest.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Welcome to the Site!</p>'; // When running this script on a local database, the servername must be 'localhost'. Use the name and password of the web user account created earlier. Do not use the root password. $servername = "localhost"; $username = "EXAMPLE_USERNAME"; $password = "EXAMPLE_PASSWORD"; // Create MySQL connection $conn = mysqli_connect($servername, $username, $password); // If the conn variable is empty, the connection has failed. The output for the failure case includes the error message if (!$conn) { die('<p>Connection failed: </p>' . mysqli_connect_error()); } echo '<p>Connected successfully</p>'; ?> </body> </html>
When done, press CTRL+X, followed by Y then Enter to save the file and exit
nano
.Run the LAMP stack script test. Open a Web browser and navigate to either the IP address or the domain name followed by
/phptest.php
. For example,http://example.com/phptest.php
, but replaceexample.com
with your actual domain name or IP address.If the test is successful, the browser displays
connected successfully
message:Note If the page displays theConnection failed
message, verify the database credentials and try again. If an HTML error occurs, ensure the contents of the sample file are complete and correct. To isolate the PHP functionality, replace the contents between<?php
and?>
, withphpinfo();
. This command displays information about the PHP installation and confirms if PHP is working.
Additional LAMP Stack Production Considerations
The previous instructions are sufficient for small personal sites. However, commercial sites might require additional configuration. Here are some other issues to potentially consider.
The database is not currently remotely accessible. To access MariaDB through the firewall, use the following commands:
sudo firewall-cmd --add-service=mysql --permanent sudo firewall-cmd --reload
To run multiple sites from the same server, configure a virtual host for each site. This is considered a more professional configuration even for a single site.
To configure a virtual host, add a new directory at
/var/www/html/EXAMPLE_DOMAIN/public_html
. ReplaceEXAMPLE_DOMAIN
with the actual domain name. Add the website files to this directory. Then edit the file at/etc/httpd/conf/httpd.conf
to add the virtual hosts. Each virtual host must define aDocumentRoot
,ServerName
, andServerAdmin
.Consult the Apache Virtual Host documentation for more information.
To remove the default welcome page, edit the file
/etc/httpd/conf.d/welcome.conf
and comment out all directives using the#
symbol.
Conclusion
The Fedora LAMP stack consists of the Linux operating system, Apache web server, the MariaDB/MySQL database, and the PHP/Perl/Python programming language. Together, this architecture is suitable for most modern computing environments. All LAMP components are available in the standard Fedora package library and are installed using dnf
. To test the stack, configure a database for the web user and create a simple script using HTML and PHP.
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
This page was originally published on