• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

编译安装PHP开发环境

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

Linux 系统为 CentOS 7.2


1. 安装 Nginx
  1. 安装 Nginx 依赖包:
    1
    # yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
  2. 安装 Nginx:
    1
    2
    3
    4
    # tar -xzvf nginx-1.10.1.tar.gz
    # cd nginx-1.6.2                                      
    # ./configure --prefix=/usr/local/nginx
    # make && make install
  3. 启动 Nginx:
    1
    # /usr/local/nginx/sbin/nginx
  4. 浏览器访问服务器地址看是否成功,如果不能访问则关闭防火墙:

    1
    2
    3
    # systemctl start firewalld.service   #启动
    # systemctl stop firewalld.service   #停止
    # systemctl disable firewalld.service   #禁止 firewall 开机启动

    再次访问成功:


    nginx 安装成功
  5. 设置开机启动:
    新建 Nginx 服务文件;

    1
    # vim /lib/systemd/system/nginx.service

    保存以下内容,并设置权限为 754;

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    [Unit]
    Description=nginx
    After=network.target
     
    [Service]
    Type=forking
    ExecStart=/usr/local/nginx/sbin/nginx start   # 如果报错(nginx: invalid option: "start"), 则不加 start 参数
    ExecReload=/usr/local/nginx/sbin/nginx restart
    ExecStop=/usr/local/nginx/sbin/nginx stop
    PrivateTmp=true
     
    [Install]
    WantedBy=multi-user.target
    # chmod 754 /lib/systemd/system/nginx.service
    # systemctl enable nginx.service

     

    重启服务器,访问浏览器成功。查看 Nginx 状态:

    1
    # systemctl status nginx.service<br><br>

    active nginx 服务正在运行

2. 安装 PHP

参考自: http://blog.csdn.net/u010861514/article/details/51926575

  1. 解压文件
    1
    2
    # tar -xzf php-7.0.11.tar.gz
    # cd php-7.0.11/
  2. 安装依赖

    1
    # yum -y install gcc gcc-c++ libxml2 libxml2-devel bzip2 bzip2-devel libmcrypt libmcrypt-devel openssl openssl-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel readline readline-devel libxslt-devel perl perl-devel psmisc.x86_64 recode recode-devel libtidy libtidy-devel

    如果 yum 安装不了,则下载无法安装的包手动编译安装,如下:
    libmcrypt 下载地址:http://sourceforge.net/projects/mcrypt/files/Libmcrypt/

    1
    2
    3
    4
    # tar -xzvf libmcrypt-2.5.8.tar.gz
    # cd libmcrypt-2.5.8
    # ./configure
    # make && make install

    libtidy 下载地址:http://fr.rpmfind.net/linux/rpm2html/search.php?query=libtidy&submit=Search+...
    rpm 包安装:

    1
    # rpm -ivh libtidy-5.1.25-1.fc25.i686.rpm
  3. 编译与配置
    --prefix=/usr/local/php7 主程序文件路径
    --sysconfdir=/etc/php7 配置文件路径
    --with-config-file-path=/etc/php7 php.ini 文件路径

    1
    2
    3
    4
    # ./configure --prefix=/usr/local/php7 --sysconfdir=/etc/php7 --with-config-file-path=/etc/php7 --enable-fpm --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mhash --with-openssl --with-zlib --with-bz2 --with-curl --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-zlib --enable-mbstring --with-mcrypt --enable-sockets --with-iconv-dir --with-xsl --enable-zip --with-pcre-dir --with-pear --enable-session  --enable-gd-native-ttf --enable-xml --with-freetype-dir --enable-gd-jis-conv --enable-inline-optimization --enable-shared --enable-bcmath --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-mbregex --enable-pcntl --with-xmlrpc --with-gettext --enable-exif --with-readline --with-recode --with-tidy
     
    # make
    # make install

      

    如果编译出错,则网上查找解决方案。

  4. 安装成功后拷贝源码包中的 php.ini-development 文件到 PHP 配置文件目录

    1
    # cp php.ini-development /etc/php7/php.ini
  5. fastcgi php-fpm
    1
    2
    3
    # cp /etc/php7/php-fpm.conf.default /etc/php7/php-fpm.conf
    # cp /etc/php7/php-fpm.d/www.conf.default /etc/php7/php-fpm.d/www.conf
    # vi /etc/php7/php-fpm.d/www.conf
    www.conf 默认即可是本机 127.0.0.1 不必修改。
    1
    2
    3
    4
    # 监听地址 
    listen = 127.0.0.1:9000 
    # 允许的客户端 
    listen.allowed_clients = 127.0.0.1
  6. 启动 PHP

    1
    # vi /etc/php7/php-fpm.conf
    1
    // 打开注释:(不打开注释仅能使用 killall php-fpm 关闭 php) pid = run/php-fpm.pid // 启动: # /usr/local/php7/sbin/php-fpm // 立刻终止 # kill -INT `cat /usr/local/php7/var/run/php-fpm.pid` # kill -TERM `cat /usr/local/php7/var/run/php-fpm.pid` # killall php-fpm // 平滑终止 # kill -QUIT `cat /usr/local/php7/var/run/php-fpm.pid` // 平滑重启 # kill -USR2 `cat /usr/local/php7/var/run/php-fpm.pid`
  7. 加入环境变量

    1
    2
    3
    4
    5
    6
    # vim /etc/profile
     
    末尾添加:
    export PATH=$PATH:/usr/local/php7/sbin:/usr/local/php7/bin
     
    # source /etc/profile     立即生效
  8. 设置开机启动

    1
    2
    3
    # vim /lib/systemd/system/php-fpm.service
    # chmod 754 /lib/systemd/system/php-fpm.service
    # systemctl enable php-fpm.service

    文件内容:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    [Unit]
    Description=php-fpm
    After=syslog.target network.target
    [Service]
    Type=forking
    ExecStart=/usr/local/php7/sbin/php-fpm
    ExecReload=/bin/kill -USR2 $MAINPID
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target

    PHP 服务相关命令:

    1
    2
    # systemctl daemon-reload        修改 serivce 文件后,需要刷新配置文件
    # systemctl (start | restart | reload | stop | enable | disable | status) php-fpm.service

    若果报错(ERROR: unable to bind listening socket for address ...)先把所有 PHP 进程杀掉,然后重启:

    1
    2
    # killall php-fpm
    # systemctl start php-fpm.service
  9. 配置 Nginx 访问 PHP

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    # vim /usr/local/nginx/conf/nginx.conf
     
    ### 编辑 server 让 Nginx 支持php:
    server {
         listen       80;
         server_name  localhost;
     
         location / {
             root   html;
             index  index.html index.htm index.php;
         }
         error_page   500 502 503 504  /50x.html;
         location = /50x.html {
             root   html;
         }
     
         location ~ \.php$ {
             root           html;
             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 的 html 目录下创建一个 PHP 文件,访问该文件查看配置信息:


php 安装成功

3. 安装 PostgreSql
    1. 安装依赖包
      1
      # yum install -y gcc.x86_64 glibc.x86_64 glibc-devel.x86_64 vim-enhanced.x86_64 gcc-java apr apr-devel openssl openssl-devel libgcc.x86_64 java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64 perl-Module-Install.noarch readline-devel.x86_64
    2. 创建 postgres 用户(一定要创建,不然 root 用户不能启动数据库)
      1
      # adduser postgres
    3. 解压编译安装
      1
      2
      3
      4
      5
      # tar -xzvf postgresql-9.6.0.tar.gz
      # cd postgresql-9.6.0
      # ./configure --prefix=/usr/local/pgdb --enable-thread-safety
      # make
      # make install
    4. 设置权限
      1
      # chown -R postgres.postgres /usr/local/pgdb/
    5. 配置 PostgreSql
      ======= 以下操作必须在 postgres 用户下完成=======
      切换用户

      1
      2
      # su postgres
      $ cd ~     切换到用户目录

      编辑 .bash_profile 添加以下内容

      1
      2
      3
      4
      5
      6
      7
      $ vim .bash_profile
       
      # 添加以下内容,配置 PGDATA 变量
      PGHOME=/home/postgres
      export PGHOM
      PGDATA=$PGHOME/data
      export PGDATA

      初始化数据文件

      1
      2
      3
      4
      5
      $ cd /usr/local/pgdb
      $ mkdir data
      $ cd /usr/local/pgdb/bin
      $ ./initdb -D ../data             初始化数据文件
      $ ./pg_ctl -D ../data start       启动数据库服务,其中-D选项指定文件存放目录为上一步中生成的data目录

      数据库操作

      1
      2
      $ ./createdb test       创建数据库 test
      $ ./psql test           访问 test

      创建 test 成功

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
php中readdir关于时间路径排序的代码发布时间:2022-07-10
下一篇:
不要在PHP7中踩这些坑发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap