基于centos7.3 redhat7.3安装LAMP(php7.0 php7.1)生产环境实践

给你一囗甜甜゛ 提交于 2019-12-01 19:35:33

#本机信息

hostname LAMP
ip 172.22.34.164

 

#由于官网yum源下载慢,这里添加ali源

yum clean all
rm -rf /etc/yum.repos.d/*.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
sed -i '/aliyuncs/d' /etc/yum.repos.d/CentOS-Base.repo
sed -i '/aliyuncs/d' /etc/yum.repos.d/epel.repo
sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo

 

#关闭selinux&firewalld

sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0
systemctl stop firewalld 
systemctl disable firewalld

 

#同步各个节点时间:

yum -y install rdate
rdate -s time-a.nist.gov
echo rdate -s time-a.nist.gov >> /etc/rc.d/rc.local 
chmod +x /etc/rc.d/rc.local

 

#添加EPEL repo来安装最新的phpMyAdmin如下:

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum -y install epel-release

 

#MariaDB是MySQL开发人员Monty Widenius的MySQL分支。MariaDB与MySQL兼容,我选择在这里使用MariaDB而不是MySQL。运行这个命令来安装MariaDB和yum:

yum -y install mariadb-server mariadb

 

#启动maridb 并设置开机启动

systemctl start mariadb.service
systemctl enable mariadb.service

 

#设置maridb密码

mysql_secure_installation
[
root@server1
 ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
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): 
<--ENTER
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] 
New password: 
<--yourmariadbpassword
Re-enter new password: 
<--yourmariadbpassword
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] 
<--ENTER
 ... Success!
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] 
<--ENTER
 ... 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] 
<--ENTER
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] 
<--ENTER
 ... 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!

 

#apache 2.4。Apache包已经提供,因此我们可以这样安装它:

yum -y install httpd

#启动apache 并设置开机启动

systemctl start httpd.service
systemctl enable httpd.service

#如果开启的防火墙 那么设置防火墙策略来允许

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

#测试apapche是否正常提供网页

http://172.22.34.164

 

 

#安装php

#添加存储库

rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm

#安装yum - utils,因为我们需要yum -config- manager实用程序。

 

yum -y install yum-utils

#安装PHP 7.1

 

#如果您想使用PHP 7.1,请使用:

yum-config-manager --enable remi-php71
yum -y install php php-opcache

 

#必须重新启动Apache来应用更改:

 systemctl restart httpd.service


#测试PHP /获取有关PHP安装的详细信息

vim /var/www/html/info.php
<?php
phpinfo();
?

#查看测试页

firefox http://172.22.34.164/info.php

 

 

 

 

#在PHP中获得MySQL支持

#为了在PHP中获得MySQL支持,我们可以安装php71w - MySQL包。安装其他PHP模块也是一个好主意,因为您可能需要它们用于您的应用程序。您可以搜索可用的PHP5模块:

yum search php

#选择你需要的,然后安装:

yum -y install php-mysql

#在接下来的步骤中,我将安装一些通用的PHP模块,这些模块是由CMS系统(如Wordpress、Joomla和Drupal)所要求的:

yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-soap curl curl-devel

#重启apache更改生效

systemctl restart httpd.service

#现在重新加载http://172.22.34.164/info。在您的浏览器中,再向下滚动到模块部分。你现在应该在那里找到很多像curl这样的新模块。

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!