There was a problem loading the comments.

How to Install a LAMP Stack on AlmaLinux or CentOS

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

Quick answer: Install a LAMP stack on AlmaLinux, Rocky, or CentOS with dnf: install and start Apache (httpd), install and secure MariaDB, then install PHP and restart httpd. Open HTTP and HTTPS in the firewall, verify PHP with a temporary info.php, and set correct ownership and SELinux context on the web root.

A LAMP stack - Linux, Apache, MySQL/MariaDB, and PHP - is the classic web server foundation and the default for many PHP applications. These steps set it up on AlmaLinux, Rocky, or CentOS using dnf.

1. Update the system

dnf update -y

2. Install and start Apache

dnf install httpd -y
systemctl enable --now httpd

Open the web ports in the firewall, then load your server IP to see the Apache test page:

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

3. Install MariaDB and secure it

dnf install mariadb-server -y
systemctl enable --now mariadb
mysql_secure_installation

Set the root password and accept the security prompts to remove anonymous users and the test database.

4. Install PHP

dnf install php php-mysqlnd php-fpm -y
systemctl restart httpd

For a newer PHP version than the base repositories provide, enable an appropriate PHP module stream before installing.

5. Verify PHP

Create /var/www/html/info.php with <?php phpinfo();, open it in a browser to confirm PHP renders, then delete it so server details are not exposed.

6. Set the document root permissions

Ensure your site files under /var/www/html are owned appropriately (commonly the apache user) so Apache can read them and your deploy user can write them. If pages return a 403, incorrect ownership or SELinux context is the usual cause; set the correct SELinux context for web content rather than disabling SELinux.

Frequently asked questions

Pages return 403 - why?
Usually incorrect ownership or SELinux context on the web root; set the proper SELinux context rather than disabling SELinux.

How do I get a newer PHP version?
Enable the appropriate PHP module stream before installing.

On a SoftSys managed Linux VPS we can provision AlmaLinux with your LAMP stack ready to go, including SELinux configured correctly, so you avoid the permission pitfalls that slow down a manual build.


Share via
Did you find this article useful?  

Related Articles

Tags

© Softsys Hosting