CentOS 7 上安装LAMP环境

环境:CentOS 7.9

预备工作:CentOS 7.x 升级至 7.9

检查当前版本

cat /etc/redhat-release

检查更新

sudo yum check-update

清理package

sudo yum clean all

重启

reboot

升级系统

sudo yum upgrade

重启

sudo reboot

检查版本更新是否成功

cat /etc/redhat-release

一、安装Apache

安装Apache

sudo yum install httpd

启动Apache

sudo systemctl start httpd.service

允许http和https通过防火墙

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

开机启动Apache

sudo systemctl enable httpd.service

查看Apache安装是否成功

http://your_server_IP_address/

出现以下画面为成功

二、安装MariaDB 10.0+

安装MariaDB

sudo yum install wget
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod +x mariadb_repo_setup
sudo ./mariadb_repo_setup
sudo yum install MariaDB-server

启动MariaDB

sudo systemctl start mariadb

去除默认安装中的隐患

sudo mysql_secure_installation

第一次安装没有密码,直接点回车,然后设置密码。

开机启动MariaDB

sudo systemctl enable mariadb.service

三、安装PHP 7

CentOS 7.2 默认带的是PHP 5.4,但因为已经过时,所以这次选择安装当前最新的PHP 7.4。

安装EPEL和REMI库

sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

安装util

sudo yum install epel-release yum-utils

更新

sudo yum update

确定要安装的版本

sudo yum-config-manager --enable remi-php74

安装PHP

sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql php-xml php-fpm php-mbstring php-pecl-zip

还可以搜索更多库安装

sudo yum search php-
sudo yum info php-fpm
sudo yum install package1 package2 ...

检测PHP安装是否成功

新建文件

sudo vi /var/www/html/info.php

输入

<?php phpinfo(); ?>

修改/etc/httpd/conf/httpd.conf文件

sudo vi /etc/httpd/conf/httpd.conf

找到ServerName www.example.com:80,去掉注释,改为

ServerName localhost

重启Apache

sudo systemctl restart httpd.service

打开页面

http://your_server_IP_address/info.php

若出现以下画面,则表示成功

参考页面

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-centos-7

https://www.rabanser.tech/2018/10/13/How-to-serve-websites-with-Apache-on-CentOS-7.html

https://computingforgeeks.com/how-to-install-php-7-4-on-centos-7/

https://stackoverflow.com/questions/9541460/httpd-could-not-reliably-determine-the-servers-fully-qualified-domain-name-us

这个人很懒,他什么资料也没有留下。