ubuntu环境安装php7+ngnix+mysql

来源:互联网 发布:客户资料整理软件 编辑:程序博客网 时间:2024/05/01 15:04

第一步:apt-get update ;

apt-get -y install build-essential

第二步:安装mysql

apt-get install  mysql-server

第三步:安装nginx

apt-get install nginx

第四步:编译安装php7.0

下载

   wget http://cn2.php.net/get/php-7.0.9.tar.bz2/from/this/mirror
解压
tar xvf mirror

cd php-7.0.9/


apt-get update


apt-get install libkrb5-dev \
libc-client2007e                 \
libc-client2007e-dev             \
libcurl4-openssl-dev             \
libbz2-dev                       \
libjpeg-dev                      \
libmcrypt-dev                    \
libxslt1-dev                     \
libxslt1.1                       \
libpq-dev                        \
libpng12-dev                     \
libfreetype6-dev                 \
build-essential                  \
git                              \
make


./configure \
--prefix=/opt/php-7.0.9                      \
--with-config-file-path=/opt/php-7.0.9/etc   \
--with-zlib-dir                              \
--with-freetype-dir                          \
--enable-mbstring                            \
--with-libxml-dir=/usr                       \
--enable-soap                                \
--enable-calendar                            \
--with-curl                                  \
--with-mcrypt                                \
--with-zlib                                  \
--with-gd                                    \
--disable-rpath                              \
--enable-inline-optimization                 \
--with-bz2                                   \
--with-zlib                                  \
--enable-sockets                             \
--enable-sysvsem                             \
--enable-sysvshm                             \
--enable-pcntl                               \
--enable-mbregex                             \
--enable-exif                                \
--enable-bcmath                              \
--with-mhash                                 \
--enable-zip                                 \
--with-pcre-regex                            \
--with-pdo-mysql                             \
--with-mysqli                                \
--with-mysql-sock=/var/run/mysqld/mysqld.sock \
--with-jpeg-dir=/usr                         \
--with-png-dir=/usr                          \
--enable-gd-native-ttf                       \
--with-openssl                               \
--with-fpm-user=www-data                     \
--with-fpm-group=www-data                    \
--enable-ftp                                 \
--with-imap                                  \
--with-imap-ssl                              \
--with-kerberos                              \
--with-gettext                               \
--with-xmlrpc                                \
--with-xsl                                   \
--enable-opcache                             \
--enable-fpm

安装php

sudo make install

运行php-fpm服务前,需要把相关的配置文件放好

sudo mv /opt/php-7.0.9/etc/php-fpm.conf.default /opt/php-7.0.9/etc/php-fpm.conf
sudo mv /opt/php-7.0.9/etc/php-fpm.d/www.conf.default /opt/php-7.0.9/etc/php-fpm.d/www.conf
sudo cp ./php.ini-production /opt/php-7.0.9/etc/php.ini

修改fpm监听的端口

vi /opt/php-7.0.9/etc/php-fpm.d/www.conf

listen = 127.0.0.1:9000

然后启动服务  /opt/php-7.0.9/sbin/php-fpm

第五步:nginx配置

/etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  localhost;


    #charset koi8-r;
    access_log  /var/log/nginx/default.access.log;


    root   /var/www/html;
    index  index.html index.htm;


    #error_page  404              /404.html;


    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }


    # 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           /var/www/html;
        fastcgi_pass   127.0.0.1:9000;
        #fastcgi_pass   unix:/run/php/php7.0-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html$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;
    #}
}

重启nginx

service nginx restart

打开host文件vi /etc/hosts
查看进程
ss -tunlp
杀死php-fpm进程
kill
重启php-fpm 
/opt/php-7.0.9/sbin/php-fpm


0 0