CentOS 7搭建LAMP环境( PHP7.0)
一、安装MariaDB
- 安装
yum -y install mariadb mariadb-server
- 启动
systemctl start mariadb
- 设置开机启动
systemctl enable mariadb
- 初始化
mysql_secure_installation
首先是设置密码,会提示先输入密码
Enter current password for root (enter for none):#初次运行直接回车
设置密码
Set root password? [Y/n] #是否设置root用户密码,输入y并回车或直接回车
New password: # 设置root用户的密码
Re-enter new password: # 再输入一次你设置的密码
其他配置
Remove anonymous users? [Y/n] # 是否删除匿名用户,回车
Disallow root login remotely? [Y/n] #是否禁止root远程登录,回车,
Remove test database and access to it? [Y/n] # 是否删除test数据库,回车 Reload privilege tables now? [Y/n] # 是否重新加载权限表,回车 初始化MariaDB完成,接下来测试登录
二、安装Apache。
- 更新软件包
yum -y update
- 安装httpd
yum -y install httpd
- 验证安装的Apache版本
httpd -v
#回显
# Server version: Apache/2.4.6 (CentOS)
# Server built: May 30 2023 14:01:11
- 启动Apache服务并设置开机自启动
systemctl start httpd #启动httpd
systemctl enable httpd #开机自启动
-
验证安装
使用浏览器访问 “http://服务器IP地址”,显示如下页面,说明Apache安装成功。
三、安装PHP及扩展
- 安装
#添加epel和remi存储库
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
- 安装PHP7.4及扩展
yum -y install yum-utils
yum repolist all |grep php
yum-config-manager --enable remi-php74
yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis
php -v #查看PHP版本
php --modules #查看启用的模块
- 开机启动
systemctl enable php74-php-fpm
- 验证
vim /var/www/html/info.php
# 输入
<?php
phpinfo();
?>