Skip to content

Instantly share code, notes, and snippets.

@ZiTAL
Last active January 4, 2019 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZiTAL/ac836061f4dbb46483c4ce089206a875 to your computer and use it in GitHub Desktop.
Save ZiTAL/ac836061f4dbb46483c4ce089206a875 to your computer and use it in GitHub Desktop.
php: compile php-fpm for nginx
cd /usr/src
wget http://au1.php.net/get/php-7.2.13.tar.gz/from/this/mirror
mv mirror php-7.2.13.tar.gz
tar -xvzf php-7.2.13.tar.gz
cd php-7.2.13
mkdir -p /opt/php/php-7.2.13

nano configure.sh

#!/bin/bash
./configure \
--prefix=/opt/php/php-7.2.13 \
--with-config-file-path=/opt/php-7.0.26/etc
--enable-shared \
--enable-mbstring \
--with-curl \
--with-gd \
--with-zlib \
--enable-bcmath \
--with-xmlrpc \
--with-xsl \
--with-pgsql \
--with-pdo-pgsql \
--enable-ctype \
--with-openssl \
--with-bz2 \
--enable-fpm \
--with-fpm-user=zital \
--with-fpm-group=zital
bash configure.sh

CPU-en arabera:

make -j2
cp /usr/src/php-7.2.13/php.ini-development /opt/php/php-7.2.13/etc/php.ini
echo "include_path = \"/opt/php/php-7.2.13/lib/php\"" >> /opt/php/php-7.2.13/etc/php.ini
cp /opt/php/php-7.2.13/etc/php-fpm.conf.default /opt/php/php-7.2.13/etc/php-fpm.conf
cp /opt/php/php-7.2.13/etc/php-fpm.d/www.conf.default /opt/php/php-7.2.13/etc/php-fpm.d/www.conf

nano /opt/php/php-7.2.13/etc/php-fpm.d/www.conf

;...
listen = /run/php-fpm/php7.2-fpm.sock
;...
listen.owner = zital
listen.group = zital
listen.mode = 0660
;...
catch_workers_output = yes
;...

nano /etc/systemd/system/php7.2-fpm.service

[Unit]
Description=The PHP FastCGI Process Manager
After=network.target

[Service]
Type=simple
PIDFile=/run/php-fpm/php7.2-fpm.pid
ExecStart=/opt/php/php-7.2.13/sbin/php-fpm --nodaemonize --fpm-config /opt/php/php-7.2.13/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target
mkdir -p /run/php-fpm/
systemctl status php7.2-fpm
systemctl start php7.2-fpm
systemctl status php7.2-fpm
# systemctl enable php7.2-fpm
# apache martxan badakozun amata
/etc/init.d/apache2 stop
apt-get install nginx

nano /etc/nginx/nginx.conf

user zital zital;

nano /etc/nginx/sites-available/default

# eskerrak @urtzai
upstream php_upstream {
    server     unix:/run/php-fpm/php7.2-fpm.sock;
}

server {
        listen 80;
        listen [::]:80;
        server_name localhost;

        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Content-Type-Options "nosniff";

        root /home/project/public;
        index index.php;

        charset utf-8;

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }

        access_log /var/log/nginx/project-access.log;
        error_log  /var/log/nginx/project-error.log;

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass php_upstream;
            include fastcgi_params;
        }

        location ~ /\.(?!well-known).* {
            deny all;
        }
}
@ZiTAL
Copy link
Author

ZiTAL commented Jan 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment