微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

VM虚拟机 CentOS7 安装PHP 环境

之前安装过PHP 云服务器环境,但是没有深究, 停留在粗浅层次,我记性不好 记点东西 防止自己遗忘

PHP 服务器 安装分两种 一种YUM 安装  一种编译安装 (由于linux机制,每个文件夹都有他指定的含义,不可随意使用,编译安装需要了解,文件分类信息,YUM 安装则不需要去考虑,因为他已经帮你固定安装好了目录,这就是网上为什么 推荐yum的原因) (文中例子 是不必要操作,可了解但不是必须,个人建议 理解一下)

YUM安装注意事项

1进入ROOT 权限(虚拟机) su 命令 接着输入密码 前缀带ROOT 即成功   CD /   (切换到根目录,可不用操作怕误导 注释出来)

[PCname@localhost ~]$ su

password:

[root@localhost PCname]# cd /

2.更换安装YUM 源  

如果  认 输入 yum install PHP  这样 认安装的会是5.4的PHP  但是 我们现阶段 基本上都是5.6 以及PHP7 的版本 此时我们就需要更换YUM源。

CentOS 6.x 源

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

 CentOS 7.x 源

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

例子:查看该源对应的安装包命令(以PHP 为例)

yum list --enablerepo=webtatic | grep PHP

例子:获得信息如下 (截取部分)

[root@localhost /]# yum list --enablerepo=webtatic | grep PHP

emacs-PHP-mode.noarch 1.18.2-1.el7 base

geos-PHP.x86_64 3.4.2-2.el7 epel

graphviz-PHP.x86_64 2.30.1-21.el7 base

mlt-PHP.x86_64 6.4.1-4.el7 epel

mod_PHP71w.x86_64 7.1.24-1.w7 webtatic

mod_PHP72w.x86_64 7.2.12-1.w7 webtatic

PHP.x86_64 5.4.16-46.el7 base

PHP-Assetic.noarch 1.3.2-3.el7 epel

PHP-easyrdf.noarch 0.9.0-1.el7 epel

PHP-easyrdf-doc.noarch 0.9.0-1.el7 epel

PHP-Faker.noarch 1.5.0-5.el7 epel

PHP-IDNA_Convert.noarch 0.8.0-2.el7 epel

PHP-JMSParser.noarch 1.0.0-9.el7 epel

PHP-JsonSchema.noarch 1.6.1-1.el7 epel

PHP-Metadata.noarch 1.6.0-1.el7 epel

PHP-Monolog.noarch 1.22.0-1.el7 epel

例子:查询5.6版本PHP 命令(也可以查 其他软件)

yum search PHP56w

例子:显示结果

[root@localhost yum.repos.d]# yum search PHP56w

已加载插件:fastestmirror,langpacks

Loading mirror speeds from cached hostfile

* base: mirrors.163.com

* epel: mirrors.aliyun.com

* extras: mirrors.aliyun.com

* updates: mirrors.163.com

* webtatic: uk.repo.webtatic.com

============================= N/S matched: PHP56w ==============================

PHP56w.x86_64 : PHP scripting language for creating dynamic web sites

PHP56w-bcmath.x86_64 : A module for PHP applications for using the bcmath

: library

PHP56w-cli.x86_64 : Command-line interface for PHP

PHP56w-common.x86_64 : Common files for PHP

PHP56w-dba.x86_64 : A database abstraction layer module for PHP applications

PHP56w-devel.x86_64 : Files needed for building PHP extensions

PHP56w-embedded.x86_64 : PHP library for embedding in applications

PHP56w-enchant.x86_64 : Enchant spelling extension for PHP applications

PHP56w-fpm.x86_64 : PHP FastCGI Process Manager

PHP56w-gd.x86_64 : A module for PHP applications for using the gd graphics

: library

PHP56w-imap.x86_64 : A module for PHP applications that use IMAP

PHP56w-interbase.x86_64 : A module for PHP applications that use

: Interbase/Firebird databases

PHP56w-intl.x86_64 : Internationalization extension for PHP applications

PHP56w-ldap.x86_64 : A module for PHP applications that use LDAP

PHP56w-mbstring.x86_64 : A module for PHP applications which need multi-byte

: string handling

PHP56w-mcrypt.x86_64 : Standard PHP module provides mcrypt library support

PHP56w-mssql.x86_64 : MSsql database module for PHP

PHP56w-MysqL.x86_64 : A module for PHP applications that use MysqL databases

PHP56w-MysqLnd.x86_64 : A module for PHP applications that use MysqL databases

PHP56w-odbc.x86_64 : A module for PHP applications that use ODBC databases

PHP56w-opcache.x86_64 : An opcode cache Zend extension

PHP56w-pdo.x86_64 : A database access abstraction module for PHP applications

PHP56w-pear.noarch : PHP Extension and Application Repository framework

PHP56w-pecl-apcu.x86_64 : APCu - APC User Cache

PHP56w-pecl-apcu-devel.x86_64 : APCu developer files (header)

PHP56w-pecl-gearman.x86_64 : PHP wrapper to libgearman

PHP56w-pecl-geoip.x86_64 : Extension to map IP addresses to geographic places

PHP56w-pecl-igbinary.x86_64 : Replacement for the standard PHP serializer

PHP56w-pecl-igbinary-devel.x86_64 : Igbinary developer files (header)

PHP56w-pecl-imagick.x86_64 : Provides a wrapper to the ImageMagick library

PHP56w-pecl-imagick-devel.x86_64 : Imagick developer files (header)

PHP56w-pecl-libsodium.x86_64 : Wrapper for the sodium cryptographic library

PHP56w-pecl-memcache.x86_64 : Extension to work with the Memcached caching

: daemon

PHP56w-pecl-memcached.x86_64 : Extension to work with the Memcached caching

: daemon

PHP56w-pecl-mongodb.x86_64 : PECL package MongoDB driver

PHP56w-pecl-redis.x86_64 : Extension for communicating with the Redis key-value

: store

PHP56w-pecl-xdebug.x86_64 : PECL package for debugging PHP scripts

PHP56w-pgsql.x86_64 : A Postgresql database module for PHP

PHP56w-PHPdbg.x86_64 : Interactive PHP debugger

PHP56w-process.x86_64 : Modules for PHP script using system process interfaces

PHP56w-pspell.x86_64 : A module for PHP applications for using pspell interfaces

PHP56w-recode.x86_64 : A module for PHP applications for using the recode

: library

PHP56w-snmp.x86_64 : A module for PHP applications that query SNMP-managed

: devices

PHP56w-soap.x86_64 : A module for PHP applications that use the SOAP protocol

PHP56w-tidy.x86_64 : Standard PHP module provides tidy library support

PHP56w-xml.x86_64 : A module for PHP applications which use XML

PHP56w-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC

: protocol

名称和简介匹配 only,使用“search all”试试。

2.安装Apache 

yum install httpd httpd-devel

启动apache:

/bin/systemctl start httpd.service

此时 用浏览器 访问你服务器IP地址  应该是

这样表示安装成功

笔记:

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall开机启动

firewall-cmd --state #查看认防火墙状态(关闭显示notrunning,开启后显示running)

2.安装MysqL:

yum install MysqL MysqL-server

启动MysqL:

systemctl start MysqL.service

如果报错

[root@localhost yum.repos.d]# systemctl start MysqL.service

Failed to start MysqL.service: Unit MysqL.service Failed to load: No such file or directory.

或者

Failed to start MysqLd.service: Unit not found

则安装 mariadb-server

yum install -y mariadb-server

启动服务

systemctl start mariadb.service

添加到开机启动

systemctl enable mariadb.service

//键入命令

[root@localhost /]# systemctl enable mariadb.service

Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

//进入MysqL

[root@localhost /]# MysqL -uroot -p

Enter password:

Welcome to the MariaDB monitor. Commands end with ; or g.

Your MariaDB connection id is 2

Server version: 5.5.60-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)]>

 键入EXIT+ 回车退出MysqL

搞定~

3.安装PHP

yum install PHP56w

重启apache使PHP生效

/bin/systemctl start httpd.service

查看 PHP 版本  PHP -v   

[root@localhost /]# PHP -v

PHP 5.6.38 (cli) (built: Sep 15 2018 08:16:33)

copyright (c) 1997-2016 The PHP Group

Zend Engine v2.6.0,copyright (c) 1998-2016 Zend Technologies

进入文件目录

cd / (进入根目录)

cd var/www/html

[root@localhost www]# cd /var/www/html/

[root@localhost html]# touch index.PHP

[root@localhost html]#

此时可以在目录:/var/www/html/下建立一个PHP文件index.PHP,加入代码 访问查看PHP 配置文件

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐