在CentOS上搭建LAMP(Linux, Apache, MySQL, PHP)服务器是一个相对直接的过程,但需要确保每个组件都正确安装和配置。以下是一个基本的步骤指南,基于CentOS 7和CentOS 8的常见配置。
更新系统
sudo yum update -y
安装Apache
sudo yum install httpd httpd-tools -y
sudo systemctl start httpd
sudo systemctl enable httpd
安装MariaDB
sudo yum install mariadb-server mariadb -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
安装PHP和PHP-MySQL
sudo yum install php php-mysql -y
配置防火墙
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=mysql
sudo firewall-cmd --reload
验证安装
phpinfo.php
文件在/var/www/html/
目录下:echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php
更新系统
sudo dnf update -y
安装Apache
sudo dnf install httpd httpd-tools -y
sudo systemctl start httpd
sudo systemctl enable httpd
安装MariaDB
sudo dnf install mariadb-server mariadb -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
安装PHP和PHP-MySQL
sudo dnf install php php-mysqlnd -y
配置防火墙
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=mysql
sudo firewall-cmd --reload
验证安装
phpinfo.php
文件在/var/www/html/
目录下:echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php
/etc/httpd/conf/httpd.conf
文件是否有语法错误。/etc/my.cnf
,确保socket路径设置正确。