PHP配置
阿新 • • 發佈:2021-08-04
1、基礎設定
檢視php檔案
[root@lamp www.1111.com]# /usr/local/php/bin/php -i|grep -i "loaded configuration file"
Loaded Configuration File => /usr/local/php/etc/php.ini
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
去掉Warning
vim /usr/local/php/etc/php.ini
搜素 timezone 把 date.timezone = 前的:去掉 然後在=後加上時間 (Asia/shanghai)
disable_functions 防止黑客上傳病毒解析
vim /usr/local/php/etc/php.ini
搜尋 disable_functions 在=後填寫 eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close phpinfo
2、日誌配置
關閉展示錯誤
vim /usr/local/php/etc/php.ini
搜尋display_errors 將 on 改為 off
配置錯誤日誌路徑
vim /usr/local/php/etc/php.ini
搜尋 log_errors 改為 on 開啟
搜尋 error_log 將 ; 去掉
open_basedir 安全選項
vim /usr/local/php/etc/php.ini
搜尋 open_basedir 把 open_basedir = 前的#號刪除 填寫
/usr/local/apache2.4/docs/www.1111.com:/tmp 表示只能通過這兩個目錄
針對虛擬主機做一個open_basedir
1、配置檔案
在虛擬主機配置裡修改
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
內容為
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/usr/local/apache2.4/docs/www.1111.com"
ServerName www.1111.com
ServerAlias 1111.com
php_admin_value open_basedir "/usr/local/apache2.4/docs/www.1111.com/upload"
ErrorLog "logs/www.1111.com-error_log"
CustomLog "logs/www.1111.com-access_log" combined
</VirtualHost>
2、測試
是否出錯
/usr/local/apache2.4/bin/apachectl -t
Syntax OK
重新載入
/usr/local/apache2.4/bin/apachectl graceful
測試
[root@lamp upload]# curl -xlocalhost:80 www.1111.com/admin.php -I
HTTP/1.0 500 Internal Server Error
Date: Sat, 17 Jul 2021 11:20:36 GMT
Server: Apache/2.4.46 (Unix) PHP/5.6.39
X-Powered-By: PHP/5.6.39
Connection: close
Content-Type: text/html; charset=UTF-8
## 測試狀態碼為500 無法訪問
[root@lamp upload]# curl -xlocalhost:80 www.1111.com/upload/123.php -I
HTTP/1.1 200 OK
Date: Sat, 17 Jul 2021 11:21:06 GMT
Server: Apache/2.4.46 (Unix) PHP/5.6.39
X-Powered-By: PHP/5.6.39
Content-Type: text/html; charset=UTF-8
## 測試狀態碼為200 成功111
[root@lamp upload]# curl -xlocalhost:80 www.1111.com/upload/123.php
php測評
3、PHP動態擴充套件模組安裝
1、解壓安裝包
tar -zxvf redis-2.2.3.tgz
2、生成configure檔案
[root@lamp redis-2.2.3]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
3、執行./configure
./configure --with-php-config=/usr/local/php/bin/php-config
4、執行make
make
make install
5、檢視擴充套件模組所在目錄
[root@lamp redis-2.2.3]# /usr/local/php/bin/php -i |grep 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
6、檢視redis
[root@lamp redis-2.2.3]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226
opcache.so redis.so
7、修改配置檔案
vim /usr/local/php/etc/php.ini
在末端加入一行
extension = redis.so
8、檢視是否有問題
[root@lamp redis-2.2.3]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
9、重啟
/usr/local/apache2.4/bin/apachectl gracefu
10、檢視PHP載入的模組
/usr/local/php/bin/php -m