查看程序的按照路径信息
rpm -ql nginx
vim删除所有内容:dG
LAMP架构介绍
liunx + apache(nginx) + mysql + PHP(后端程序)
快速部署LAMP架构
1、关闭防火墙
关闭所有的防火墙规则
[root@master ~]# iptables -F
关闭防火墙(省略)
永久关闭(省略)
2、安装apache,并启动apache
[root@master ~]# yum install -y httpd
已加载插件:fastestmirror, langpacks
.....................
正在更新 : httpd-tools-2.4.6-97.0.5.el7_9.5.x86_64 1/4
正在更新 : httpd-2.4.6-97.0.5.el7_9.5.x86_64 2/4
清理 : httpd-2.4.6-97.0.1.el7_9.x86_64 3/4
清理 : httpd-tools-2.4.6-97.0.1.el7_9.x86_64 4/4
验证中 : httpd-2.4.6-97.0.5.el7_9.5.x86_64 1/4
验证中 : httpd-tools-2.4.6-97.0.5.el7_9.5.x86_64 2/4
验证中 : httpd-tools-2.4.6-97.0.1.el7_9.x86_64 3/4
验证中 : httpd-2.4.6-97.0.1.el7_9.x86_64 4/4
更新完毕:
httpd.x86_64 0:2.4.6-97.0.5.el7_9.5
作为依赖被升级:
httpd-tools.x86_64 0:2.4.6-97.0.5.el7_9.5
完毕!
[root@master ~]# systemctl start httpd
[root@master ~]# netstat -tunlp |grep httpd
tcp6 0 0 :::80 :::* LISTEN 6765/httpd
3、安装mysql
#安装mysql程序
yum install mariadb-server mariadb -y
启动mysql
报错处理
由于我系统里面之前安装过mysql,这需要先卸载并清理旧的mysql
没清理干净之前,启动时会报错。
[root@master ~]# systemctl start mariadb.service
Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
彻底清理MySQL的方法:https://blog.csdn.net/ly021499/article/details/86575682
进行MariaDB的简单配置。
参考:https://www.cnblogs.com/jpfss/p/10128043.html
mysql_secure_installation
如果提示权限问题,请切换用户,或者在对应命令前加上sudo以提升该用户的操作权限。
Enter current password for root (enter for none):
让我们输入root用户密码,初次运行直接回车。
Set root password? [Y/n]
是否设置root用户密码,输入y并回车或直接回车。
New password:
Re-enter new password:
输入新密码,并确认密码。
其他配置
Remove anonymous users? [Y/n] 是否删除匿名用户,输入y或者回车。
Disallow root login remotely? [Y/n] 是否禁止root远程登录,输入y或者回车。
Remove test database and access to it? [Y/n] 是否删除test数据库,输入y或者回车。
Reload privilege tables now? [Y/n] 是否重新加载权限表,输入y或者回车。
配置MariaDB远程连接
进入到MariaDB控制台
- 执行如下语句建立用户并赋予所有操作权限。
CREATE USER ‘username’@‘host’ IDENTIFIED BY ‘password’;
参数 | 说明 |
---|---|
username | 将要创建的用户名 |
host | 指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost,如果想让该用户可以从任意远程主机登陆,可以使用通配符% |
password | 该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器 |
- 给用户赋予远程登录权限
GRANT privileges ON databasename.tablename TO ‘username’@‘host’
参数 | 说明 |
---|---|
privileges | 用户的操作权限,如SELECT , INSERT , UPDATE 等(权限列表见文末)。如果要授予所的权限则使用ALL |
databasename | 数据库名 赋予创建某个数据库的权限 : grant all on xxxx.* to ‘root’@‘%’ identified by ‘password’ with grant option; |
tablename | 表名,如果要授予该用户对所有数据库和表的相应操作权限则可用表示,如.* |
- 修改完成后在MariaDB控制台执行FLUSH PRIVILEGES刷新配置权限使其生效
4、安装PHP
安装依赖:
yum install -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libtool-ltdl-devel pcre pcre-devel apr apr-devel zlib-devel gcc make
安装php、php链接mysql的驱动:
yum install php php-fpm php-mysql -y
配置apache文件,在/etc/httpd/conf/httpd.conf文件里面“DocumentRoot “/var/www/html””后面添加一下四行
[root@master ~]# vim /etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html"
TypesConfig /etc/mime.types
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html
测试apache是否能访问php
在apache的首页目录下"/var/www/html"新建一个index.php文件
文件内容为:
<meta charset=utf-8>
I am new page,hello brother!
<?php
phpinfo();
?>
重启apache
systemctl restart httpd
访问apache首页:192.168.29.152:80