centos7手动编译安装nginx与php

编译安装nginx1.25

#安装依赖
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel 

#下载源码并解压
cd /usr/local/src
wget http://nginx.org/download/nginx-1.25.3.tar.gz
tar -zxvf nginx-1.25.3.tar.gz

#编译安装
cd nginx-1.25.3
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-stream
make && make install

#创建软连接
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

#创建服务
vi /lib/systemd/system/nginx.service
#填入以下内容
[Unit]
Description=nginx service
After=network.target 

[Service] 
Type=forking 
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true 

[Install] 
WantedBy=multi-user.target

#测试
#开启nginx
systemctl restart nginx
systemctl enable nginx
#防火墙放行80端口,然后浏览器访问
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --reload

编译安装php7.2

#安装依赖
yum install gcc autoconf gcc-c++
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel
yum install systemd-devel
yum install openjpeg-devel

#下载源代码
cd /usr/local/src
wget https://www.php.net/distributions/php-7.2.28.tar.gz
tar -zxvf php-7.2.28.tar.gz

#新建用户及组
groupadd php-fpm
useradd -s /sbin/nologin -g php-fpm -M php-fpm

#编译及安装
cd /usr/local/src/php-7.2.28

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-xmlreader \
--enable-xmlwriter \
--enable-soap \
--enable-calendar \
--with-curl \
--with-zlib \
--with-gd \
--with-pdo-sqlite \
--with-pdo-mysql \
--with-mysqli \
--with-mysql-sock \
--enable-mysqlnd \
--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-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--disable-fileinfo

make && make install

#配置
cp /usr/local/src/php-7.2.28/php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

#配置错误文件位置 及pid
vi /usr/local/php/etc/php-fpm.conf
error_log = /var/log/php-fpm.log
pid = /usr/local/php/var/run/php-fpm.pid

cp /usr/local/php/etc/php-fpm.d/www.conf.default  /usr/local/php/etc/php-fpm.d/www.conf

#配置服务
cp /usr/local/src/php-7.2.28/sapi/fpm/php-fpm.service /usr/lib/systemd/system/

#启动
systemctl enable php-fpm
systemctl restart php-fpm

#添加环境变量:
vi  /etc/profile
export PATH=$PATH:'/usr/local/php/bin/'

source /etc/profile

#参考资料
https://learnku.com/articles/41767

nginx配置php网站

server {
    listen       80;
    server_name  127.0.0.1;
    root /www/test;

    location / {       
        index index.php;
        autoindex on;
    }  

    location ~ \.php$ {       
        fastcgi_intercept_errors on;       
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

}