In this comprehensive guide, we will walk you through the process of how to install LAMP stack on Oracle Linux. (Linux, Apache, MySQL, PHP) A LAMP stack is a powerful platform for building dynamic web applications and hosting various services. This article assumes that you have already set up Oracle Linux and are ready to install the LAMP stack components.
Prerequisites
Before starting the installation, ensure that you have the following:
- Oracle Linux (7 or 8) installed and up-to-date
- Root or sudo access to the Oracle Linux server
How to Install LAMP Stack on Oracle Linux
Update Your Oracle Linux System
First, update your Oracle Linux system to ensure you have the latest packages and security patches:
sudo yum update -y
Install Apache Web Server on Oracle Linux
To install Apache, run the following command:
sudo yum install httpd -y
After installing Apache, enable and start the web server:
sudo systemctl enable httpd
sudo systemctl start httpd
You can verify the Apache installation by accessing your server’s IP address or domain name in a web browser. You should see the Apache test page.
For more information on configuring Apache, refer to our guide on how to install Apache on Oracle Linux.
Install MySQL (MariaDB) Database Server on Oracle Linux
Install MariaDB, a popular MySQL drop-in replacement, using the following command:
sudo yum install mariadb-server -y
Once MariaDB is installed, enable and start the database server:
sudo systemctl enable mariadb
sudo systemctl start mariadb
Secure your MariaDB installation by running the mysql_secure_installation
script:
sudo mysql_secure_installation
This script will prompt you to set a root password, remove anonymous users, disable remote root login, remove the test database, and reload the privilege tables.
For a more detailed guide on setting up MariaDB, read our how to install MariaDB server on Oracle Linux article.
Installing PHP on Oracle Linux
To install PHP and necessary extensions, run:
sudo yum install php php-mysql php-fpm php-gd php-xml -y
Once PHP is installed, start and enable the PHP-FPM service:
sudo systemctl enable php-fpm
sudo systemctl start php-fpm
To test the PHP installation, create a simple PHP file in the Apache document root:
sudo echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
Visit http://your-server-ip/phpinfo.php
in your web browser to verify the PHP installation. Remember to remove the phpinfo.php
file after testing.
For more information on PHP installation, check out our guide on how to install PHP on Oracle Linux.
Configure Apache to Use PHP-FPM
To configure Apache to use PHP-FPM, create a new configuration file:
sudo nano /etc/httpd/conf.d/php-fpm.conf
Add the following content to the file:
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php-fpm/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
Save and close the file, then restart Apache:
sudo systemctl restart httpd
Securing Apache and PHP-FPM
To secure your Apache and PHP-FPM setup, modify the /etc/httpd/conf/httpd.conf
file:
sudo nano /etc/httpd/conf/httpd.conf
Find the line containing ServerTokens OS
and change it to ServerTokens Prod
. This setting will prevent Apache from revealing its version number in HTTP headers and error pages.
Next, find the line containing ServerSignature On
and change it to ServerSignature Off
. This setting disables the server signature on server-generated pages.
Save and close the file, then restart Apache:
sudo systemctl restart httpd
Set Up a Firewall
To secure your LAMP stack, set up a firewall using firewalld:
sudo yum install firewalld -y
sudo systemctl enable firewalld
sudo systemctl start firewalld
Allow incoming connections to your web server on ports 80 (HTTP) and 443 (HTTPS):
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
For a more detailed guide on securing your Oracle Linux server, read our articles on how to disable root login on Oracle Linux and how to enable 2FA on Oracle Linux.
Install Additional PHP Extensions (Optional)
Depending on your web application’s requirements, you may need to install additional PHP extensions. Use the following command to search for available extensions:
sudo yum search php-
To install an extension, run:
sudo yum install php-extension_name -y
Replace extension_name
with the desired extension. For example, to install the php-mbstring
extension, run:
sudo yum install php-mbstring -y
Conclusion
Congratulations! You have successfully installed a LAMP stack on Oracle Linux. You can now build and host web applications, create databases, and develop dynamic websites.
For more tips and tutorials on Oracle Linux, check out our other articles, such as how to build a file server on Oracle Linux and how to use SSH keys on Oracle Linux.