CentOS 7 yum方式配置LAMP环境

1、安装Apache

yum install httpd
nano /etc/httpd/conf/httpd.conf

允许htacess重写:找到全部的AllowOverride none 修改为AllowOverride All

允许所有请求访问资源:把Require all denied 修改为Require all granted

systemctl start httpd.service //启动
systemctl enable httpd.service //设置开机启动
systemctl restart httpd.service //重启
systemctl status httpd.service //查看状态

另外,还需要配置一下防火墙,打开80和443端口

安装firewall

yum -y install firewalld firewall-config
systemctl start firewalld.service
systemctl enable firewalld.service

配置防火墙

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

2、安装PHP

yum install php php-fpm php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel -y
systemctl start php-fpm.service
systemctl enable php-fpm.service
systemctl restart httpd
nano /var/www/html/test.php //测试

3、安装Mysql

yum install mariadb mariadb-server -y
systemctl start mariadb-server
systemctl enable mariadb-server
systemctl restart httpd
mysql_secure_installation //设置root密码等
mysql -uroot -p123456 //测试登录

4、安装phpMyAdmin

如果无法直接yum,需要先安装EPEL源

yum install epel-release
yum install phpmyadmin
nano /etc/httpd/conf.d/phpMyAdmin.conf

在<Directory /usr/share/phpMyAdmin/>中,把Require ip 127.0.0.1和Require ip ::1两个回环地址#掉,增加一句Require all granted

systemctl restart httpd

参考: