Centos7 PHP7 編譯安裝 開機自啟動


1、PHP7.0.13下載

wget http://cn2.php.net/get/php-7.0.13.tar.gz/from/this/mirror

2、解壓 

tar -zxvf php-7.0.13.tar.gz

3、 進入目錄  

cd php-7.0.13

4、下載擴展庫

yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel MySQL pcre-devel
yum -y install curl-devel
yum -y install libxslt-devel

5、編譯安裝

./configure --prefix=/usr/local/php7 \
 --with-curl \
 --with-freetype-dir \
 --with-gd \
--with-jpeg-dir \
--with-gettext \ --with-iconv-dir \ --with-kerberos \ --with-libdir=lib64 \ --with-libxml-dir \ --with-mysqli \ --with-openssl \ --with-pcre-regex \ --with-pdo-mysql \ --with-pdo-sqlite \ --with-pear \ --with-png-dir \ --with-xmlrpc \ --with-xsl \ --with-zlib \ --enable-fpm \ --enable-bcmath \ --enable-libxml \ --enable-inline-optimization \ --enable-gd-native-ttf \ --enable-mbregex \ --enable-mbstring \ --enable-opcache \ --enable-pcntl \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-sysvsem \ --enable-xml \ --enable-zip

 

make &&  make install

6、拷貝配置文件

cp php.ini-production /usr/local/php7/lib/php.ini
vim /usr/local/php7/lib/php.ini
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf

 #把pid 改成 /run/php-fpm.pid

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

 #listen = 127.0.0.1:9000 默認可不改

vim /usr/local/php7/etc/php-fpm.d/www.conf 

 

7、添加服務

vim /etc/systemd/system/php-fpm.service

內容如下

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

[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target

 

8、啟動php-fpm

systemctl start php-fpm.service

9、添加到開機啟動

systemctl enable php-fpm.service
 
10、systemctl指令
systemctl enable *.service #開機運行服務
systemctl disable *.service #取消開機運行
systemctl start *.service #啟動服務
systemctl stop *.service #停止服務
systemctl restart *.service #重啟服務
systemctl reload *.service #重新加載服務配置文件
systemctl status *.service #查詢服務運行狀態
systemctl --failed #顯示啟動失敗的服務



修改 php.ini 文件 設置 expose_php = Off
vim /usr/local/php7/etc/php.ini
找到 expose_php = On
改為 expose_php = Off

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM