1. 程式人生 > >LNMP結構搭建論壇之配置php

LNMP結構搭建論壇之配置php

  1. 使用原始碼包的方式編譯安裝PHP語言環境其實並不複雜,難點在於解決PHP的程式包和其他軟體的依賴關係。為此需要先安裝部署將近十個用於搭建網站頁面的軟體程式包,然後才能正式安裝PHP程式。 yasm原始碼包是一款常見的開源彙編器 cd …

tar zxvf yasm-1.2.0.tar.gz

cd yasm-1.2.0

./configure

make

make install

libmcrypt原始碼包是用於加密演算法的擴充套件庫程式 cd …

tar zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure

make

make install 2.libvpx原始碼包是用於提供視訊編碼器的服務程式,libvpx-v1.3.0.tar.bz2,則此處解壓方式為:tar xjvf cd …

tar xjvf libvpx-v1.3.0.tar.bz2

cd libvpx-v1.3.0

./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9

make

make install 3.tiff原始碼包是用於提供標籤影象檔案格式的服務程式 cd …

tar zxvf tiff-4.0.3.tar.gz

cd tiff-4.0.3

./configure --prefix=/usr/local/tiff --enable-shared

make

make install 4.libpng原始碼包是用於提供png圖片格式支援函式庫的服務程式 cd …

tar zxvf libpng-1.6.12.tar.gz

cd libpng-1.6.12

./configure --prefix=/usr/local/libpng --enable-shared

make

make install 5.freetype原始碼包是用於提供字型支援引擎的服務程式 cd …

tar zxvf freetype-2.5.3.tar.gz

cd freetype-2.5.3

./configure --prefix=/usr/local/freetype --enable-shared

make

make install 6.jpeg原始碼包是用於提供jpeg圖片格式支援函式庫的服務程式 cd …

tar zxvf jpegsrc.v9a.tar.gz

cd jpeg-9a

./configure --prefix=/usr/local/jpeg --enable-shared

make

make install

7.libgd原始碼包是用於提供圖形處理的服務程式,在編譯libgd原始碼包時,請記得寫入的是jpeg、libpng、freetype、tiff、libvpx等服務程式在系統中的安裝路徑,即在上面安裝過程中使用–prefix引數指定的目錄路徑: cd …

tar zxvf libgd-2.1.0.tar.gz

cd libgd-2.1.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-vpx=/usr/local/libvpx

make

make install 8.t1lib原始碼包是用於提供圖片生成函式庫的服務程式,安裝後把/usr/lib64目錄中的函式檔案連結到/usr/lib目錄中,以便系統能夠順利調取到函式檔案: cd …

tar zxvf t1lib-5.1.2.tar.gz

cd t1lib-5.1.2

./configure --prefix=/usr/local/t1lib --enable-shared

make

make install

ln -s /usr/lib64/libltdl.so /usr/lib/libltdl.so

cp -frp /usr/lib64/libXpm.so* /usr/lib/ 9.啟動php服務程式 cd … tar -zvxf php-5.5.14.tar.gz cd php-5.5.14 export LD_LIBRARY_PATH=/usr/local/libgd/lib

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-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-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --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

make

make install 10.在php原始碼包程式安裝完成後,需要刪除當前預設的配置檔案,然後將php服務程式目錄中相應的配置檔案複製過來: rm -rf /etc/php.ini

ln -s /usr/local/php/etc/php.ini /etc/php.ini

cp php.ini-production /usr/local/php/etc/php.ini

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf 11.php-fpm.conf是php服務程式重要的配置檔案之一,我們需要啟用該配置檔案中第25行左右的pid檔案儲存目錄,然後分別將第148和149行的user與group引數分別修改為www賬戶和使用者組名稱: vim /usr/local/php/etc/php-fpm.conf

25 pid = run/php-fpm.pid

148 user = www 149 group = www 12.配置妥當後便可把用於管理php服務的指令碼檔案複製到/etc/rc.d/init.d中了。為了能夠執行指令碼,請記得為指令碼賦予755許可權。最後把php-fpm服務程式加入到開機啟動項中: cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

chmod 755 /etc/rc.d/init.d/php-fpm

chkconfig php-fpm on 13.由於php服務程式的配置引數直接會影響到Web服務服務的執行環境,因此,如果預設開啟了一些不必要且高危的功能(如允許使用者在網頁中執行Linux命令),則會降低網站被入侵的難度,入侵人員甚至可以拿到整臺Web伺服器的管理許可權。因此我們需要編輯php.ini配置檔案,在305行的disable_functions引數後面追加上要禁止的功能。 vim /usr/local/php/etc/php.ini

305 disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restor e,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,g etservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,po six_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 14.編輯Nginx服務程式的主配置檔案,把第2行的井號(#)刪除,然後在後面寫上負責執行Nginx服務程式的賬戶名稱和使用者組名稱;在第45行的index引數後面寫上網站的首頁名稱。最後是將第65~71行引數前的井號(#)刪除來啟用引數,主要是修改第69行的指令碼名稱路徑引數,其中$document_root變數即為網站資訊儲存的根目錄路徑,若沒有設定該變數,則Nginx服務程式無法找到網站資訊,因此會提示“404頁面未找到”的報錯資訊。在確認引數資訊填寫正確後便可重啟Nginx服務與php-fpm服務。 vim /usr/local/nginx/conf/nginx.conf

2 user www www;

45 index index.html index.htm index.php;

65 location ~ .php$ { 66 root html; 67 fastcgi_pass 127.0.0.1:9000; 68 fastcgi_index index.php; 69 fastcgi_param SCRIPT_FILENAME documentrootdocument_rootfastcgi_script_name; 70 include fastcgi_params; 71 }

systemctl restart nginx

systemctl restart php-fpm 15.搭建Discuz論壇 cd /usr/local/src/

unzip Discuz_X3.2_SC_GBK.zip

rm -rf /usr/local/nginx/html/{index.html,50x.html}*

mv upload/* /usr/local/nginx/html/

chown -Rf www:www /usr/local/nginx/html

chmod -Rf 755 /usr/local/nginx/html