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

ls 查看文件列表

vi 编辑文件

[root@localhost www]# cd /var/www/html/
[root@localhost html]# touch index.php
[root@localhost html]# ls
index.php
[root@localhost html]# vi index.php

i/a 开始编辑文件

输入

<?php phpinfo(); ?>

按ESC (结束文本操作) 输入   :wq (保存并退出)

访问查看PHP 配置文件

 

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值