centos6.8部署php的方法:1、安裝依賴套件;2、下載php;3、修改php.ini設定檔;4、設定環境變數;5、設定apache;6、新增擴充並測試即可。
本文操作環境:centos6.8系統、php7.0、Dell G3。
centos6.8 怎麼部署php?
centos6.8原始碼安裝php7.0
yum -y install gd gd-devel zlib-devel libjpeg-devel libiconv-devel libxml2 libxml2-devel <br> curl-devel mhash mcrypt libxslt-devel <br> curl-devel mhash mcrypt libxslt-devel
librypt- devel libjpeg-devel libpng-devel
安裝時遇到No package libmcrypt available的情況
若libiconv安裝失敗,可下載原始碼,使用原始碼安裝
#下載位址:http:// cn2.php.net/distributions/php-7.0.1.tar.gz #tar -zxvf php-7.0.1.tar.gz
#cd php-7.0.1
<br>./configure \ <br> --prefix=/usr/local/php7 \ <br> --exec-prefix=/usr/local/php7 \ <br> --bindir= /usr/local/php7/bin \ <br> --sbindir=/usr/local/php7/sbin \ <br> --includedir=/usr/local/php7/include \ <br> --libdir=/usr /local/php7/lib/php \ <br> --mandir=/usr/local/php7/php/man \ <br> --with-config-file-path=/usr/local/php7/etc \ <br> --with-mcrypt=/usr/include \ <br> --with-mhash \ <br> --with-openssl \ <br> --with-mysqli=shared,mysqlnd \ <br> --with -pdo-mysql=shared,mysqlnd \ <br> --with-gd \ <br> --with-iconv \ <br> --with-zlib \ <br> --enable-zip \ <br> -- enable-inline-optimization \ <br> --disable-debug \ <br> --disable-rpath \ <br> --enable-shared \ <br> --enable-xml \ <br> --enable-bcmath \ <br> --enable-shmop \ <br> --enable-sysvsem \ <br> --enable-mbregex \ <br> --enable-mbstring \ <br> --enable-ftp \ <br> - -enable-gd-native-ttf \ <br> --enable-pcntl \ <br> --enable-sockets \ <br> --with-xmlrpc \ <br> --enable-soap \ <br> -- without-pear \ <br> --with-gettext \ <br> --enable-session \ <br> --with-curl \ <br> --with-jpeg-dir \ <br> --with-freetype -dir \ <br> --enable-opcache \ <br> --enable-fpm \ <br> --without-gdbm \ <br> --disable-fileinfo
--with-apxs2="/usr /local/apache2/bin/apxs
make
make install
#cp /root/php-7.0.15/php.ini-development /usr/local/php7/lib/php.ini
cp -R /root/php-7.0 .15/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /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
mkdir /usr/local/php7/tmp
chmod 766 /usr/local/php7/tmp
<br>extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-zts-20151012/"
session.save_path = "/usr/local/php7/tmp"
echo 'export PATH=/usr/local/php7/bin: /usr/local/php7/sbin:$PATH' >> /etc/profile
讓生效
source /etc/profile
<br>#chkconfig --add php-fpm
chkconfig php-fpm on
##chmod 755 /etc/init.d/ php-fpm <br> service php-fpm start
安裝php後,需要設定apache使其能夠支援php。
在apache的設定檔中加入下邊的設定:AddType application/x-httpd-php .php
這是能讓apache呼叫php模組解析php檔案
在
< IfModule dir_module>
DirectoryIndex index.html
< /IfModule>
中的index.html前加index.php
<br><br>
下載pdo_mysql擴充的壓縮套件http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
tar -xzvf PDO_MYSQL-1.0. 2.tgz
cd /root/php-7.0.15/ext/pdo_mysql
/usr/local/php7/bin/phpize
./configure --with-php-config=/#usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
為mysql的頭檔做一個軟鏈接,因為mysql安裝時指定了安裝目錄,不做鏈接,找不到頭檔ln -s /usr/local/mysql/include/ /usr/local/include/
make
make install
在設定檔中新增: extension_dir = /usr/local/php7/lib/php/extensions/no-debug-zts-20151012/ <br> extension=pdo_mysql.so
#然後重新啟動php-fpm 和apache
測試,發現仍然無效。
透過phpinfo()函數發現
Loaded Configuration File 為none
#然後cp /usr/local/php7/lib/php.ini /usr/local/php7/etc/
重新測試成功
推薦學習:《PHP影片教學》
#以上是centos6.8 怎麼部署php的詳細內容。更多資訊請關注PHP中文網其他相關文章!