编译安装PHP开发环境

Linux 系统为 CentOS 7.2


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

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

    再次访问成功:


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

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

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

    [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 状态:

    # systemctl status nginx.service


    active nginx 服务正在运行

2. 安装 PHP

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

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

    # 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/

    # 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 包安装:

    # 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 文件路径

    # ./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 配置文件目录

    # cp php.ini-development /etc/php7/php.ini
  5. fastcgi php-fpm
    # 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 不必修改。
    # 监听地址  
    listen = 127.0.0.1:9000  
    # 允许的客户端  
    listen.allowed_clients = 127.0.0.1
  6. 启动 PHP

    # vi /etc/php7/php-fpm.conf  
    // 打开注释:(不打开注释仅能使用 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. 加入环境变量

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

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

    文件内容:

    [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 服务相关命令:

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

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

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

    # 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. 安装依赖包
      # 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 用户不能启动数据库)
      # adduser postgres
    3. 解压编译安装
      # 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. 设置权限
      # chown -R postgres.postgres /usr/local/pgdb/
    5. 配置 PostgreSql
      ======= 以下操作必须在 postgres 用户下完成=======
      切换用户

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

      编辑 .bash_profile 添加以下内容

      $ vim .bash_profile
      
      # 添加以下内容,配置 PGDATA 变量
      PGHOME=/home/postgres
      export PGHOM
      PGDATA=$PGHOME/data
      export PGDATA

      初始化数据文件

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

      数据库操作

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

      创建 test 成功
posted @ 2017-04-27 11:15  妖星杉木  阅读(2875)  评论(0编辑  收藏  举报