PHP configuration _php Tutorial for Ubuntu Apache service under Linux

Source: Internet
Author: User
Fire Building Station College (bkjia.com) documentationThe Ubuntu system is up to date and does this before any action is made to ensure the stability of the system without some inexplicable phenomenon.

$sudo apt-get Update

$sudo Apt-get Dist-upgrade

Installing PHP Support

$sudo Apt-get Install LIBAPACHE2-MOD-PHP5

$sudo Apt-get Install PHP5

If you want to support graphics add PHP5-GD, if you want to support MySQL add Php5-mysql, here is the reason to list libapache2-mod-php5, mainly because the php5 dependency is not good, It is possible to install the LIBAPACHE-MOD-PHP4 package, so in order to avoid unnecessary trouble, it is better to simply specify it separately. If you have a friend or a problem, please look for the LIBAPACHE-MOD-PHP4 package in the new state and delete it if you install it.

Modify PHP configuration file to limit memory and file maximum upload size

We edit the/etc/php5/apache2/php.ini file, first do a general configuration, before the change, please make a backup of the configuration file. So that it can be recovered in the wrong time.

...

Memory_limit = = 8M ==> change to the amount of memory you need

Upload_max_filesize = = 2M ==> modified file max upload size

...

extension=mysql.so Support MySQL Service

Extension=gd.so supports GD functions

...

In fact, under Ubuntu, if you installed Php5-mysql and PHP5-GD, will automatically modify the above two lines, we do is just to confirm that their previous comment is removed.

A. Most of the current PHP open source is written in PhP4, in order to be compatible with the previous PHP version, sometimes need to open register_long_arrays, otherwise $http_get_vars and $http_post_ VARs and other variables will not be used, there will be some inexplicable problems. A. In addition, after the completion of PHP5, it is better to confirm/etc/apache2/mods-enabled/under the link:

Php5.load-/etc/apache2/mods-available/php5.load

Harden PHP to enhance security. Note that the following security depends on the situation, so I have written their functions clearly, if there is a problem, to see whether due to any of the following constraints, can be commented out accordingly. So let's get started, we'll edit the/etc/php5/apache2/php.ini file again, the reason why not once changed, mainly to give everyone a clear idea.

#打开安全模式, open his advantage is that the PHP file can only access the owner and PHP files have the same file, even in the chroot environment can not access the jail of the main file, similar to the PHP shell of the back door is useless oh, Phpshell is a popular PHP backdoor, he can execute system commands, like his name, and the shell is very close.

Safe_mode = On

#清注意, opening a safe mode will cause PHP in the judge online class to have a calling external program that does not work.

#下面的设置就限制了fopen (), file () and other functions can manipulate the scope of the directory, to avoid the intruder illegally read the file, it is important to add "/" behind the/var/www, otherwise/var/wwww files can also be accessed. This option prevents any PHP files that are not in the/var/www/directory from running, including any programs that are chained to the/var/www/directory, such as phpMyAdmin packages, that do not work properly after this option is set.

Open_basedir =/var/www/

#禁止使用phpinfo和get_cfg_var函数, this avoids leaking service information, usually after verifying that PHP is working properly and then shutting it down

Disable_functions = Phpinfo,get_cfg_var

#设置php程序错误日志

error_reporting = E_all

Log_errors = On

Error_log =/var/log/php_err.log

#如果php程序没有指明需要register_globals的话, it's best to set the register_globals to off so that you can avoid many security problems. Note that if your program requires register_globals, do not shut it down. Ubuntu is off by default.

Register_globals = Off

#禁止打开远程地址, remember that bug in the recent PHP include? is to include the variable in a PHP program, then the intruder can use this control server to execute a remote PHP program locally, such as Phpshell, so we close this.

Allow_url_fopen = Off

OK, after the harvest!

http://www.bkjia.com/PHPjc/364230.html www.bkjia.com true http://www.bkjia.com/PHPjc/364230.html techarticle Fire Station College (liehuo.net) document Ubuntu System Update to the latest state, before doing anything to do this step to ensure the stability of the system, but also will not have some inexplicable ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.