Centos安裝PHP7及配置php-fpm開機啟動
centos 7 編譯安裝 php-7.2.11的步驟
在官網下載php-7.2.11的php壓縮包,centos 7 安裝 php-7.2.11的步驟,http://cn2.php.net/distributions/php-7.2.11.tar.gz
cd /usr/local/srcwget -c http://cn2.php.net/distributions/php-7.2.11.tar.gz
下載好後解壓 php-7.2.11.tar.gz 壓縮包,並進入解壓後的目錄
tar -xzvf php-7.2.11.tar.gzcd php-7.2.11
安裝php7需要的一些依賴庫包 libxml2和一些其他依賴的擴充套件庫
yum -y install libxml2 yum -y install libxml2-devel yum -y install openssl yum -y install openssl-devel yum -y install curl-devel yum -y install libjpeg-devel yum -y install libpng-devel yum -y install freetype-develyum -y install bzip2-develyum -y install libmcrypt libmcrypt-develyum -y install postgresql-develyum -y install aspell-develyum -y install readline-develyum -y install libxslt-develyum -y install net-snmp-develyum -y install unixODBC-develyum -y install libicu-develyum -y install libc-client-develyum -y install libXpm-develyum -y install libvpx-develyum -y install enchant-develyum -y install openldapyum -y install openldap-develyum -y install db4-develyum -y install gmp-develyum -y install sqlite-develyum -y install mysql-devel
yum install oniguruma-devel -y
安裝前的環境配置檢查,php7的一些依賴包的檢查和php擴充套件的啟動,這個過程如果缺少php依賴的庫包會有報錯提示。
新增使用者和組: (此處使用者和組為 nginx, 我 nginx 用的使用者名稱 ) groupadd -r nginx && useradd -r -g nginx -s /sbin/nologin
php 安裝配置
請根據以下 A B C 選擇合適的一項進行安裝配置
A. PHP 7.2.10 單選模式
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-xmlrpc --with-openssl --with-mcrypt --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache
B. PHP 7.2.10 多行模式
./configure \--prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--enable-fpm \ --with-fpm-user=nginx \--with-fpm-group=nginx \ --enable-inline-optimization \--disable-debug \--disable-rpath \--enable-shared \--enable-soap \--with-xmlrpc \--with-openssl \--with-mcrypt \--with-pcre-regex \--with-sqlite3 \--with-zlib \--enable-bcmath \--with-iconv \--with-bz2 \--enable-calendar \--with-curl \--with-cdb \--enable-dom \--enable-exif \--enable-fileinfo \--enable-filter \--with-pcre-dir \--enable-ftp \--with-gd \--with-openssl-dir \--with-jpeg-dir \--with-png-dir \--with-freetype-dir \--enable-gd-native-ttf \--enable-gd-jis-conv \--with-gettext \--with-gmp \--with-mhash \--enable-json \--enable-mbstring \--enable-mbregex \--enable-mbregex-backtrack \--with-libmbfl \--with-onig \--enable-pdo \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \--with-zlib-dir \--with-pdo-sqlite \--with-readline \--enable-session \--enable-shmop \--enable-simplexml \--enable-sockets \--enable-sysvmsg \--enable-sysvsem \--enable-sysvshm \--enable-wddx \--with-libxml-dir \--with-xsl \--enable-zip \--enable-mysqlnd-compression-support \--with-pear \--enable-opcache
C. PHP 7.4.10
./configure \--prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--enable-fpm \--with-fpm-user=nginx \--with-fpm-group=nginx \--enable-inline-optimization \--disable-debug \--disable-rpath \--enable-shared \--enable-soap \--with-xmlrpc \--with-openssl \--with-mcrypt \--with-pcre-regex \--with-sqlite3 \--with-zlib \--enable-bcmath \--with-iconv \--with-kerberos \--with-libdir=lib64 \--with-bz2 \--enable-calendar \--with-curl \--with-cdb \--enable-dom \--enable-exif \--enable-fileinfo \--enable-filter \--with-pcre-dir \--enable-ftp \--enable-gd \--with-openssl-dir \--with-jpeg-dir \--with-png-dir \--with-freetype-dir \--enable-gd-native-ttf \--enable-gd-jis-conv \--with-gettext \--with-gmp \--with-mhash \--enable-json \--enable-mbstring \--enable-mbregex \--enable-mbregex-backtrack \--with-libmbfl \--with-onig \--enable-pdo \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \--with-zlib-dir \--with-pdo-sqlite \--with-readline \--enable-session \--enable-shmop \--enable-simplexml \--enable-sockets \--enable-sysvmsg \--enable-sysvsem \--enable-sysvshm \--enable-wddx \--with-libxml-dir \--with-xsl \--with-zip \--enable-xml \--enable-mysqlnd-compression-support \--with-pear \--enable-opcache \--enable-pcntl
從 PHP 7.4.0 開始,必須在編譯 PHP 時用 --with-zip 配置選項來提供 zip 支援。之前的 PHP 版本,需要使用 --enable-zip 選項。
對php7進行編譯和安裝的操作
make && make install
( 如果出現 make: *** [sapi/cli/php] Error 1 的錯誤,通過繼續執行 make ZEND_EXTRA_LIBS='-liconv' 命令解決
編譯成功,檢視php版本
/usr/local/php/bin/php -v
執行php-fpm
/usr/local/php/sbin/php-fpm
啟動php-fpm可能會遇到的錯誤,基本都是配置檔案配置和重新命名的問題:
錯誤一:缺少www.conf配置檔案(WARNING: Nothing matches the include pattern /usr/local/php/etc/php-fpm.d/*.conf),需要把/usr/local/php/etc/php-fpm.d/*.conf目錄中的www.conf.default重新命名為www.conf。
錯誤二:缺少php-fpm.conf配置檔案 需要在/usr/local/php/etc/php-fpm.conf 把預設的配置檔案php-fpm.conf.default改成php-fpm.conf
錯誤三:缺少php.ini配置檔案 php7編譯安裝好後會發現沒有php.ini配置檔案,需要在解壓包的根目錄中複製php.ini-production或php.ini-development並重新命名為php.ini到php編譯好的安裝目錄中的/usr/local/php/etc資料夾即可。
其它錯誤的解決:
error: Package requirements (sqlite3 > 3.7.4) were not metyum install libsqlite3x-devel -yerror: Package requirements (oniguruma) were not met
yum install oniguruma-devel -y當yum install 提示 "沒可用軟體包"
yum install -y epel-releaseoff_t undefined 報錯
configure: error: off_t undefined; check your library configuration
configure: WARNING: unrecognized options: --with-mcrypt, --enable-gd-native-ttf
php7.2以後不支援–with-mcrypt, --enable-gd-native-ttf 這兩個引數,需要去掉
在centos7中編譯安裝好php後,系統重啟後並不會對php進行開機啟動,所以需要對centos7新增開機啟動指令碼對php進行開機啟動服務。
php7編譯安裝方法:http://zixuephp.net/article-207.html
手動啟動:
-
/usr/local/php/sbin/php-fpm
開機自動啟動:
開啟配置php-fpm pid
-
#找到php-fpm.conf配置檔案
-
/usr/local/php/etc/php-fpm.conf
-
#開啟pid ,去掉分號註釋
-
pid = run/php-fpm.pid
安裝後要進行的操作:
1. 把安裝目錄下的 php.ini-development 複製到 /etc/ 目錄下2. 修改 /usr/local/php/etc/php-fpm.conf.default 名為 php-fpm.conf 並進入修改3. 修改 /usr/local/php/etc/php-fpm.d/www.conf.default 為 www.conf 並進入修改
PHP 7.4.10 安裝 ZIP
1 擴充套件包 wget https://pecl.php.net/get/zip-1.19.0.tgz 2 解壓 並進入 tar -zxvf zip-1.19.0.tgz 2.2 cd zip-1.19.03 /usr/local/php/bin/phpize 4 ./configure --with-php-config=/usr/local/php/bin/php-config 自己的php目錄5 make && make install---------------------然後下載最新的,解壓wget https://libzip.org/download/libzip-1.5.2.tar.gztar -zxvf libzip-1.5.2.tar.gz這時發現還要安裝cmake,再去下載cmake:wget https://github.com/Kitware/CMake/releases/download/v3.15.4/cmake-3.15.4.tar.gz解壓:tar -zxvf cmake-3.15.4.tar.gz注意:cmake要按照文件安裝./bootstrap && make && sudo make install漫長的等待,安裝完成後,執行cmake -version出現版本號即表示cmake安裝成功。接下來, 再進入 cd libzip-1.5.2mkdir build && cd build/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/libzip ..makemake install//檢測libzip是否安裝成功whereis libzip libzip: /usr/local/libzip
建立開機啟動指令碼
在Linux中將php-fpm配置成服務的方法
PHP 原始檔路徑: /usr/local/src/php-7.2.11/
PHP 安裝後路徑: /usr/local/php/
1. 配置 php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
php-fpm.pid 目錄必須指向:/usr/local/php/var/run/php-fpm.pid
2. 拷貝php-fpm指令碼至/etc/init.d目錄
cp /usr/local/src/php-7.2.11/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#! /bin/sh### BEGIN INIT INFO# Provides: php-fpm# Required-Start: $remote_fs $network# Required-Stop: $remote_fs $network# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: starts php-fpm# Description: starts the PHP FastCGI Process Manager daemon### END INIT INFOprefix=/usr/local/phpexec_prefix=${prefix}php_fpm_BIN=${exec_prefix}/sbin/php-fpmphp_fpm_CONF=${prefix}/etc/php-fpm.confphp_fpm_PID=${prefix}/var/run/php-fpm.pidphp_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"wait_for_pid () { try=0 while test $try -lt 35 ; do case "$1" in 'created') if [ -f "$2" ] ; then try='' break fi ;; 'removed') if [ ! -f "$2" ] ; then try='' break fi ;; esac echo -n . try=`expr $try + 1` sleep 1 done}case "$1" in start) echo -n "Starting php-fpm " $php_fpm_BIN --daemonize $php_opts if [ "$?" != 0 ] ; then echo " failed" exit 1 fi wait_for_pid created $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit 1 else echo " done" fi ;; stop) echo -n "Gracefully shutting down php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -QUIT `cat $php_fpm_PID` wait_for_pid removed $php_fpm_PID if [ -n "$try" ] ; then echo " failed. Use force-quit" exit 1 else echo " done" fi ;; status) if [ ! -r $php_fpm_PID ] ; then echo "php-fpm is stopped" exit 0 fi PID=`cat $php_fpm_PID` if ps -p $PID | grep -q $PID; then echo "php-fpm (pid $PID) is running..." else echo "php-fpm dead but pid file exists" fi ;; force-quit) echo -n "Terminating php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -TERM `cat $php_fpm_PID` wait_for_pid removed $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit 1 else echo " done" fi ;; restart) $0 stop $0 start ;; reload) echo -n "Reload service php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -USR2 `cat $php_fpm_PID` echo " done" ;; configtest) $php_fpm_BIN -t ;; *) echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}" exit 1 ;;esac
3.設定許可權並啟動php-fpm:
chmod 755 /etc/init.d/php-fpm
/etc/init.d/php-fpm start
chkconfig –add php-fpm
最後,給出php-fpm以服務的方式啟動、停止和重啟:
service php-fpm start
service php-fpm stop
service php-fpm reload
PHP-FPM 自啟動配置服務:
vim /etc/rc.d/rc.local
檢視開機啟動的所有服務
chkconfig --list
nginx demo 配置:(不要忘記chown www-data:www-data 網站目錄 不然沒許可權)
server { listen 80; server_name {{ server_name }}; access_log /data/logs/nginx/{{ server_name }}/access.log; error_log /data/logs/nginx/{{ server_name }}/error.log;location / {index index.php index.html index.htm;root /data/www/wwwroot/{{ server_name }}/;if (!-e $request_filename) {rewrite ^/(.*)$ /index.php;}}location ~ \.php$ {include fastcgi_params;fastcgi_pass unix:/tmp/php-fcgi.sock;fastcgi_index index.php;}}
php-fpm配置 (重新命名兩個檔案 其他看實際情況配置(略。。。))
www.conf.default -> www.conf
php-fpm.conf.default -> php-fpm.conf
啟動: php-fpm -D
nginx -s reload
相關文章
- CentOS7.4安裝php配置php-fpm服務CentOSPHP
- Supervisor安裝、配置、開啟啟動
- php-fpm啟動引數及重要配置詳解PHP
- CentOS 7 安裝、配置、使用 PostgreSQL 10 安裝及基礎配置CentOSSQL
- Centos 7.1安裝後修改主機名及網路配置CentOS
- centos7原始碼安裝php7CentOS原始碼PHP
- CentOS 6 安裝MAVEN及系統配置CentOSMaven
- Centos安裝tomcat9及配置CentOSTomcat
- CentOS 7 - 配置服務實現開機自啟動CentOS
- centos php-fpm nginx配置CentOSPHPNginx
- centos下安裝mysql不能啟動CentOSMySql
- AeroSpike安裝及啟動ROS
- PHP7安裝配置(win10)PHPWin10
- 編譯安裝nginx時配置開機自啟編譯Nginx
- CentOS 安裝 supervisor 及配置 Redis 佇列CentOSRedis佇列
- mac系統,php-fpm加入開機啟動項MacPHP
- CentOS 7 下安裝PHP環境並且配置Nginx支援php-fpm模組CentOSPHPNginx
- php5.6原始碼安裝及php-fpm配置與nginx整合PHP原始碼Nginx
- Kafka 的安裝及啟動Kafka
- nginx安裝及自啟動Nginx
- 技術乾貨實戰(3)- CentOS7 下 Redis6 安裝與配置教程(Redis開機啟動)CentOSRedis
- CentOS redis安裝配置CentOSRedis
- CentOS安裝配置yumCentOS
- RabbitMQ安裝配置(CentOS)MQCentOS
- centos設定Apache開機啟動CentOSApache
- Windows XP安裝CentOS 7.0 後開機沒有XP啟動項解決辦法WindowsCentOS
- mongodb的安裝與啟動(centos7)MongoDBCentOS
- 開啟及配置centos5.4上面的vsftpdCentOSFTP
- xampp安裝步驟及啟動
- Memcached安裝及啟動指令碼指令碼
- centos7上配置MySQL5.7的開機自啟動方法CentOSMySql
- oracle配置開機自啟動Oracle
- centos 服務開機啟動設定CentOS
- Mac 下 Nginx、MySQL、PHP-FPM 的安裝配置MacNginxMySqlPHP
- centos7 hadoop 單機模式安裝配置CentOSHadoop模式
- Centos安裝與配置RedisCentOSRedis
- CentOS下安裝配置cmakeCentOS
- 【redis】centOS安裝配置redisRedisCentOS