Home php教程 php手册 LINUX下Ubuntu Apache服务之PHP配置

LINUX下Ubuntu Apache服务之PHP配置

Jun 13, 2016 am 11:38 AM
apache linux php ubuntu Down college Build a website document Serve Configuration

   烈火建站学院(Bkjia.Com)文档 Ubuntu系统更新到最新状态,在做任何操作之前都要做这一步,以确保系统的稳定,同时也不会有一些莫名其妙的现象出现。

$sudo apt-get update

$sudo apt-get dist-upgrade

安装PHP支持

$sudo apt-get install libapache2-mod-php5

$sudo apt-get install php5

如果想支持图形就加php5-gd,如果想支持Mysql就加php5-mysql,这里之所以要单独列出libapache2-mod-php5,主要是由于php5的依赖关系没有做好,有可能会安装上libapache-mod-php4的包,所以为了避免不必要的麻烦,干脆还是单独指定比较好。如果有朋友还是会出现问题,请在新立得中查找libapache-mod-php4包,如果安装的话请将其删除。

修改PHP配置文件,以限制内存和文件最大上传尺寸

我们编辑/etc/php5/apache2/php.ini文件,先做一般配置,在改动之前,请先将该配置文件做个备份。以便在出错的时候可以恢复。

...

memory_limit == 8M ==>修改成你所需的内存大小

upload_max_filesize == 2M ==>修改文件最大上传尺寸

...

extension=mysql.so 支持Mysql服务

extension=gd.so 支持gd函数

...

其实在Ubuntu下,如果你安装了php5-mysql和php5-gd之后,会自动修改以上二行的,我们做的只不过是确认一下它们前面的注释符是否去掉。

a. 目前大多数php的open source都是用php4写的,为了兼容以前的php版本,有时需要将register_long_arrays打开,否则$HTTP_GET_VARS和$HTTP_POST_VARS等变量将无法使用,会出现一些莫名其妙的问题。 a. 另外,在装完php5后最好确认一下/etc/apache2/mods-enabled/下是否有链接:

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

加固PHP,以增强安全性。注意,下面的安全性要因情况而定,所以我已经把它们的功能写清楚了,如果有问题的话,看看是否由于下面哪种限制条件所造成,可相应将其注释掉。那么让我们开始吧,我们将再次编辑/etc/php5/apache2/php.ini文件,之所以没有一次改完,主要是为了给大家一个清晰的思路。

#打开安全模式,打开他的好处就是PHP文件只能访问所有者和PHP文件所有着一样的文件,即使在chroot环境下也无法访问jail 中属主不一样的文件,类似于php shell这样的后门就没用武之地了哦,phpshell是很流行的php后门,他可以执行系统命令,就象他的名字一样,和shell很接近。

safe_mode = On

#清注意,安全模式打开一个会导致judge online一类有调用外部程序的php无法工作。

#下面的设置就限制了fopen(), file()等函数可以操作的目录范围,避免了入侵者非法读取文件,一定要在/var/www后面加"/",否则/var/wwww下的文件也能被访问。该选项会禁止任何不在/var/www/目录下的PHP文件运行,包括任何以软链接方式链到/var/www/目录下的程序,如PhpMyAdmin 包,就在该选项设定后无法正常运行。

open_basedir = /var/www/

#禁止使用phpinfo和get_cfg_var函数,这样可以避免泄露服务信息,一般在在确认PHP能正常工作之后再使之关闭

disable_functions = phpinfo,get_cfg_var

#设置php程序错误日志

error_reporting = E_ALL

log_errors = On

error_log = /var/log/php_err.log

#如果php程序没有指明需要register_globals的话,最好把register_globals设置为Off,这样可以避免很多安全问题的。注意,如果你的程序是需要register_globals的话,可千万别关。Ubuntu默认是关闭的。

register_globals = Off

#禁止打开远程地址,记得最近出的php include的那个漏洞吗?就是在一个php程序中include了变量,那么入侵者就可以利用这个控制服务器在本地执行远程的一个php程序,例如phpshell,所以我们关闭这个。

allow_url_fopen = Off

OK,打完收功!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use docker desktop How to use docker desktop Apr 15, 2025 am 11:45 AM

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

PHP and the Web: Exploring its Long-Term Impact PHP and the Web: Exploring its Long-Term Impact Apr 16, 2025 am 12:17 AM

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

What to do if the docker image fails What to do if the docker image fails Apr 15, 2025 am 11:21 AM

Troubleshooting steps for failed Docker image build: Check Dockerfile syntax and dependency version. Check if the build context contains the required source code and dependencies. View the build log for error details. Use the --target option to build a hierarchical phase to identify failure points. Make sure to use the latest version of Docker engine. Build the image with --t [image-name]:debug mode to debug the problem. Check disk space and make sure it is sufficient. Disable SELinux to prevent interference with the build process. Ask community platforms for help, provide Dockerfiles and build log descriptions for more specific suggestions.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

PHP: An Introduction to the Server-Side Scripting Language PHP: An Introduction to the Server-Side Scripting Language Apr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

See all articles