This tutorial guides you through building a LAMP (Linux, Apache, MySQL, PHP) stack on Rocky Linux 8, providing a robust environment for hosting dynamic websites and web applications.
rocky linuxApacheMySQLphp
Micro
VPS
1
vCPU
2 GB
Memory
20 GB
NVMe Disk
1024 GB
Traffic
4.90€
/month
* Up to 6GB RAM, 60GB NVMe Disk Space and 1Gbit/s Network Speed
#### Prerequisites
Before you begin, ensure you have:
- A server running Rocky Linux 8
- SSH access to your server with sudo privileges
- Basic familiarity with the command line and package management on Rocky Linux
#### Step 1: Install Apache
Install Apache web server using DNF package manager:
```bash
sudo dnf install httpd
```
Start Apache and enable it to start on boot:
```bash
sudo systemctl start httpd
sudo systemctl enable httpd
```
#### Step 2: Install MySQL (MariaDB)
Install MySQL database server (MariaDB) and secure the installation:
```bash
sudo dnf install mariadb-server
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
```
Follow the on-screen prompts to secure your MySQL installation.
#### Step 3: Install PHP
Install PHP and necessary PHP modules for Apache:
```bash
sudo dnf install php php-mysqlnd php-json php-gd php-mbstring
```
Restart Apache to apply PHP configuration:
```bash
sudo systemctl restart httpd
```
#### Step 4: Test PHP Processing
Create a PHP info file to test your PHP installation:
```bash
echo "" | sudo tee /var/www/html/info.php
```
Access the PHP info file in your web browser:
```
http://your-server-ip/info.php
```
#### Step 5: Configure Firewall (UFW)
If UFW (Uncomplicated Firewall) is active, allow HTTP (port 80) and HTTPS (port 443) traffic:
```bash
sudo ufw allow http
sudo ufw allow https
```
#### Step 6: Optional: Install phpMyAdmin (Database Management Tool)
If you need a graphical interface to manage your databases, install phpMyAdmin:
```bash
sudo dnf install phpMyAdmin
```
Configure phpMyAdmin to work with Apache:
```bash
sudo ln -s /usr/share/phpMyAdmin /var/www/html/phpmyadmin
```
Access phpMyAdmin in your web browser:
```
http://your-server-ip/phpmyadmin
```
#### Conclusion
You have successfully built a LAMP stack on Rocky Linux 8. You can now start deploying and hosting your PHP-based websites and applications on your server.
**Additional Resources:**
- **Apache Documentation:** [https://httpd.apache.org/docs/](https://httpd.apache.org/docs/)
- **PHP Documentation:** [https://www.php.net/docs.php](https://www.php.net/docs.php)
- **Rocky Linux Documentation:** [https://docs.rockylinux.org/](https://docs.rockylinux.org/)