To set up a LAMP (Linux, Apache, MySQL/MariaDB, PHP) stack on Alibaba Cloud Linux 3, you need to use the package manager specific to this distribution. Alibaba Cloud Linux 3 is based on RHEL 8 / CentOS Stream 8, so it uses dnf or yum.
Here’s a step-by-step guide:
✅ Step 1: Update System
sudo dnf update -y
✅ Step 2: Install Apache HTTP Server
sudo dnf install httpd -y
Start and enable Apache:
sudo systemctl start httpd
sudo systemctl enable httpd
Check status:
sudo systemctl status httpd
🔒 Open port 80 in your security group/firewall if needed.
✅ Step 3: Install MariaDB (MySQL Alternative)
Alibaba Cloud Linux 3 recommends MariaDB as the default relational database.
sudo dnf install mariadb-server -y
Start and enable MariaDB:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Secure installation:
sudo mysql_secure_installation
✅ Step 4: Install PHP and Required Modules
Install PHP along with common extensions:
sudo dnf install php php-mysqlnd php-fpm php-json php-gd php-curl php-mbstring php-xml php-zip -y
Restart Apache to load PHP module:
sudo systemctl restart httpd
✅ Step 5: Test PHP Installation
Create a test file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Visit http://<your-server-ip>/info.php in your browser.
Remove after testing:
sudo rm /var/www/html/info.php
✅ Optional: Configure Firewall
If using firewalld:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
✅ Verify All Components
# Check Apache version
httpd -v
# Check MariaDB version
mariadb --version
# Check PHP version
php -v
📝 Notes for Alibaba Cloud Linux 3
- Uses
dnfinstead ofyum(thoughyumis aliased). - SELinux is enabled by default — ensure proper contexts if issues arise.
- Use
semanage fcontextandrestoreconif file permissions are blocked by SELinux.
Let me know if you want to add SSL via Let’s Encrypt, PHP-FPM tuning, or WordPress deployment!
PHPWP博客