LAMP:Linux安装Apache、MySQL、PHP

465 阅读1分钟

这是我参与11月更文挑战的第17天,活动详情查看:2021最后一次更文挑战


LAMP手动安装

一、安装前准备

1.更新系统yum源

cat  /etc/redhat-release
uname -a

yum clean all
yum makecache

2.安装基础软件

yum install -y wget curl git vim net-tools bash-completion

二、开始安装LAMP环境

1.安装Apache服务

Apache对应的是httpd故而在centos中使用命令安装的是httpd

yum install -y httpd httpd-devel

设置服务开机自启,并启动服务

systemctl status httpd
systemctl enable httpd
systemctl start httpd
systemctl status httpd

查看端口开放运行情况

netstat -lntp

关闭防火墙

systemctl status firewalld
systemctl stop firewalld
systemctl status firewalld
systemctl disable firewalld

也可以放行http服务

firewall-cmd --permanent --zone=public --add-service=http

验证httpd服务运行情况

systemctl status httpd
curl 127.0.0.1:80

浏览器中输入首页地址http://$IP:80

2.安装mariadb

yum install -y mariadb mariadb-server mariadb-libs mariadb-devel

设置服务开机自启,并启动服务

systemctl status mariadb
systemctl enable mariadb
systemctl start mariadb
systemctl status mariadb

查看端口开放运行情况

netstat -lntp

简单配置数据库

mysql_secure_installation

修改远程访问权限

mysql -uroot -p
MariaDB [(none)]> update mysql.user set host='%' where user='root' and host='localhost';
MariaDB [(none)]> flush privileges;

查看文件位置

rpm -qa |grep maria

例子:

[root@host-192-168-2-128 conf]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> update mysql.user set host='%' where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

3.安装PHP

yum -y install php
php -v
rpm -ql php
yum install -y php-mysql
rpm -ql php-mysql
yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath

验证安装

touch /etc/www/html/info.php
vim /etc/www/html/info.php

文件中写入以下代码

<?php
phpinfo();
?>

然后访问http://$IP$IP:80/info.php

至此lamp服务安装完成。

三、部署网站

参考链接:
Linux——使用 Apache 服务部署静态网站
linux下使用Apache服务部署静态网站

0.文件目录说明

配置服务文件参数

服务目录:/etc/httpd 主配置文件:/etc/httpd/conf/httpd.conf 网站数据目录:/var/www/html 访问日志:/var/log/httpd/access_log 错误日志:/var/log/httpd/error_log

1.创建与导入数据库

2.配置httpd.conf文件

cd /etc/httpd/conf
ls
cp httpd.conf httpd.conf.bak
vim httpd.conf

更改网站数据目录 若想将网站数据放在 /home/wwwroot 目录下,则需要对 Apache 服务程序的配置文件进行编辑。

3.配置网站目录权限

给予网站目录 755 的访问权限:

cd /var/www/html
chmod -Rf 755 ./

4.删除文件

5.重新启动Apache服务

systemctl status httpd
systemctl restart httpd
systemctl status httpd