PHP相關配置php
1.查找php配置文件/usr/local/php/bin/php -i或者phpinfo()html
[root@bogon admin]# /usr/local/php/bin/php -i|grep -i "loaded configuration file" PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function.
In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now,
but please set date.timezone to select your timezone. in Unknown on line 0 Loaded Configuration File => /usr/local/php/etc/php.ini [root@bogon admin]#
2.若是沒有配置文件須要將源碼包中的php配置文件拷貝進來mysql
cp -r /usr/local/src/php-5.6.30/php.ini-production /usr/local/php/etc/php.ini
3.disable_functions 安全函數(禁止掉這些比較危險的函數)git
在生產環境中會把phpinfo禁掉。由於有時候不當心寫了一個phpinfo文件,上傳上去被黑客發現。可以看到系統的目錄。不安全
eval:一句話木馬使用了該函數若是把這個函數禁了,即便上傳了木馬也沒辦法解析github
[root@bogon 111.com]# vim /usr/local/php/etc/php.ini [root@bogon 111.com]#
4.date.timezone //定義時區web
date.timezone =Asia/shanghai
5.display_errors = On //會把錯誤信息直接顯示在瀏覽器上改爲Off(生產環境該參數改爲Off,爲了不暴露信息)可是有一個問題,就是頁面什麼都不顯示(白頁)。那麼還須要配置錯誤日誌。redis
log_errors = On //表示錯誤日誌打開狀態sql
6.error_log = /tmp/php_errors.log //定義錯誤日誌所在位置apache
7.error_reporting //定義日誌的級別,還須要定義error_log的級別。若是級別很高的話,很嚴謹的話,只會記錄一些比較嚴峻的錯誤,不太嚴峻的就不記錄,好比警告等、因此放鬆些json
生產環境使用
E_ALL & ~E_NOTICE (Show all errors, except for notices)
模擬:把phpinfo函數禁掉。
1.phpinfo放入disable_functions裏
2.display_errors = Off
3.log_errors = On
4.error_log = /tmp/php_errors.log
5./usr/local/apache2.4/bin/apachectl -t && graceful
6.ll /tmp/
7.cat /tmp/php_errors.log
[11-Dec-2017 21:23:49 Asia/shanghai] PHP Warning: phpinfo() has been disabled for security reasons in /data/wwwroot/discuz2/lsx/1.php on line 2
php_errors.log的屬主實際是httpd的屬主daemon。由於這個日誌是以daemon這個進程的身份建立的。當你定義了一個日誌,可是日誌始終沒有生成,就要看一下定義的目錄有沒寫權限,並且寫文件的進程是這個進程。
爲了保守起見,能夠把這個文件建立好/tmp/php_errors.log,在受權777權限
[root@bogon 111.com]# touch /tmp/php_errors.log; chmod 777 /tmp/php_errors.log
[root@bogon 111.com]# grep error_log /usr/local/php/etc/php.ini ; server-specific log, STDERR, or a location specified by the error_log ; Set maximum length of log_errors. In error_log information about the source is ;error_log = php_errors.log ;error_log = syslog ; OPcache error_log file name. Empty string assumes "stderr". ;opcache.error_log= [root@bogon 111.com]#
open_basedir 將php所能打開的文件限制在指定的目錄樹中,包括文件自己。當程序要使用例如fopen()或file_get_contents()打開一個文件時,這個文件的位置將會被檢查。當文件在指定的目錄樹以外,程序將拒絕打開。
1.在php.ini 加入
open_basedir="指定目錄"
2.在程序中使用
ini_set('open_basedir', '指定目錄');
改php.ini有個問題,假若有多個虛擬主機這樣作是不可行的,能夠在虛擬主機配置文件中配置
3.httpd.conf中的VritualHost
php_admin_value open_basedir "指定目錄"
<VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/data/wwwroot/abc.com" ServerName abc.com ServerAlias www.abc.com www.123.com php_admin_value open_basedir "/data/wwwroot/abc.com:/tmp/" ErrorLog "logs/abc.com-error_log" CustomLog "logs/abc.com-access_log" common </VirtualHost>
[root@bogon tmp]# /usr/local/apache2.4/bin/apachectl graceful [root@bogon tmp]# [root@bogon tmp]# !curl curl -x127.0.0.1:80 http://111.com -I HTTP/1.1 200 OK Date: Wed, 07 Feb 2018 06:05:58 GMT Server: Apache/2.4.28 (Unix) PHP/5.6.30 X-Powered-By: PHP/5.6.30 Cache-Control: max-age=0 Expires: Wed, 07 Feb 2018 06:05:58 GMT Content-Type: text/html; charset=UTF-8 [root@bogon tmp]#
http://blog.sina.com.cn/s/blog_3dbab2840100uo5l.html
1.php編譯後想增長模塊怎麼辦,下面娓娓道來,以增長redis模塊爲例
https://codeload.github.com/phpredis/phpredis/zip/develop
2.解壓phpredis包
[root@bogon src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop
[root@bogon src]# mv develop phpredis-develop.zip
[root@bogon src]# unzip phpredis-develop.zip
3.使用phpize命令生成./configure文件,報錯autoconf not find,須要安裝autoconf包
[root@bogon src]# cd phpredis-develop/ [root@bogon phpredis-develop]# /usr/local/php php/ php7/ [root@bogon phpredis-develop]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. [root@bogon phpredis-develop]# yum install -y autoconf
4.再次執行命令成功
[root@bogon phpredis-develop]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 [root@bogon phpredis-develop]#
5.編譯
[root@bogon phpredis-develop]# ./configure --with-php-config=/usr/local/php/bin/php-config
6.make && make install 生成redis.so模塊
[root@bogon phpredis-develop]# make install Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ [root@bogon phpredis-develop]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ opcache.so redis.so [root@bogon phpredis-develop]#
7.查看php支持的所有擴展模塊
[root@bogon phpredis-develop]# /usr/local/php/bin/php -m|grep redis
8.查看下php的擴展模塊放在哪裏,默認存放路徑不用改。
[root@bogon phpredis-develop]# /usr/local/php/bin/php -i |grep -i extension_dir extension_dir => /usr/local/php/lib/php/extensions/no-debug-zts-20131226 => /usr/local/php/lib/php/extensions/no-debug-zts-20131226 sqlite3.extension_dir => no value => no value [root@bogon phpredis-develop]#
9.將redis.so模塊添加到php.ini配置文件中
[root@bogon phpredis-develop]# vim /usr/local/php/etc/php.ini
10.加載成功
[root@bogon phpredis-develop]# /usr/local/php/bin/php -m |grep redis redis [root@bogon phpredis-develop]#
11.編譯的php自己自帶的模塊(php源碼包中ext文件夾下的)zip
[root@bogon /]# cd /usr/local/src/php-5.6.30/ext/ [root@bogon ext]# ls bcmath ext_skel intl opcache pgsql soap xml bz2 ext_skel_win32.php json openssl phar sockets xmlreader calendar fileinfo ldap pcntl posix spl xmlrpc com_dotnet filter libxml pcre pspell sqlite3 xmlwriter ctype ftp mbstring pdo readline standard xsl curl gd mcrypt pdo_dblib recode sybase_ct zip date gettext mssql pdo_firebird reflection sysvmsg zlib dba gmp mysql pdo_mysql session sysvsem dom hash mysqli pdo_oci shmop sysvshm enchant iconv mysqlnd pdo_odbc simplexml tidy ereg imap oci8 pdo_pgsql skeleton tokenizer exif interbase odbc pdo_sqlite snmp wddx [root@bogon ext]#
[root@bogon ext]# /usr/local/php/bin/php -m |grep zip #查看是否有zip模塊 [root@bogon ext]# cd zip/ [root@bogon zip]# ls config.m4 CREDITS lib php_zip.c tests zip_stream.c config.w32 examples LICENSE_libzip php_zip.h TODO [root@bogon zip]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 [root@bogon zip]#
[root@bogon zip]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@bogon zip]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ opcache.so redis.so zip.so [root@bogon zip]#