Ubuntu Nginx+php+yaf安装

本文详细介绍了如何从零开始安装Nginx和PHP,包括下载、编译、配置等步骤,并通过示例展示了如何配置Nginx使其支持PHP。此外还提供了YAF框架的安装教程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、Nginx安装

下载

 wget -c http://nginx.org/download/nginx-1.4.2.tar.gz

解压

tar -xzvf nginx-1.4.2.tar.gz

编译安装

cd nginx-1.4.2
./configure --prefix=/usr/php/nginx //安装的位置
make
make install

运行

cd /usr/php/nginx/sbin/
./nginx
./nginx -s stop //退出
./nginx -s reload //重新加载配置文件

运行nginx的时候,碰到了错误:[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use),可以使用

sudo fuser -k 80/tcp

然后重新启动服务器。然后打开浏览器输入localhost.

二 PHP安装

安装PHP
进入到php的解压目录

./configure --prefix=/usr/php/php-5.6 \
--with-config-file-path=/usr/php/php-5.6/etc \
--with-config-file-scan-dir=/usr/php/php-5.6/conf.d \
--enable-fpm \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--with-freetype-dir=/usr/php/php-5.6/freetype \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr/php/php-5.6/libxml \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl=/usr \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--enable-intl --with-xsl 
make
make install

编译过程中有可能会因为依赖包未安装而报错,使用apt-get install 安装相应的依赖包即可。编译安装完成后,将etc目录下php-fpm.conf.default配置示例文件重命名为php-fpm.conf

将php-fpm作为系统服务
进入安装源文件目录:

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm56
chmod+x /etc/init.d/php-fpm56
chkconfig --add php-fpm56
service php-fpm56 start
ss -tnl

配置php和ngnix,使nginx支持php
nginx的配置文件为/usr/php/nginx/conf/nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        access_log  logs/host.access.log;

    root    /mnt/hgfs/share/projects/ct_webtools/public;
        index   index.php index.html;


        if (!-e $request_filename){
        rewrite ^/(.*)  /index.php?$1 last;
    }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        location ~ \.php {
        #fastcgi_pass unix:/tmp/php-cgi.sock;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME   /mnt/hgfs/share/projects/ct_webtools/public$fastcgi_script_name;
        #include fastcgi.conf;
        include fastcgi_params;
    }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}

将源文件目录下的的php.ini-production复制到安装目录etc文件夹下,并改名为php.ini
启动php-fpm,nginx

三、yaf的安装

下载yaf-2.3.5

wget -c https://pecl.php.net/get/yaf-2.3.5.tgz
tar -xzvf yaf-2.3.5.tgz
cd yaf-2.3.5

编译安装

./configure --with-php-config=/usr/php/php-5.6/bin/php-config //指定配置文件
make
make install

php.ini中加入yaf扩展

extension=yaf.so
yaf.use_namespace=1

然后启动nginx和php-fpm

四 测试

在nginx的根目录下创建test.php,内容如下:

<?php
phpinfo();?>

在浏览器中输入localhost/test.php即可查看php的扩展信息。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值