·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> linux安装php&nginx

linux安装php&nginx

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23

1.安装libxml2

  • 地址:http://ftp.gnome.org/pub/GNOME/sources/libxml2/
  • wget http://caesar.acc.umu.se/pub/GNOME/sources/libxml2/2.6/libxml2-2.6.30.tar.gz
./configure --PRefix=/usr/local/libxml2
make
make install

失败的话执行 make clean,再重复上述操作

2.安装php

-下载php ...

./configure --prefix=/usr/local/php --with-MySQL=/usr/local/mysql --with-libxml-dir=/usr/local/libxml2
make
make install

也可以使用yum安装软件包:

yum list | grep xxx

yum install -y libpng-devel libjpeg-devel freetype-devel libmcrypt-devel ...

./configure --prefix=/usr/local/php5.6 --with-config-file-path=/usr/local/php5.6/etc --enable-fpm --with-libxml-dir=/usr/local/libxml2 --with-png-dir --with-jpeg-dir --with-freetype-dir --with-gd --with-mcrypt --enable-soap --enable-mbstring=all --enable-sockets  --with-mysqli=mysqlnd  --with-pdo-mysql --enable-mysqlnd --with-zlib-dir=/usr/local/zlib --disable-fileinfo
#测试php-fpm配置
/usr/local/php/sbin/php-fpm -t
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf -t

#启动php-fpm
/usr/local/php/sbin/php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf

#关闭php-fpm
kill -INT `cat /usr/local/php/var/run/php-fpm.pid`

#重启php-fpm
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`

3.安装Nginx

Nginx需要依赖下面3个包

  1. gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ ) zlib-1.2.8.tar.gz
  2. rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ ) pcre-8.21.tar.gz
  3. ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ ) openssl-1.0.1.tar.gz

安装zlib

wget http://jaist.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz
./configure --prefix=/usr/local/zlib
make && make install

安装pcre

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
./configure --prefix=/usr/local/pcre
make && make install

安装openssl

wget http://www.openssl.org/source/openssl-1.0.2e.tar.gz
./config --prefix=/usr/local/openssl
make && make install

创建用户

  1. groupadd -r nginx

    \#创建系统工作组,系统工作组的组ID小于500
  2. useradd -r -g nginx -s /bin/false -M nginx

    \#-r 建立系统帐号
    \#-g<群组> 指定用户所属的群组
    \#-s<shell> 指定用户登入后所使用的shell,"/bin/false"su不到该用户
    \#-M 不自动建立用户的登入目录

    下载nginx

wget http://nginx.org/download/nginx-1.9.9.tar.gz

./configure --sbin-path=/usr/local/nginx/ --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/home/install/pcre-8.38 --with-zlib=/home/install/zlib-1.2.8 --with-openssl=/home/install/openssl-1.0.2e --with-http_stub_status_module --user=nginx --group=nginx

--with-zlib 和 --with-openssl --with-openssl #指向解压的源码目录
--with-http_stub_status_module #启用nginx的NginxStatus功能,用来监控Nginx的当前状态:

在nginx.conf的server块中添加如下代码
location /nginx_status {
        # Turn on nginx stats
        stub_status on;
        # I do not need logs for stats
        access_log   off;
        # Security: Only allow access from 192.168.1.100 IP #
        #allow 192.168.1.100;
        # Send rest of the world to /dev/null #
        #deny all;
    }
    这段代码是加在默认的server里的,
    假设默认server的配置为

    listen       127.0.0.1:80;
    server_name  127.0.0.1;
    那么访问nginx的状态,就可以通过 curl 127.0.0.1/nginx_status访问了

    返回结果类似于:

    Active connections: 1 
    server accepts handled requests
     655 655 1985 
    Reading: 0 Writing: 1 Waiting: 0