Edited 3 weeks ago by ExtremeHow Editorial Team
FedoraLAMP StackInstallationLinuxApacheMySQLPHPWeb ServerCommand LineTerminalComputers
This content is available in 7 different language
The LAMP stack is a popular open-source software bundle widely used for web development. It includes Linux, Apache, MySQL (or MariaDB), and PHP. If you are planning to set up a web server environment on Fedora, this comprehensive guide will introduce you to the entire process of setting up a LAMP stack. Fedora is a powerful and flexible operating system, and with the LAMP stack, you can host reliable and efficient web applications.
Before we move on to the installation process, it is important to make sure that your Fedora system is up-to-date. First, open your Terminal application. The Terminal is where you will execute all the necessary commands. Keeping your system updated ensures that you have the latest security patches and software features.
To update your Fedora system, use the following command:
sudo dnf update -y
This command updates all packages on your system to their latest versions. -y
flag automatically answers "yes" to any prompts, making the update process seamless.
Although it is not completely necessary, installing some basic tools can be beneficial to manage your server. You can do this with the following command:
sudo dnf install wget curl nano -y
With wget and curl, you can easily download files from the web, and nano is a friendly text editor for editing configuration files.
The first component of the LAMP stack is the Apache web server. Apache is a robust and widely used web server software that handles requests and delivers web content over the Internet.
To install Apache on Fedora, execute the following command:
sudo dnf install httpd -y
This installs the latest version of the Apache web server available in Fedora's package repository.
After installation, you must start the Apache service and enable it to start on boot. Use these commands:
sudo systemctl start httpd
sudo systemctl enable httpd
The first command starts the Apache service, and the second one ensures that it will start automatically whenever your system boots up.
By default, Fedora uses the Firewalld service to manage the system's firewall settings. You need to open the HTTP and HTTPS ports to allow web traffic. Run the following command:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
The first two commands permanently open the HTTP and HTTPS ports, and the last command reloads the firewall configuration to apply the changes. After setting up the firewall, you can test whether Apache is working by accessing your server's IP address in a web browser. You should see the Apache Fedora test page.
The next component of our LAMP stack is the database management system. Fedora has switched to MariaDB, a fork of MySQL. MariaDB is fully compatible with MySQL and offers additional features. This tutorial will cover installing MariaDB, but you can replace MySQL if you prefer.
Use the following command to install MariaDB:
sudo dnf install mariadb-server mariadb -y
This installs both the MariaDB server and client packages, allowing you to run the database server and connect to it locally or remotely.
Like Apache, you need to start the service and enable it to start on boot:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Make sure your database server is running and will restart automatically after a reboot.
Like MySQL, MariaDB also comes with a utility to perform some basic security tasks, such as setting the root password and deleting test users and databases. Run the security script with:
sudo mysql_secure_installation
The script will ask several questions, including whether to set the root password, remove anonymous users, deny root login remotely, and delete the test database. It is recommended to answer Yes (Y)
to all prompts for optimal security.
The last component of the LAMP stack is PHP, which processes dynamic content and interacts with the database.
Fedora's package repository includes the PHP package. To install PHP along with some commonly used extensions, execute the following command:
sudo dnf install php php-mysqlnd php-fpm php-json php-gd php-pear -y
This command installs the core PHP package along with the extensions needed for database interaction, JSON parsing, and more.
After installation, you may need to modify some PHP settings. Edit the main configuration file by running the following:
sudo nano /etc/php.ini
In this file, you can adjust settings such as memory_limit
, upload_max_filesize
, and date.timezone
. After making changes, save and close the file by pressing CTRL + X
, then Y
, and ENTER
.
Whenever you make changes to the PHP configuration, restart Apache to apply the updates:
sudo systemctl restart httpd
Now, your web server is fully equipped to handle PHP scripts.
To make sure everything is working correctly, create a simple PHP file in the Apache document root and access it through a web browser.
Create a file called info.php
in the document root:
sudo nano /var/www/html/info.php
Add the following PHP code:
<?php phpinfo(); ?>
Save the file and exit. Now, access http://your_server_ip/info.php
in a web browser. If PHP is installed and configured correctly, you will see a page displaying detailed information about your PHP installation.
For security reasons, it is a good idea to delete info.php
file after confirming that PHP is working correctly:
sudo rm /var/www/html/info.php
Congratulations, you have successfully installed the LAMP stack on your Fedora system. This powerful combination of open-source software is the backbone of countless websites and web applications around the world. With Apache as your web server, MariaDB as your database management system, and PHP for dynamic content processing, your server is ready to host a wide variety of web applications. This setup allows for flexibility, scalability, and a rich environment for developing robust applications.
Beyond this basic setup, there are many ways to extend your server's capabilities. Consider exploring additional PHP modules, increasing database performance with caching, or integrating a content management system such as WordPress or Joomla into your server environment. Using the LAMP stack as a foundation, the web development and hosting possibilities are nearly limitless.
As you continue to work with Fedora and the LAMP stack, keep your server secure by regularly applying software updates and configuring appropriate firewall rules. Security should always be a top priority to protect your data and web applications.
Thanks for following this guide, and happy hosting on your new Fedora LAMP stack setup!
If you find anything wrong with the article content, you can