热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

centos7如何安装php环境-PHP问题

centos7安装php环境的方法:首先用yum快速搭建LAMP平台;然后安装PHP,并将php与mysql关联起来;接着安装常用PHP模块,并创建“phpinfo();”用于测试PHP;最后重启apache服务器即可。

centos7安装php环境的方法:首先用yum快速搭建LAMP平台;然后安装PHP,并将php与mysql关联起来;接着安装常用PHP模块,并创建“phpinfo();”用于测试PHP;最后重启apache服务器即可。

Centos7下面安装PHP环境

用yum快速搭建LAMP平台

实验环境:

[root@nmserver-7 html]# cat  /etc/redhat-release 
CentOS release 7.3.1611 (AltArch) 
[root@nmserver-7 html]# uname -a
Linux nmserver-7.test.com 3.10.0-514.el7.centos.plus.i686 #1 SMP Wed Jan 25 12:55:04 UTC 2017 i686 i686 i386 GNU/Linux

1、安装apache

  1.1 安装apache

[root@nmserver-7 ~]# yum install httpd httpd-devel

  1.2 启动apache服务

[root@nmserver-7 ~]# systemctl start  httpd

  1.3 设置httpd服务开机启动

[root@nmserver-7 ~]# systemctl enable  httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

  1.4 查看服务状态

[root@nmserver-7 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2017-07-21 17:21:37 CST; 6min ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 2449 (httpd)
   Status: "Total requests: 11; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─2449 /usr/sbin/httpd -DFOREGROUND
           ├─2450 /usr/sbin/httpd -DFOREGROUND
           ├─2451 /usr/sbin/httpd -DFOREGROUND
           ├─2452 /usr/sbin/httpd -DFOREGROUND
           ├─2453 /usr/sbin/httpd -DFOREGROUND
           ├─2454 /usr/sbin/httpd -DFOREGROUND
           ├─2493 /usr/sbin/httpd -DFOREGROUND
           ├─2494 /usr/sbin/httpd -DFOREGROUND
           └─2495 /usr/sbin/httpd -DFOREGROUND
7月 21 17:21:35 nmserver-7.test.com systemd[1]: Starting The Apache HTTP Server...
7月 21 17:21:36 nmserver-7.test.com httpd[2449]: AH00558: httpd: Could not reliably determine the server's fully q...ssage
7月 21 17:21:37 nmserver-7.test.com systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
  1.5 防火墙设置开启80端口
[root@nmserver-7 ~]# firewall-cmd --permanent --zOne=public  --add-service=http
success
[root@nmserver-7 ~]# firewall-cmd --permanent --zOne=public  --add-service=https
success
[root@nmserver-7 ~]# firewall-cmd --reload
success

  1.6确认80端口监听中

[root@nmserver-7 ~]# netstat -tulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN      1084/sshd           
tcp        0      0 localhost:smtp          0.0.0.0:*               LISTEN      1486/master         
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      1084/sshd           
tcp6       0      0 localhost:smtp          [::]:*                  LISTEN      1486/master         
tcp6       0      0 [::]:http               [::]:*                  LISTEN      2449/httpd          
udp        0      0 localhost:323           0.0.0.0:*                           592/chronyd         
udp6       0      0 localhost:323           [::]:*                              592/chronyd

  1.8 查服务器IP

[root@nmserver-7 ~]# ip addr
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:56:bc:cf brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.9/24 brd 192.168.8.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe56:bccf/64 scope link 
       valid_lft forever preferred_lft forever
3: bridge0:  mtu 1500 qdisc noqueue state DOWN qlen 1000
    link/ether ea:89:d5:c7:32:73 brd ff:ff:ff:ff:ff:ff

  1.9 浏览器登陆

如果浏览器访问不了,配置阿里云控制台的安全组80

2、安装mysql

  2.1安装mysql

[root@nmserver-7 ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel
 
root@nmserver-7 ~]# rpm -qa |grep maria
mariadb-libs-5.5.52-1.el7.i686
mariadb-5.5.52-1.el7.i686
mariadb-server-5.5.52-1.el7.i686
mariadb-devel-5.5.52-1.el7.i686

  2.2 开启mysql服务,并设置开机启动,检查mysql状态

[root@nmserver-7 ~]# systemctl start  mariadb 
[root@nmserver-7 ~]# systemctl enable  mariadb 
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@nmserver-7 ~]# systemctl status  mariadb 
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2017-07-22 21:19:20 CST; 21s ago
 Main PID: 9603 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─9603 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─9760 /usr/libexec/mysqld --basedir=/usr --datadir=/v...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:16 nmserver-7.test.com mysqld_safe[9603]: 170722 21...
7月 22 21:19:16 nmserver-7.test.com mysqld_safe[9603]: 170722 21...
7月 22 21:19:20 nmserver-7.test.com systemd[1]: Started MariaDB ...

[root@nmserver-7 ~]# netstat -tulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN      1084/sshd           
tcp        0      0 0.0.0.0:mysql           0.0.0.0:*               LISTEN      9760/mysqld         
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      1084/sshd           
tcp6       0      0 [::]:http               [::]:*                  LISTEN      2449/httpd          
udp        0      0 localhost:323           0.0.0.0:*                           592/chronyd         
udp6       0      0 localhost:323           [::]:*                              592/chronyd

  2.3 数据库安全设置

[root@nmserver-7 ~]# 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] 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] y
 ... 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] n
 ... skipping.
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] y
 - 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] 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!

  2.4 登陆数据库测试

[root@nmserver-7 ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, 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 |
+--------------------+
3 rows in set (0.02 sec)
MariaDB [(none)]>

3、安装PHP

  3.1 安装php

[root@nmserver-7 ~]# yum -y install php
[root@nmserver-7 ~]# rpm -ql php
/etc/httpd/conf.d/php.conf
/etc/httpd/conf.modules.d/10-php.conf
/usr/lib/httpd/modules/libphp5.so
/usr/share/httpd/icons/php.gif
/var/lib/php/session

  3.2 将php与mysql关联起来

[root@nmserver-7 ~]# yum install php-mysql
[root@nmserver-7 ~]# rpm -ql php-mysql
/etc/php.d/mysql.ini
/etc/php.d/mysqli.ini
/etc/php.d/pdo_mysql.ini
/usr/lib/php/modules/mysql.so
/usr/lib/php/modules/mysqli.so
/usr/lib/php/modules/pdo_mysql.so

  3.3 安装常用PHP模块

[root@nmserver-7 ~]# 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

  3.4 测试PHP

[root@nmserver-7 ~]# cd  /var/www/html/
[root@nmserver-7 html]# ls
[root@nmserver-7 html]# pwd
/var/www/html
[root@nmserver-7 html]# vi info.php

~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                            
:wq

  3.5重启apache服务器

[root@nmserver-7 html]# systemctl restart http

  3.6测试PHP

  在自己电脑浏览器输入 192.168.8.9/info.php,你可以看到已经安装的模块;

更多相关知识,请访问PHP中文网!

以上就是centos7如何安装php环境的详细内容,更多请关注 第一PHP社区 其它相关文章!


推荐阅读
  • 阿里云主机实战应用之centos7上的防火墙设置
    最近公司又上了一台服务器,以前都是用centos6系统,这次选择使用了centos7系统的安装镜像,因为现在程序版本在centos7上一般php默认就是5.4以上的,mysql也 ... [详细]
  • Tomcat安装与配置教程及常见问题解决方法
    本文介绍了Tomcat的安装与配置教程,包括jdk版本的选择、域名解析、war文件的部署和访问、常见问题的解决方法等。其中涉及到的问题包括403问题、数据库连接问题、1130错误、2003错误、Java Runtime版本不兼容问题以及502错误等。最后还提到了项目的前后端连接代码的配置。通过本文的指导,读者可以顺利完成Tomcat的安装与配置,并解决常见的问题。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 这是原文链接:sendingformdata许多情况下,我们使用表单发送数据到服务器。服务器处理数据并返回响应给用户。这看起来很简单,但是 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • 如何在服务器主机上实现文件共享的方法和工具
    本文介绍了在服务器主机上实现文件共享的方法和工具,包括Linux主机和Windows主机的文件传输方式,Web运维和FTP/SFTP客户端运维两种方式,以及使用WinSCP工具将文件上传至Linux云服务器的操作方法。此外,还介绍了在迁移过程中需要安装迁移Agent并输入目的端服务器所在华为云的AK/SK,以及主机迁移服务会收集的源端服务器信息。 ... [详细]
  • oceanbase,试用,版,部署,安装,lin ... [详细]
  • MySQL/MariaDB/PerconaDB提权条件漏洞
    背景  2016年11月01日,国外安全研究员DawidGolunski在MyS ... [详细]
  • 列举几个Java程序员通用的、必须掌握的框架
    Java程序员历来就被认为是好职业,但并不是所有的Java程序员都能如愿获得好的回报,任何一个行业,都有低端饱和、高端紧缺的现象ÿ ... [详细]
  • 禁止程序接收鼠标事件的工具_VNC Viewer for Mac(远程桌面工具)免费版
    VNCViewerforMac是一款运行在Mac平台上的远程桌面工具,vncviewermac版可以帮助您使用Mac的键盘和鼠标来控制远程计算机,操作简 ... [详细]
  • 目录浏览漏洞与目录遍历漏洞的危害及修复方法
    本文讨论了目录浏览漏洞与目录遍历漏洞的危害,包括网站结构暴露、隐秘文件访问等。同时介绍了检测方法,如使用漏洞扫描器和搜索关键词。最后提供了针对常见中间件的修复方式,包括关闭目录浏览功能。对于保护网站安全具有一定的参考价值。 ... [详细]
  • NFS文件共享系统
    1、概述:NFS(NetworkFileSystem)意为网络文件系统,它最大的功能就是可以通过网络,让不同的机器不同的操作系统可以共享 ... [详细]
  • Centos7安装MySql5.6
    如何在CentO ... [详细]
  • 数据库进入全新时代,腾讯云发布五大数据库提前布局
    8月28日,腾讯云数据库在京正式启动战略升级,宣布未来将聚焦云原生、自治、超融合三大战略方向,以用户为中心,联接未来。并在现场面向全球用户同步发布五大战略级新品,包括数据库智能管家 ... [详细]
  • 本文是搭建的mariadb-10.0.17版本的下载地址:https:downloads.mariadb.orginterstitialmariadb-10.0.17sourcemariadb-10.0.17.tar.gzfromhtt ... [详细]
author-avatar
不点包子
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有