ubuntu下编译安装nginx和php

文章目录

建立目录结构

/www
    ./backup
    ./log
        ./nginx
        ./php
    ./server
        ./nginx
        ./php
            ./72
    ./site

创建用户和组并赋予目录权限

sudo useradd www
chown -R www.www /www

安装PHP

// 下载PHP
wget https://www.php.net/distributions/php-7.2.34.tar.gz
// 解压
tar -zxvf php-7.2.34.tar.gz
// 进入php目录
cd php-7.2.34
// 安装依赖
sudo apt-get install libzip-dev bison autoconf build-essential pkg-config git-core   libltdl-dev libbz2-dev libxml2-dev libxslt1-dev libssl-dev libicu-dev libpspell-dev libmcrypt-dev libpng-dev libjpeg8-dev libfreetype6-dev libmysqlclient-dev   libreadline-dev libcurl4-openssl-dev librecode-dev libsqlite3-dev libonig-dev
// 编译
./configure --prefix=/www/server/php/72 --with-config-file-scan-dir=/www/server/php/72/etc/php.d --with-config-file-path=/www/server/php/72/etc --with-openssl=/opt/build --enable-mbstring --enable-zip --enable-bcmath --enable-pcntl --enable-ftp --enable-xml --enable-shmop --enable-soap --enable-exif --enable-calendar --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-opcache --enable-fpm --enable-session --enable-sockets --enable-mbregex --enable-wddx --with-curl --with-iconv --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr  --with-pdo-mysql=mysqlnd --with-gettext=/usr --with-zlib=/usr --with-bz2=/usr --with-recode=/usr --with-xmlrpc --with-mysqli=mysqlnd
// 安装
make && sudo make install
// 拷贝并修改php-fpm配置文件
sudo cp /www/server/php/72/etc/php-fpm.conf.default  /www/server/php/72/etc/php-fpm.conf
vim /www/server/php/72/etc/php-fpm.conf
pid = run/php-fpm.pid
error_log = /www/log/php/php-fpm.log
// 拷贝并修改php-fpm目录下配置文件
sudo cp /www/server/php/72/etc/php-fpm.d/www.conf.default  /www/server/php/72/etc/php-fpm.d/www.conf
vim /www/server/php/72/etc/php-fpm.d/www.conf
user = www
group = www
// 拷贝php.ini
sudo cp ~/php-7.2.34/php.ini-production /www/server/php/72/etc/php.ini
// 启动fpm
sudo /www/server/php/72/sbin/php-fpm

安装NGINX

// 下载
wget http://nginx.org/download/nginx-1.24.0.tar.gz
// 解压
tar -zxvf nginx-1.24.0.tar.gz
// 进入nginx目录
cd nginx-1.24.0
// 编译
./configure --prefix=/www/server/nginx --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
// 安装
make && sudo make install
// 修改nginx启动用户, 找到 user 指令所在的行,通常位于配置文件的开头部分,修改nobody为www
sudo vim /www/server/nginx/conf/nginx.conf
// 配置
sudo vim /www/server/nginx/conf/nginx.con
server {
    listen       80;
    server_name  127.0.0.1;
    access_log   /www/log/nginx/xxx.access.log;
    error_log    /www/log/nginx/xxx.error.log;
    root         /www/site/xxx;

    location / {
        index  index.php index.html;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
// 启动
sudo /www/server/nginx/sbin/nginx
原文链接:,转发请注明来源!
评论已关闭。