CentOS7安装LAMP (PHP8.0)

安装Apache

#更新软件仓库
yum update

#安装Apache
yum install httpd

#安装Apache相关应用
yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

#启动Apache并设置为开机自启
systemctl start httpd.service
systemctl enable httpd.service

#为了方便,关闭防火墙拒绝开机自启(不安全)
systemctl stop firewalld
systemctl disable firewalld

安装php8.0

#安装PHP8.0
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
sudo yum -y install yum-utils
sudo yum-config-manager --disable 'remi-php*'
sudo yum-config-manager --enable remi-php80
sudo yum -y install php php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json}

#检查PHP版本
php --version

安装PHP后如果测试不能解析PHP而是原文输出的话

请重启Apache

service httpd restart

安装MySQL

#安装MySQL
yum -y install mysql

#安装mysql-server(很大可能会报错)
#yum -y install mysql-server

#报错解决方案(可跳过上一步直接执行一遍)
yum -y install wget

#下载mysql的repo源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 

#安装mysql-community-release-el7-5.noarch.rpm包
rpm -ivh mysql-community-release-el7-5.noarch.rpm

#安装mysql-server
yum install mysql-server 

#安装php-mysql工具
yum -y install php-mysql

#安装其他mysql工具
yum -y install mysql-connector-odbc libdbi-dbd-mysql mysql-devel

#启动mysql并设置为开机自启
systemctl start mysqld.service
systemctl enable mysqld.service

#配置mysql
mysql_secure_installation
#输入当前密码Enter current password for root (enter for none):(初次为空,直接回车即可)
#Set root password? [Y/n]设置新密码?:Y(简单密码也可以 root)
#Remove anonymous users? [Y/n]删除匿名用户?:Y
#Disallow root login remotely? [Y/n] 禁止远程root登录?:N
#Remove test database and access to it? [Y/n]删除测试数据库并访问?:Y
#Reload privilege tables now? [Y/n]重新加载表数据?:Y

#此处建议处理mysql编码问题

#重启mysql服务
systemctl restart mysqld.service

#进入mysql数据库
mysql -u root -p

mysql编码问题:初始化后进行

在CentOS7中修改文件/etc/my.cnf

在[mysqld],[mysql],[client]下分别添加如下内容

[client]
default-character-set=utf8
 
[mysqld]
character-set-server=utf8
 
[mysql]
default-character-set=utf8

配置mysql允许远程访问

#进入 mysql
mysql -u root -p

#使用 mysql库
use mysql;

#查看用户表 
SELECT `Host`,`User` FROM user;

#更新用户表
UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1;
#其中%的意思是允许所有的ip远程访问,如果需要指定具体的某个ip就写上具体的ip即可

#强制刷新权限
flush privileges;

安装其他服务

安装FTP

安装vsftpd

#安装vsftpd
yum install -y vsftpd

#可以查看安装目录
whereis vsftpd

#查看vsftpd服务的状态
systemctl status vsftpd.service

#开启vsftpd服务并设置开机自启
systemctl start vsftpd.service
systemctl enable vsftpd.service

修改ftp的根目录只要修改/etc/vsftpd/vsftpd.conf文件

加入几行

local_root=/var/www/html
chroot_local_user=YES
anon_root=/var/www/html

vsftpd允许root用户登录

在/etc/vsftpd/user_list文件中把root那一行删除或者注释掉

/etc/vsftpd/ftpusers文件中的root也注释掉

然后重启vsftpd就可以了

#重启vsftpd服务
service vsftpd restart
posted @ 2022-02-20 21:55  limonene0x  阅读(291)  评论(0编辑  收藏  举报