1. 程式人生 > >Linux 系統安裝配置PHP服務(源碼安裝)

Linux 系統安裝配置PHP服務(源碼安裝)

net -i alt 處理 sap 技術 title setuid solved

Linux 系統安裝配置PHP服務(源碼安裝)



簡介

PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本預處理器”)是一種通用開源腳本語言。語法吸收了C語言、Java和Perl的特點,利於學習,使用廣泛,主要適用於Web開發領域。


標註:

配置nginx請參考此教程:

http://www.cnblogs.com/zoulongbin/p/6253568.html

配置mysql請參考此教程:

http://www.cnblogs.com/zoulongbin/p/6287167.html

配置網絡yum源參考此教程:

http://www.cnblogs.com/zoulongbin/p/5773330.html

需要安裝以下安裝包:(使用網絡yum源在線安裝以下四個依賴包,本教程大部分使用下載的源碼安裝進行編譯安裝)

[root@ssticentos65 src]# yum -y install libcurl-devel (必須安裝)

[root@ssticentos65 src]# yum -y install libXpm-devel (必須安裝)

若提示安裝失敗,則需要單獨下載包安裝

[root@tmaster zabbix]# yum -y install libXpm-devel
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
file:///mnt/cdrom/Server/repodata/repomd.xml: [Errno 14] Could not open/read file:///mnt/cdrom/Server/repodata/repomd.xml
Trying other mirror.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package libXpm-devel.x86_64 0:3.5.10-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================
Package Arch Version Repository Size
=======================================================================================================
Installing:
libXpm-devel x86_64 3.5.10-2.el6 EL 33 k

Transaction Summary
=======================================================================================================
Install 1 Package(s)

Total download size: 33 k
Installed size: 60 k
Downloading Packages:


Error Downloading Packages:
libXpm-devel-3.5.10-2.el6.x86_64: failure: ../Packages/libXpm-devel-3.5.10-2.el6.x86_64.rpm from EL: [Errno 256] No more mirrors to try


根據操作系統版本下載包

地址:http://www.rpmfind.net/linux/rpm2html/search.php?query=libXpm-devel(x86-64)

[root@ssticentos65 src]# yum -y install libxml2-devel (必須安裝)

[root@ssticentos65 src]# yum -y install php-mbstring (自行選擇安裝)


提示:Linux軟件編譯安裝都需要依賴兩個安裝包 gcc gcc-c++ make 可使用 yum -y install gcc gcc-c++ make 在線安裝。

標註:下載的軟件安裝包統一存放路徑在 /usr/local/src 目錄下進行解壓編譯安裝

1、 安裝yasm

下載地址:http://www.tortall.net/projects/yasm/releases/

[root@ssticentos65 src]# cd yasm-1.3.0

[root@ssticentos65 yasm-1.3.0]# ./configure

[root@ssticentos65 yasm-1.3.0]# make

[root@ssticentos65 yasm-1.3.0]# make install

2、 安裝libmcrypt

下載地址:https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/

[root@ssticentos65 src]# cd libmcrypt-2.5.8

[root@ssticentos65 libmcrypt-2.5.8]# ./configure

[root@ssticentos65 libmcrypt-2.5.8]# make

[root@ssticentos65 libmcrypt-2.5.8]# make install


3、 安裝libvpx

下載地址: http://www.linuxfromscratch.org/blfs/view/svn/multimedia/libvpx.html

[root@ssticentos65 src]# cd libvpx-1.6.0

[root@ssticentos65 libvpx-1.6.0]#./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9

[root@ssticentos65 libvpx-1.6.0]# make

[root@ssticentos65 libvpx-1.6.0]# make install

4、 安裝tiff

下載地址: http://download.osgeo.org/libtiff/

[root@ssticentos65 src]# cd tiff-4.0.6

[root@ssticentos65 tiff-4.0.6]#./configure --prefix=/usr/local/tiff --enable-shared

[root@ssticentos65 tiff-4.0.6]# make

[root@ssticentos65 tiff-4.0.6]# make install

5、 安裝libpng

下載地址:http://www.libpng.org/pub/png/libpng.html

[root@ssticentos65 src]# cd libpng-1.6.28

[root@ssticentos65 libpng-1.6.28]#./configure --prefix=/usr/local/libpng --enable-shared

[root@ssticentos65 libpng-1.6.28]# make

[root@ssticentos65 libpng-1.6.28]# make install

6、 安裝freetype

下載地址:http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/

[root@ssticentos65 src]# cd freetype-2.7.1

[root@ssticentos65 freetype-2.7.1]#./configure --prefix=/usr/local/freetype --enable-shared

[root@ssticentos65 freetype-2.7.1]# make

[root@ssticentos65 freetype-2.7.1]# make install

7、 安裝jpeg

下載地址:http://www.ijg.org/files/

[root@ssticentos65 src]# cd jpeg-9a

[root@ssticentos65 jpeg-9a]#./configure --prefix=/usr/local/jpeg --enable-shared

[root@ssticentos65 jpeg-9a]# make

[root@ssticentos65 jpeg-9a]# make install

8、 安裝libgd

下載地址:https://github.com/libgd/libgd/releases

[root@ssticentos65 src]# cd libgd-2.2.0

[root@ssticentos65 libgd-2.2.0]#./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-webp=/usr/local/libwebp/

[root@ssticentos65 libgd-2.2.0]# make

[root@ssticentos65 libgd-2.2.0]# make install

9、 安裝t1lib

下載地址:http://download.csdn.net/download/sunkaivg/9696064

[root@ssticentos65 src]# cd t1lib-5.1.2

[root@ssticentos65 t1lib-5.1.2]#./configure --prefix=/usr/local/t1lib --enable-shared

[root@ssticentos65 t1lib-5.1.2]# make without_doc

[root@ssticentos65 t1lib-5.1.2]# make install

10、 安裝php

下載地址 :http://www.php.net/downloads.php

[root@ssticentos65 src]# ls

php-5.6.28 php-5.6.28.tar.gz

[root@ssticentos65 src]# pwd

/usr/local/src

[root@ssticentos65 src]# cd php-5.6.28

[root@ssticentos65 php-5.6.28]#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-zlib-dir=/usr/local/zlib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctype

[root@ssticentos65 php-5.6.28]# make

[root@ssticentos65 php-5.6.28]# make install

11、配置PHP

#顯示php安裝包存放路徑

[root@ssticentos65 src]# pwd

/usr/local/src

[root@ssticentos65 src]# ls

php-5.6.28 php-5.6.28.tar.gz

[root@ssticentos65 src]# cd php-5.6.28

#復制php配置文件到安裝目錄

[root@ssticentos65 php-5.6.28]# cp php.ini-production /usr/local/php/etc/php.ini

#刪除系統自帶配置文件

[root@ssticentos65 php-5.6.28]# rm -rf /etc/php.ini

#添加軟鏈接到 /etc目錄

[root@ssticentos65 php-5.6.28]# ln -s /usr/local/php/etc/php.ini /etc/php.ini

[root@ssticentos65 php-5.6.28]# ls -l /etc/php.ini

lrwxrwxrwx 1 root root 26 Jan 6 02:22 /etc/php.ini -> /usr/local/php/etc/php.ini

#復制模板文件為php-fpm配置

[root@ssticentos65 php-5.6.28]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

#添加軟件鏈接到 /etc目錄

[root@ssticentos65 php-5.6.28]#ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf

#編輯php配置文件php-fpm.conf

[root@ssticentos65 php-5.6.28]# vim /usr/local/php/etc/php-fpm.conf

pid = run/php-fpm.pid //如果這個選項在配置文件存在就取消掉註釋使用,如果不存在可以忽略,請勿手動添加,否則PHP啟動會報錯。

user = www

group = www

:wq! #保存並退出

12、設置php-fpm開機自啟動

#復制php-fpm到啟動目錄

[root@ssticentos65 ~]# cp /usr/local/src/php-5.6.28/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@ssticentos65 ~]# ls -l /etc/init.d/php-fpm

-rw-r--r--. 1 root root 2354 Jan 6 02:37 /etc/init.d/php-fpm

#賦予php-fpm執行權限

[root@ssticentos65 ~]# chmod 755 /etc/init.d/php-fpm

[root@ssticentos65 ~]# ls -l /etc/init.d/php-fpm

-rwxr-xr-x. 1 root root 2354 Jan 6 02:37 /etc/init.d/php-fpm

#設置php-fpm開機啟動

[root@ssticentos65 ~]# chkconfig php-fpm on

[root@ssticentos65 ~]# chkconfig --list php-fpm

php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off

#編輯php配置文件php.ini

[root@ssticentos65 ~]# vim /usr/local/php/etc/php.ini

找到:disable_functions =

修改成disable_functions= passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit,posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

找到:date.timezone =

修改為:date.timezone = PRC #設置時區

找到:expose_php = On

修改為:expose_php = Off #禁止顯示php版本的信息

找到:short_open_tag = Off

修改為:short_open_tag = On #支持php短標簽

找到opcache.enable=0

修改為opcache.enable=1 #php支持opcode緩存

找到:opcache.enable_cli=1 #php支持opcode緩存

修改為:opcache.enable_cli=0

在最後一行添加:zend_extension=opcache.so #開啟opcode緩存功能 (在文本按Shift+G就能跳到最後一行)

:wq! #保存並退出


13、配置nginx支持php

檢查www用戶和www用戶組是否存在,不存在請手動創建

[root@ssticentos65 ~]# cat /etc/passwd | grep www

apache:x:48:48:Apache:/var/www:/sbin/nologin

www:x:501:3005::/home/www:/bin/bash

[root@ssticentos65 ~]# cat /etc/group | grep www

www:x:3005:

[root@ssticentos65 ~]# vim /usr/local/nginx/conf/nginx.conf

user www www;

#首行user去掉註釋,修改Nginx運行組為www www;必須與/usr/local/php/etc/php-fpm.d/www.conf中的user,group配置相同,否則php運行出錯

location / {

root html;

index index.html index.htm index.php; #添加index.php

}

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

#取消FastCGI server部分location的註釋,註意fastcgi_param行的參數,改為$document_root$fastcgi_script_name,或者使用絕對路徑

:wq! #保存並退出

#啟動nginx服務

[root@ssticentos65 ~]# /etc/init.d/nginx restart

#啟動php服務

[root@ssticentos65 ~]# /etc/init.d/php-fpm start

14、測試php配置

#進入nginx默認網站根目錄

[root@ssticentos65 ~]# cd /usr/local/nginx/html/

[root@ssticentos65 html]# ls

50x.html index.html

#刪除默認測試頁

[root@ssticentos65 html]# rm -rf /usr/local/nginx/html/*

[root@ssticentos65 html]# pwd

/usr/local/nginx/html

#新建index.php文件進行測試

[root@ssticentos65 html]# vim index.php

<?php

phpinfo();

?>

:wq! #保存並退出

#設置目錄所有者為 www

[root@ssticentos65 html]# chown www.www /usr/local/nginx/html/ -R

#設置目錄權限

[root@ssticentos65 html]# chmod 755 /usr/local/nginx/html/ -R


打開瀏覽器輸入服務器IP地址,會看到下面的界面就是php安裝成功

技術分享圖片


感謝此博客提供參考

http://www.osyunwei.com/archives/7891.html

https://www.cnblogs.com/zoulongbin/p/6379272.html


Linux 系統安裝配置PHP服務(源碼安裝)