
The LAMP stack is a software bundle composed of Linux, Apache, MySQL or MariaDB, and PHP. These free open-source software applications drive dynamic web applications such as WordPress, Joomla, Magento, and more.
In this guide, you'll install Apache as the HTTP server, MySQL or MariaDB as a relational database management system, and PHP as the server-side scripting language. On the Linux part, you'll use Fedora 34 operating system. After completing this guide, your Apache web server will run a PHP script, connect to a database, and return a successful response.
Before you begin, ensure you have the following:
SSH to your server and ensure your system is up to date.
In Fedora, the Apache HTTP server runs as an httpd daemon. Install the package by running the command below.
Start the httpd service.
Visit your server's domain name or public IP address in a web browser to test the installation.
You should now see a Fedora Web Server Test Page as shown below.
Enable the web server to start automatically.
You may also find these control command useful:
To stop the web server when performing maintenance:
To stop the web server momentarily and restart it after changing the configuration files:
To reload the web server's configurations without interrupting active connections:
After installing Apache, you can locate the httpd service main configuration file from this location.
When working in a system architecture that calls for separation of concerns, you can include different configuration files under the directory below.
By default, Apache serves all requests from /var/www/html.
When setting up a LAMP stack, you have a choice of either MySQL or MariaDB server. Both are compatible with most popular content management systems.
Please note: MariaDB is a fork of the MySQL package, and installing both packages on the same server causes conflicts.
To set up the MariaDB server, run the command below.
After installation, the MariaDB server runs under the daemon mariadb. Start the mariadb service.
Enable the service to start automatically when your server boots.
You can find the main MariaDB configuration file in the location below.
You can add more configuration files that load when the MariaDB server starts in /etc/my.cnf.d/.
If you make any changes to the MariaDB configuration file, you must always restart the mariadb service using the command below.
To stop the mariadb service, use the command below.
To continue testing this guide, make sure the MariaDB server is running.
If you have a particular need for MySQL server or prefer it over the MariaDB server, follow these installation steps.
To install the MySQL server, pull the community-mysql-server package from the main Fedora repository.
After completing the installation, start the MySQL service. It runs under the service - mysqld
Enable the MySQL server to run automatically when your server boots.
You can locate the main MySQL configuration file in the location below.
Also, you can place fragmented configuration files under the directory below.
Remember to restart the mysqld service if you make any configuration changes.
To stop the MySQL server at any time, run the command below.
To proceed with this guide, ensure the MySQL server is running.
Secure the database server by running the command below. This applies to both MySQL and MariaDB.
Answer the prompts depending on the package that you're configuring. Replace EXAMPLE_PASSWORD with a strong value for the root user. For this guide, you may skip setting up the validate_password component that validates the strength of passwords in the MySQL server. However, in a production environment, you can enable it to avoid using weak passwords.
After you've finished securing MySQL/MariaDB server, log in to the database server as a root user.
Enter your root password for the MySQL/MariaDB server and press Enter to proceed. Then, issue the command below to create a sample_db database and a test_user user.
MySQL server.
MariaDB server.
Output:
Exit from the database server command-line interface.
MySQL server.
MariaDB server.
Install the php package.
Install some common PHP extensions required to create dynamic websites and web applications.
You can locate the main PHP configuration file in this location.
In case you make any changes to the PHP configuration file, remember to reboot the Apache web server. PHP also scans the directory below for configuration files.
Restart the httpd service to load the PHP package.
Install nano text editor and open a new /var/www/html/test.php to test PHP connectivity to the MySQL/MariaDB database.
Paste the content below into the file.
Save the file by pressing Ctrl + X, then Y and Enter.
Visit your web server's domain name or IP address in a web browser.
You should see a success message. Your PHP script is now able to connect to the MySQL/MariaDB database.
Your Apache web server is serving the web content from the /var/www/html directory. Up to this point, your LAMP stack is working as expected.
In this tutorial, you've installed a LAMP stack on your Fedora 34 server. With this setup in place, you can now upload your website/web application or probably install a content management system like WordPress.
0 Comments
Be the first to comment and share your perspective with the community.