Ubuntu Nginx+php+yaf安装

2017-09-13 08:13:35来源:CSDN作者:lemon2631人点击

分享

一、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 //安装的位置makemake 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 makemake 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-fpm56chmod+x /etc/init.d/php-fpm56chkconfig --add php-fpm56service php-fpm56 startss -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.tgztar -xzvf yaf-2.3.5.tgzcd yaf-2.3.5

编译安装

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

php.ini中加入yaf扩展

extension=yaf.soyaf.use_namespace=1

然后启动nginx和php-fpm

四 测试

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

<?phpphpinfo();?>

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

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台