首先我们先来了解一下
简单来说LAMP
就是linux+Apache+Mysql+php环境搭建
一、安装Apache
1.在CentOS 8上安装Apache Web 服务器
[root@192 ~]# sudo dnf install httpd httpd-tools
2.安装完成后,使用以下命令启用Apache在系统启动时自动启动。
[root@192 ~]# sudo systemctl enable httpd Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
3.启动Apache服务。
[root@192 ~]# sudo systemctl start httpd
4.查看Apache Web服务是否正在运行
[root@192 ~]# sudo systemctl status httpd
httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor prese> Active: active (running) since Sun 2022-04-24 02:24:45 EDT; 11s ago Docs: man:httpd.service(8) Main PID: 75910 (httpd) Status: "Running, listening on: port 80" Tasks: 213 (limit: 11068) Memory: 28.7M
5.查看版本(可以略过)
[root@192 ~]# httpd -v
6.查看安装系信息(可以略过)
[root@192 ~]# rpm -qi httpd
二、安装mysql
1.在CentOS 8上安装mysql
[root@192 ~]# yum install mysql-server
2.启动mysql,开机启动mysql
[root@192 ~]# systemctl start mysqld [root@192 ~]# systemctl enable mysqld Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
3.查看mysql运行状态
[root@192 ~]# sudo systemctl status mysqld
三、安装php
1.安装EPEL存储库
[root@192 ~]# sudo dnf install https://dl.Fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
2.安装yum-utils
[root@192 ~]# sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
3.选择模块
[root@192 ~]#sudo dnf module list php
4.选择启用版本,这里选择7.4
[root@192 ~]# sudo dnf module enable php:remi-7.4
5.进行php的安装
sudo dnf install php php-opcache php-gd php-curl php-mysqlnd
5.设置启动开机启用PHP-FPM
[root@192 ~]# sudo systemctl start php-fpm [root@192 ~]# sudo systemctl enable php-fpm Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
6.查看运行状态
[root@192 ~]# sudo systemctl status php-fpm
php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor pre> Active: active (running) since Sun 2022-04-24 03:30:35 EDT; 1min 58s ago Main PID: 79396 (php-fpm) Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/s> Tasks: 6 (limit: 11068) Memory: 47.6M CGroup: /system.slice/php-fpm.service ├─79396 php-fpm: master process (/etc/php-fpm.conf) ├─79397 php-fpm: pool www ├─79398 php-fpm: pool www
四、设置
1.指示SELinux允许Apache通过PHP-FPM运行来执行PHP代码
[root@192 ~]# setsebool -P httpd_execmem 1
2.重启Apache使PHP与Apache Web服务器一起使用。
[root@192 ~]# sudo systemctl restart httpd
3.防火墙通过80端口
[root@192 ~]# firewall-cmd --permanent --add-port=80/tcp success
4.重新加载防火墙
[root@192 ~]# firewall-cmd --reload success
五:测试PHP信息
[root@192 ~]# $sudo nano /var/www/html/linuxidc.php
在下面插入PHP代码并保存文件。
<?php phpinfo (); ?>
相关文章