目录
LAMP含义
- LAMP:Linux + Apache + Mysql + PHP
- LNMP:Linux + Nginx + MySQL + php-fpm LNMP 架构(组合)
- LNMPA:Linux + Nginx(80) + MySQL + PHP + Apache Nginx 代理方式
部署步骤
部署前
关闭防火墙和selinux
- 关闭防火墙(暂时关闭)
systemctl stop firewalld firewall-cmd --state
- 关闭selinux(永久关闭)
2.1. 修改/etc/selinux/config
文件内容, 将SELIUNX=enforcing
修改为SELINUX=disabled
修改后的文件内容如下:# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
查询当前服务器上是否安装apache/mysql/php
rpm -qa |grep httpd rpm -qa |grep mysq rpm -qa |grep php
没有安装对应包的话,应该没有内容显示
安装Apache
- 使用yum命令安装httpd软件包
yum install -y httpd
- 安装完成后,修改配置文件:
/etc/httpd/conf/httpd.conf
,新增一行ServerName Localhost:80
最后文件中相关部分内容如下:ServerAdmin root@localhost # # ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # #ServerName www.example.com:80 ServerName Localhost:80 # # Deny access to the entirety of your server's filesystem. You must # explicitly permit access to web content directories in other # <Directory> blocks below. #
- 使用
systemctl
将httpd
设置开机自启,并重启httpd
服务systemctl enable httpd systemctl restart httpd
4.最后查看是否有80端口监听
netstat -ntlp 80
有类似下面的内容就表示安装成功
tcp6 0 0 :::80 :::* LISTEN 27769/httpd
或者可以输入服务器对应的ip看有没有apache的初始页面
安装mysql
先从官网上下载安装包
wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
添加mysql的yum源存储库
rpm -ivh mysql80-community-release-el8-1.noarch.rpm
安装mysql
yum install mysql-server
将mysql设置为开机自启并重启mysql
systemctl enable mysqld.service systemctl restart mysqld.service
查看mysql是否安装成功
netstat -ntlp
[root@localhost html]# netstat -ntlp | grep mysqld tcp6 0 0 :::33060 :::* LISTEN 26132/mysqld tcp6 0 0 :::3306 :::* LISTEN 26132/mysqld
初始化数据库
mysql_secure_installation
下面是几个需要手动选择的地方Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: y
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
# 这里密码需要输的稍微复杂些 Please set the password for root here. New password: Re-enter new password:
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
完了后使用
mysql -u root -p
来检查能否正确连接到MYSQL数据库
安装PHP
- yum安装PHP
yum -y install php
- 重启httpd服务
更改php配置一定要重启httpd服务 - 测试LAMP环境是否可用
3.1cd /var/www/html
3.2vim index.php
3.3 在index.php中编写php代码<?php echo 'hello world'; ?>
- 在浏览器上输入服务器ip地址,查看能否向下面这样显示
留言