记录纯净RedHat7部署LAMP

1.关闭防火墙、禁用SELINUX
systemctl disable firewalld
systemctl stop firewalld
vi /etc/sysconfig/selinux

将SELINUX设置为disabled
重启服务器

2.配置网络yum源
wget -O /etc/yum.repos.d/my.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i 's#$releasever#7#g;s#$basearch#x86_64#g' /etc/yum.repos.d/my.repo
yum clean all
yum makecache
yum install epel-release -y

EPEL (Extra Packages for Enterprise Linux)是基于Fedora的一个项目,为“红帽系”的操作系统提供额外的软件包,适用于RHEL、CentOS和Scientific Linux.

3.安装组件
yum install httpd php php-fpm php-mysql mariadb-server -y

关于php-fpm

首先,CGI是干嘛的?CGI是为了保证web server传递过来的数据是标准格式的,方便CGI程序的编写者。

web server(比如说nginx)只是内容的分发者。比如,如果请求/index.html,那么web server会去文件系统中找到这个文件,发送给浏览器,这里分发的是静态数据。好了,如果现在请求的是/index.php,根据配置文件,nginx知道这个不是静态文件,需要去找PHP解析器来处理,那么他会把这个请求简单处理后交给PHP解析器。Nginx会传哪些数据给PHP解析器呢?url要有吧,查询字符串也得有吧,POST数据也要有,HTTP header不能少吧,好的,CGI就是规定要传哪些数据、以什么样的格式传递给后方处理这个请求的协议。仔细想想,你在PHP代码中使用的用户从哪里来的。


当web server收到/index.php这个请求后,会启动对应的CGI程序,这里就是PHP的解析器。接下来PHP解析器会解析php.ini文件,初始化执行环境,然后处理请求,再以规定CGI规定的格式返回处理后的结果,退出进程。web server再把结果返回给浏览器。

好了,CGI是个协议,跟进程什么的没关系。那fastcgi又是什么呢?Fastcgi是用来提高CGI程序性能的。

提高性能,那么CGI程序的性能问题在哪呢?“PHP解析器会解析php.ini文件,初始化执行环境”,就是这里了。标准的CGI对每个请求都会执行这些步骤(不闲累啊!启动进程很累的说!),所以处理每个时间的时间会比较长。这明显不合理嘛!那么Fastcgi是怎么做的呢?首先,Fastcgi会先启一个master,解析配置文件,初始化执行环境,然后再启动多个worker。当请求过来时,master会传递给一个worker,然后立即可以接受下一个请求。这样就避免了重复的劳动,效率自然是高。而且当worker不够用时,master可以根据配置预先启动几个worker等着;当然空闲worker太多时,也会停掉一些,这样就提高了性能,也节约了资源。这就是fastcgi的对进程的管理。

那PHP-FPM又是什么呢?是一个实现了Fastcgi的程序,被PHP官方收了。

大家都知道,PHP的解释器是php-cgi。php-cgi只是个CGI程序,他自己本身只能解析请求,返回结果,不会进程管理(皇上,臣妾真的做不到啊!)所以就出现了一些能够调度php-cgi进程的程序,比如说由lighthttpd分离出来的spawn-fcgi。好了PHP-FPM也是这么个东东,在长时间的发展后,逐渐得到了大家的认可(要知道,前几年大家可是抱怨PHP-FPM稳定性太差的),也越来越流行。

4.配置Apache

为了使Apache能支持php动态网页的访问需要进行一些配置

vi /etc/httpd/conf/httpd.conf

在AddType下面添加:

AddType application/x-httpd-php-source .php
AddType application/x-httpd-php .php

添加修改默认主页:

在DirectoryIndex index.html 后添加 index.php

使用httpd -t 检查配置文件语法

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::52e8:3708:716d:40a4. Set the 'ServerName' directive globally to suppress this message
Syntax OK

需要配置服务器名,编辑/etc/httpd/conf/httpd.conf

ServerName www.qigefei.com
5.配置Apache连接php-fpm
vi /etc/httpd/conf.d/php-fpm.conf

加入两行内容

ProxyRequests Off		#关闭正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1
#将php资源转发到php-fpm

在/var/www/html/下创建index.php 内容:

<?php
	phpinfo();
?>

重启Apache

systemctl restart httpd

浏览器访问服务器地址,看到php配置信息说明配置成功

6.初始化Mysql
systemctl start mariadb

mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
#默认
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n]
#是否设置root密码 Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
#是否删除匿名用户 n
 ... skipping.

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
#是否禁止root用户远程登录 Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
#是否删除test库 n
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
#现在重新加载表吗 Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
7.配置Mysql
mysql -uroot -proot
grant all on *.* to 'root'@'%';
flush privileges;

测试PHP能不能连接到Mysql,/var/www/html/下创建test.php 内容:

<?php
	$conn = mysql_connect('127.0.0.1','root','root');
	if ($conn)
		echo "连接成功"
	else
		echo "连接失败"
?>

在浏览器输入服务器ip/test.php

连接成功

至此,LAMP搭建完毕

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值