php

作者: 北疆07 | 来源:发表于2019-06-14 14:32 被阅读0次

    搭建PHP环境

    yum remove php-mysql-5.4 php php-fpm php-common

    更新yum源信息

    [root@web02 ~]#rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    [root@web02 ~]#rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    

    安装PHP服务及相关软件

    [root@web02 ~]# yum install -y php71w php71w-cli php71w-common php71w-devel php71w-embedded  php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache  php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
    

    配置PHP-fpm用户与nginx相同

    [root@web02 ~]# sed -i '/^user/c user=nginx' /etc/php-fpm.d/www.conf 
    [root@web02 ~]# sed -i '/^group/c group=nginx' /etc/php-fpm.d/www.conf 
    [root@web02 ~]# egrep -n '^user|^group' /etc/php-fpm.d/www.conf 
    8:group=nginx
    10:group=nginx
    

    启动php-fpm并检查服务

    [root@web02 ~]# systemctl start php-fpm
    [root@web02 ~]# systemctl enable php-fpm
    [root@web02 ~]# ps -ef |grep php
    root      11860      1  0 03:43 ?        00:00:00 php-fpm: master process (/etc/php-fpm.conf)
    nginx     11861  11860  0 03:43 ?        00:00:00 php-fpm: pool www
    

    nginx配置软件

    [root@web02 /etc/nginx/conf.d]# vim www.conf 
    server {
       listen   80;
       server_name   www.bossx.com;
       location / {
             root   /app/html/www;
             index  index.php index.html;
       } 
       location ~ \.php$ {
       root   /app/html/www;
       fastcgi_pass  127.0.0.1:9000;
       fastcgi_index index.php; 
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;      
       }
    }
    

    编写配置文件,检查php与nginx是否连接成功

    [root@web02 /app/html/www]# vim info.php 
    <?php
      phpinfo();
    ?>
    

    编写文件,检查php与mysql是否连接成功

    [root@web01 /blog]# vim mysqli.php 
    <?php
    $servername = "localhost";
    $username = "wordpress";
    $password = "123456";
    
    // 创建连接
    $conn = mysqli_connect($servername, $username, $password);
    
    // 检测连接
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    echo "php连接MySQL数据库成功";
    ?>
    

    相关文章

      网友评论

          本文标题:php

          本文链接:https://www.haomeiwen.com/subject/rhdbfctx.html