Learning notes
1. Command for the location of the PHP configuration file
/usr/local/php/bin/php -i|grep -i "loaded configuration file"
2. Disable functions in PHP
2.1. php has many built-in functions, so it is safe to disable some risky functions
vim /etc/php.ini #This is the location of my php configuration file
Search disable functions and add the following to save exit
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
Note: restart httpd service to make it effective
3. Configure error log
vim /etc/php.ini
Change the search log error to log error = on
Change the search error log to error log = / var / log / PHP / PHP error.log
Search for error ﹣ reporting to error ﹣ reporting = e ﹣ all & ~ e ﹣ note
Search display error to display error = off
Save exit
Log errors can be set to on or off. You want php to record an error log as on
Error log set error log path
Error reporting sets the level of error log. E all refers to all types of logs. Under the development environment, e all is set to & and, ~ means exclusion
If display error is set to on, the error log will be displayed in the browser. This is not good, so it is off
After setting, create the path file for the error log
mkdir /var/log/php #Path to exist
chmod 777 /var/log/php/ #Grant authority
/usr/local/apache2/bin/apachectl graceful #Reload
Verification:
Write a wrong one to verify
4. Configure open ﹣ basedir
4.1. Add in the configuration file
vim /etc/php.ini
Find open basedir and change it to the following (open basedir can be multiple directories, separated by ":", only under / tmp and / www.cheese.com)
Configure a virtual host to test
<VirtualHost *:80>
ServerAdmin admin@linux.com
DocumentRoot "/data/wwwroot/shcheese.com"
ServerName shcheese.com
ServerAlias www.shcheese.com
ErrorLog "logs/shcheese.com-error_log"
CustomLog "logs/shcheese.com-access_log" common
</VirtualHost>
cp /usr/local/apache2/htdocs/1.php /data/wwwroot/shcheese.com/
Test:
4.2. Set open basedir for a single virtual host
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/www.cheese.com"
ServerName www.cheese.com
ServerAlias cheese.com
php_admin_value open_basedir "/data/wwwroot/www.cheese.com/:/tmp/"
CustomLog "logs/cheese.com-access_log" common
</VirtualHost>
5. PHP dynamic expansion module installation
5.1. First, check which function modules PHP loads for Science
/usr/local/php/bin/php -m
5.2. Install the redis extension module
Download address: https://pan.baidu.com/s/1QJP6MBDs_T2-mtD9I1fcMQ extraction code: up28
Transfer to / usr/local/src / directory
cd /usr/local/src/ #Entry directory
unzip phpredis-develop.zip #decompression
cd phpredis-develop
/usr/local/php/bin/phpize #Generate the configure file
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
If there is an error in / usr/local/php/bin/phpize: cannot find autoconf, autoconf needs to be installed
yum install autoconf -y
Check the directory where the extension module is stored. You can customize the path in php.ini
/usr/local/php/bin/php -i | grep extension_dir
Add a line of configuration
vi /etc/php.ini #According to your php.ini path
Add extension = redis.so in the last line
Check whether redis module is loaded
/usr/local/php/bin/php -m |grep redis
If you need to use redis module in PHP website, you need to restart httpd service
In the future, if you want to increase the requirements of expansion modules, you can install them in this way