Docker環境下編譯安裝PHP7.1.4 Nginx1.12.0
基礎準備
yum provides ifconfig yum install -y net-tools vim wget unzip
工具安裝(gcc-c++在編譯libmcrypt時用到)
yum install -y make gcc gcc-c++ autoconf cmake libxml2-devel openssl-devel bzip2-devel libcurl-devel libpng-devel libjpeg-turbo-devel libwebp-devel libXpm-devel freetype-devel gmp-devel unixODBC-devel readline-devel net-snmp-devel expat-devel libxslt-devel
ln -s /usr/lib64/libexpat.* /usr/lib/ mkdir -p /data/softcd /data/soft wget -c tar zxvf php-7.1.4.tar.gzcd /data/soft wget -c -O tidy-html5.zip unzip tidy-html5.zip -d tidy-html5cd tidy-html5/tidy-html5-master/cd build/cmake/ cmake ../.. make make installcd ../../../../ 如果要編譯到PHP裡,還要cd 到PHP的目錄程式碼把ext/tidy/*.c的程式碼裡的 "buffio.h" 轉成 "tidybuffio.h"cd /data/soft/php-7.1.4/ sed -i 's/buffio.h/tidybuffio.h/' ext/tidy/*.c
centos源不能安裝libmcrypt-devel,由於版權的原因沒有自帶mcrypt的包
wget -c -O ./libmcrypt-2.5.8.tar.gz 編譯 tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8/ ./configure make make install /sbin/ldconfig cd libltdl/ ./configure --enable-ltdl-install make make install cd ../../
正式編譯
php -i |grep ini 編譯的php.ini的預設位置是指定目錄下的 cd php-7.1.4./configure --sysconfdir=/etc --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-bcmath --enable-calendar --enable-exif --enable-ftp --enable-mbstring --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-wddx --with-libexpat-dir --enable-zip --with-bz2 --with-curl --with-zlib --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-webp-dir --with-xpm-dir --with-freetype-dir --with-gettext --with-gmp --with-mcrypt --with-mhash --with-unixODBC=/usr --with-pdo-odbc=unixODBC,/usr --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-readline --with-snmp --with-tidy --with-xmlrpc --with-xsl --with-freetype-dir --enable-opcache
pthreads (需要執行緒安全支援)
要使用 pthreads 擴充套件,需要構建 PHP 時啟用 ZTS (Zend Thread Safety)。(--enable-maintainer-zts 選項, Windows 平臺為 --enable-zts)
編譯安裝
make make install Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20160303/ Installing PHP CLI binary: /usr/local/bin/ Installing PHP CLI man page: /usr/local/php/man/man1/ Installing PHP FPM binary: /usr/local/sbin/ Installing PHP FPM defconfig: /etc/ Installing PHP FPM man page: /usr/local/php/man/man8/ Installing PHP FPM status page: /usr/local/php/php/fpm/ Installing phpdbg binary: /usr/local/bin/ Installing phpdbg man page: /usr/local/php/man/man1/ Installing PHP CGI binary: /usr/local/bin/ Installing PHP CGI man page: /usr/local/php/man/man1/ Installing build environment: /usr/local/lib/php/build/ Installing header files: /usr/local/include/php/ Installing helper programs: /usr/local/bin/ program: phpize program: php-config Installing man pages: /usr/local/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/lib/php/ [PEAR] Archive_Tar - already installed: 1.4.2 [PEAR] Console_Getopt - already installed: 1.4.1 [PEAR] Structures_Graph- already installed: 1.1.1 [PEAR] XML_Util - already installed: 1.4.2 [PEAR] PEAR - already installed: 1.10.3 Wrote PEAR system config file at: /etc/pear.conf You may want to add: /usr/local/lib/php to your php.ini include_path /data/soft/php-7.1.4/build/shtool install -c ext/phar/phar.phar /usr/local/bin ln -s -f phar.phar /usr/local/bin/phar Installing PDO headers: /usr/local/include/php/ext/pdo/
需要pecl安裝的擴充套件
有較多php7擴充套件memcache memcached redis igbinary imagick xhprof
memcache 有github包
cd /data/soft wget -c -O pecl-memcache.zipunzip pecl-memcache.zip cd pecl-memcache-NON_BLOCKING_IO_php7//data/server/php7/bin/phpize ./configure --with-php-config=/data/server/php7/bin/php-config make make install cd ../
memcached 原生支援
wget -c tar zxvf libmemcached-1.0.18.tar.gzcd libmemcached-1.0.18 ./configure make make installcd ../ wget -c tar zxvf memcached-3.0.3.tgzcd memcached-3.0.3 phpize ./configure --with-php-config=php-config --disable-memcached-sasl make make installcd ../
redis 原生支援
wget -c tar zxvf redis-3.1.2.tgz cd redis-3.1.2 phpize ./configure --with-php-config=php-config make make installcd ../
igbinary 原生支援
wget -c tar zxvf igbinary-2.0.1.tgzcd igbinary-2.0.1 phpize ./configure --with-php-config=php-config make make installcd ../
imagick 原生這個也可以用 也有github包
安裝ImageMagick wget -c ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz tar zxvf ImageMagick.tar.gz # 這個名字會變cd ImageMagick-6.9.1-0/ ./configure make make install cd ../ wget -c tar zxvf imagick-3.4.3.tgzcd imagick-3.4.3 phpize ./configure --with-php-config=php-config make make installcd ../
swoole 原生支援
wget -c tar zxvf swoole-1.9.9.tgzcd swoole-1.9.9 phpize ./configure --with-php-config=php-config make make installcd ../
xhprof 原生暫時沒有pecl包, 目前可以用
wget -c -O phpng-xhprof.zip unzip phpng-xhprof.zipcd phpng-xhprof-master phpize ./configure --with-php-config=php-config make make installcd ../
PHP配置
在PHP原始碼目錄下
cd /data/soft/php-7.1.4cp php.ini-production /etc/php.ini cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service cp /etc/php-fpm.conf.default /etc/php-fpm.conf cp /etc/php-fpm.d/ /etc/php-fpm.d/ mkdir -p /etc/php.d vim /etc/php.ini ;expose_php = On expose_php = Off ;short_open_tag = Off short_open_tag = On post_max_size = 30M upload_max_filesize = 30M date.timezone = Asia/Shanghai 編輯完儲存 echo -e "[opcache]nzend_extension=opcache.sonopcache.enable=1nopcache.enable_cli=1" > /etc/php.d/opcache.ini echo "extension=igbinary.so" > /etc/php.d/igbinary.ini echo "extension=imagick.so" > /etc/php.d/imagick.ini echo "extension=memcached.so" > /etc/php.d/memcached.ini echo "extension=memcache.so" > /etc/php.d/memcache.ini echo "extension=redis.so" > /etc/php.d/redis.ini echo "extension=swoole.so" > /etc/php.d/swoole.ini echo "extension=phpng_xhprof.so" > /etc/php.d/phpng_xhprof.ini php -m |grep -E "OPcache|igbinary|imagick|memcache|memcached|redis|xhprof|swoole"php -v看一下 PHP 7.1.4 (cli) (built: Aug 11 2016 02:14:40) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.1.4, Copyright (c) 1999-2016, by Zend Technologies vim /etc/php-fpm.d/ 把php-fpm產生的檔案使用者組改成nginx user = nginx group = nginx 如果小記憶體設定為動態,如果是公司記憶體大,設定static可以在高併發有不錯的表現 pm = static pm.max_children = 128 (記憶體量/30) 4G 64/128 8G 128/256; listen = 127.0.0.1:9000listen = /var/run/php-fpm.sock ; 如果用上面這個 nginx要如下配置 ; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; ;request_slowlog_timeout = 0;request_slowlog_timeout = 1s ;slowlog = /var/log/php-fpm/www-slow.log ;connect() to unix:/data/server/php7/var/run/php-fpm.sock failed (13: Permission denied) 開啟下面幾行 listen.owner = nginx listen.group = nginx listen.mode = 0660
systemctl enable php-fpm
systemctl start php-fpm
php -m 如下擴充套件
[PHP Modules]bcmathbz2calendarCorectypecurldatedomexiffileinfofilterftpgdgettextgmphashiconvigbinaryimagickjsonlibxmlmbstringmcryptmemcachememcachedmysqlimysqlndodbcopensslpcntlpcrePDOpdo_mysqlPDO_ODBCpdo_sqlitePharposixreadlineredisReflectionsessionshmopSimpleXMLsnmpsoapsocketsSPLsqlite3standardswoolesysvmsgsysvsemsysvshmtidytokenizerwddxxhprofxmlxmlreaderxmlrpcxmlwriterxslZend OPcachezipzlib[Zend Modules]Zend OPcache
安裝 Nginx
cd /data/soft 新建 nginx 使用者 /usr/sbin/groupadd nginx /usr/sbin/useradd -g nginx nginx ## 隨便安裝一下 wget -c zxvf nginx-1.12.0.tar.gz cd nginx-1.12.0mkdir -p /var/cache/nginx ### 偽裝NGINX vim src/core/nginx.h #define NGINX_VERSION "1.10.1" #define NGINX_VER "nginx/" NGINX_VERSION 修改成 #define NGINX_VERSION "1.0" #define NGINX_NAME "BServer" #define NGINX_VER NGINX_NAME "/" NGINX_VERSIONvim src/http/ngx_http_header_filter_module.c static char ngx_http_server_string[] = "Server: nginx" CRLF; 修改成 static char ngx_http_server_string[] = "Server: " NGINX_NAME CRLF; vim src/http/ngx_http_special_response.c "<hr><center>nginx</center>" CRLF 修改成 "<hr><center>" NGINX_NAME "</center>" CRLF 安裝需要的工具及類庫 yum install -y gcc pcre-devel openssl-devel zlib-devel ## 預設安裝 ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module make make install Configuration summary + using threads + using system PCRE library + using system OpenSSL library + using system zlib library nginx path prefix: "/etc/nginx" nginx binary file: "/usr/sbin/nginx" nginx modules path: "/etc/nginx/modules" nginx configuration prefix: "/etc/nginx" nginx configuration file: "/etc/nginx/nginx.conf" nginx pid file: "/var/run/nginx.pid" nginx error log file: "/var/log/nginx/error.log" nginx http access log file: "/var/log/nginx/access.log" nginx http client request body temporary files: "/var/cache/nginx/client_temp" nginx http proxy temporary files: "/var/cache/nginx/proxy_temp" nginx http fastcgi temporary files: "/var/cache/nginx/fastcgi_temp" nginx http uwsgi temporary files: "/var/cache/nginx/uwsgi_temp" nginx http scgi temporary files: "/var/cache/nginx/scgi_temp"
配置自啟動
vim /usr/lib/systemd/system/nginx.service [Unit] Description=nginx - high performance web server Documentation= remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true[Install] WantedBy=multi-user.target systemctl enable nginx systemctl start nginx
配置伺服器
mkdir -p /etc/nginx/conf.d/ vim /etc/nginx/nginx.conf#user nobody;user nginx; worker_processes 1; # 看看是幾核,設定為幾error_log /data/server/nginx/var/log/nginx/error.log warn; pid /data/server/nginx/var/run/nginx.pid; 把 http { server_tokens off; 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 /var/log/nginx/access.log main; gzip on; gzip_min_length 1k; gzip_buffers 16 64k; gzip_http_version 1.1; gzip_comp_level 6; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; client_max_body_size 30M; include /etc/nginx/conf.d/*.conf; } mkdir -p /var/www vim /etc/nginx/conf.d/apps.conf server { listen 80; server_name localhost; #charset utf-8; root /var/www; index index.php index.html index.htm; location / { if (!-f $request_filename) { rewrite ^/(.+)$ /index.php?$1& last; } } location ~ .php$ { # fastcgi_pass 127.0.0.1:9000; fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
安裝 mysql5.7
wget -c yum localinstall mysql57-community-release-el7-11.noarch.rpm yum install -y mysql-community-server systemctl enable mysqld systemctl start mysqld 檢視臨時密碼 grep 'temporary password' /var/log/mysqld.log mysql -uroot -pset password = password('Mark*123456') alter user 'root'@'localhost' password expire never; flush privileges;exitmysql -uroot -pMark*123456 grant all privileges on *.* to apps@'%' identified by 'Mark*123456'; alter user 'apps'@'%' password expire never; flush privileges;
安裝 memcached
yum install -y memcached systemctl enable memcached systemctl start memcached systemctl stop memcached
安裝 redis
yum install -y epel-release yum install -y redis systemctl enable redis systemctl start redis systemctl stop redis
作者:波哥教你學
連結:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/810/viewspace-2821484/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Linux 環境下編譯安裝 RedisLinux編譯Redis
- docker環境下安裝tensorflowDocker
- Debian9(Stretch) 下編譯安裝LNMP環境編譯LNMP
- Debian9 (Stretch) 下編譯安裝 LNMP 環境編譯LNMP
- Docker 下安裝配置 lnmp 環境DockerLNMP
- CPP編譯器安裝(Windows環境)編譯Windows
- CentOS 7.4 環境下原始碼編譯安裝 postgreSQL 11.4CentOS原始碼編譯SQL
- PHP編譯configure時常見錯誤,和PHP7.1.4 編譯安裝PHP編譯
- Linux 下使用 Docker 安裝lnmp環境LinuxDockerLNMP
- Linux環境PostGIS原始碼編譯安裝Linux原始碼編譯
- (轉)Windows下安裝Docker, GitBash環境配置WindowsDockerGit
- Linux環境下透過docker安裝mysqlLinuxDockerMySql
- CentOS 7.4 環境下原始碼編譯(多例項)安裝 Mysql 5.7.26CentOS原始碼編譯MySql
- centos7環境下二進位制編譯安裝ffmpegCentOS編譯
- Linux 開發環境 -- C/C++開發環境編譯安裝Linux開發環境C++編譯
- Linux環境下, 原始碼編譯安裝詳解 (編譯CMake 3.15 和 gcc 5.3.0 為例)Linux原始碼編譯GC
- php環境篇:linux編譯安裝nginx1.13.2PHPLinux編譯Nginx
- JDK20安裝+環境配置+編譯執行JDK編譯
- [環境搭建] 透過原始碼編譯安裝 Redis原始碼編譯Redis
- 1.8LNMP環境編譯安裝php-5.6.14LNMP編譯PHP
- Ubuntu 22.04 安裝Docker環境UbuntuDocker
- docker安裝多環境ApolloDocker
- Windows 環境下 Python 環境安裝WindowsPython
- VLC在ubuntu環境下編譯編譯
- win10環境下fortran怎麼編譯_win10環境下fortran如何編譯Win10編譯
- WIN10x64系統安裝AliOSThings編譯環境Win10iOS編譯
- Docker環境編譯時的錯誤記錄Docker編譯
- 常用環境部署—Docker安裝RocketMQ教程!DockerMQ
- ros2 jazzy docker環境安裝ROSDocker
- 無網環境安裝docker之--rpmDocker
- Linux下安裝Go環境LinuxGo
- linux環境下redis安裝LinuxRedis
- Windows環境下安裝LinuxWindowsLinux
- Windows環境下安裝NexusWindows
- Windows 環境下安裝 RedisWindowsRedis
- Windows 環境下安裝 LaravelWindowsLaravel
- Mac環境下安裝PodMac
- Linux下Java環境安裝LinuxJava