centos7如何安装php环境

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

centos7如何安装php环境

Centos7下面安装PHP环境

用yum快速搭建LAMP平台

 

实验环境:

立即学习“PHP免费学习笔记(深入)”;

[root@nmserver-7 html]# cat  /etc/redhat-release CentOS release 7.3.1611 (AltArch) [root@nmserver-7 html]# uname -aLinux 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  httpdCreated 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 -DFOREGROUND7月 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...ssage7月 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=httpsuccess[root@nmserver-7 ~]# firewall-cmd --permanent --zone=public  --add-service=httpssuccess[root@nmserver-7 ~]# firewall-cmd --reloadsuccess

登录后复制

  1.6确认80端口监听中

[root@nmserver-7 ~]# netstat -tulpActive 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 addr1: 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 forever2: 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 forever3: 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 mariamariadb-libs-5.5.52-1.el7.i686mariadb-5.5.52-1.el7.i686mariadb-server-5.5.52-1.el7.i686mariadb-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 -tulpActive 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 currentpassword for the root user.  If you've just installed MariaDB, andyou 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 MariaDBroot user without the proper authorisation.Set root password? [Y/n] yNew password: Re-enter new password: Password updated successfully!Reloading privilege tables.. ... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y ... Success!Normally, root should only be allowed to connect from 'localhost'.  Thisensures 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 canaccess.  This is also intended only for testing, and should be removedbefore 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 farwill 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 MariaDBinstallation should now be secure.Thanks for using MariaDB!

登录后复制

 

  2.4 登陆数据库测试

[root@nmserver-7 ~]# mysql -uroot -pEnter password: Welcome to the MariaDB monitor.  Commands end with ; or g.Your MariaDB connection id is 11Server version: 5.5.52-MariaDB MariaDB ServerCopyright (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环境的详细内容,更多请关注【创想鸟】其它相关文章!

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

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2134999.html

(0)
上一篇 2025年2月25日 00:12:06
下一篇 2025年2月18日 23:50:25

AD推荐 黄金广告位招租... 更多推荐

相关推荐

  • php读取txt是乱码怎么办

    php读取txt是乱码的解决办法:首先使用“file_get_contents”函数把整个文件读入一个字符串中;然后获取文件的编码方式;接着以只读的方式打开文件;最后使用iconv将“$encoding”转换成“UTF-8”即可。 PHP读…

    2025年2月25日
    200
  • php保存文件乱码怎么办

    php保存文件乱码的解决办法:1、设置php文件本身的编码与网页的编码相匹配;2、在PHP页面中添加“header(“Content-Type: text/html;charset=gb2312″)”;3、设置所有文件的编码格式…

    2025年2月25日
    200
  • php怎样实现utf8转unicode?

    php实现utf8转unicode的方法:首先将第一个字节的0100提取出来;然后将得到的结果左移12位;接着提取111101,将所得到的结果左移6位与最高字节所得的结果取或;最后以此类推第n位直接与111111【0x3F】取与即可。 ph…

    2025年2月25日
    200
  • php bom如何去掉

    去掉php bom的方法:首先用fopen函数打开php文件;然后读取php文件内容;接着调用ltrim将php开头的BOM头去掉;最后通过fwrite命令将去掉BOM头的php文件写入到新的PHP文件中即可。 PHP去除BOM实例 PHP…

    2025年2月25日 编程技术
    200
  • 怎么解决linux php无法解析的问题

    linux php无法解析的解决办法:首先找到apache配置文件;然后在根目录下执行“#find / -name “httpd.conf””;最后添加内容为“AddType application/x-httpd-…

    2025年2月25日
    200
  • php如何设置网页颜色?

    php设置网页颜色的方法:首先新建两个文件,分别是【changecolor.php】、【bgcolor.html】;然后放入本地服务器;接着启动后,在浏览器直接访问;最后选择一个颜色,点击chang按钮即可。 php设置网页颜色的方法: 首…

    2025年2月25日
    200
  • 关于php curl 错误码的说明

    php curl错误码的说明:1、“CURLE_UNSUPPORTED_PROTOCOL (1)”,表示传送给libcurl的网址使用了此libcurl不支持的协议;2、“CURLE_FAILED_INIT (2)”,表示初始化代码失败等。…

    2025年2月25日
    200
  • php如何用if判断文本框是否等于空

    php if不等于空的判断方法:首先通过“$_POST[‘content’];”获取文本框的内容;然后使用“if($content==””){}else{}”方法判断文本框内容是否为空;最后在…

    2025年2月25日
    200
  • php中html标签不显示的设置方法

    在PHP中可以通过“strip_tags()”函数使html不显示,该函数的作用就是剥去字符串中的HTML、XML以及PHP的标签,其语法是“strip_tags(string,allow)”,参数string表示要检查的字符串。 php中…

    2025年2月25日
    200
  • 怎么解决php socket乱码问题

    php socket乱码的解决办法:首先通过“mb_detect_encoding(socket_last_error($socket))”方法对错误信息的编码进行检查;然后将错误信息转为“UTF-8”编码即可。 PHP编写socket错误…

    2025年2月25日
    200

发表回复

登录后才能评论