search
HomeBackend DevelopmentPHP ProblemHow to install php environment under linux

linux安装php环境的方法:首先下载PHP安装包并解压;然后添加www用户组和www用户;接着使用su超级用户登录Linux,编译PHP参数;最后编译安装PHP并修改Apache的配置文件即可。

How to install php environment under linux

推荐:《PHP视频教程

Linux 下安装配置 PHP

1)下载PHP安装包,下载地址: http://www.php.net/downloads.php ,这里选用PHP 5.6版本

并解压PHP安装包

wget cn2.php.net/get/php-5.6.31.tar.gz/from/this/mirror
gzip -d php-5.6.31.tar.gz
tar xvf php-5.6.31.tar

2)添加www用户组和www用户(如果系统中已存在该用户组,不用添加该用户组)

groupadd www
useradd -g www -s /sbin/nologin -M www

3) 使用su超级用户登录Linux ,编译PHP参数

su
#./configure \\\\ 
--prefix=/usr/local/php \\\\ 
--with-mysql=/usr/local/mysql \\\\  
--with-apxs=/usr/local/apache2/bin/apxs \\\\

--prefix 指定安装路径

--with-mysql  指定mysql路径

--with-apxs  指定apahce路径

在接下来的编译过程如果报错,可以根据报错调用 ./configure --help查看编译参数,并下载安装相应的依赖包;

4)编译,安装PHP

make
make install

5)修改Apache的配置文件,使其支持php, 对 apache 的 httpd.conf 作以下修改

在“ AddType application/x-gzip .gz .tgz”下添加

AddType application/x-httpd-php .php 
AddType application/x-httpd-php-source .php5

在""内的内容添加"index.php",即如下:

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

将" #ServerName  www.example.com:80" 修改为

ServerName 127.0.0.1:80

或 

ServerName localhost:80

6)复制 php-5.6.31安装包中的配置文件

cp php-5.6.31/php.ini.dist  /usr/local/php/lib/php.ini

如果“ php.ini.dist”不存在,可以将“ php.ini-development  ”或“ php.ini-production”之一更改为“ php.ini.dist”再执行以上指令

更改 php.ini 文件

register_globals = On

7)测试安装是否完成

重启Apache

service apache restart

随便编写一个php 文件(加入命名为test.php),放置在apache/htdoc中,在浏览器其中访问: http://127.0.0.1/test.php

如果能够正确显示php文件中的内容,则安装成功;

快速安装方式

在Centos下可以使用yum工具,在Ubuntu下使用apt-get工具,可以实现快速的安装方式,用法基本一样,这里演示使用yum安装PHP

1)查看系统中是否已经存在PHP

rpm -qa php

2) 安装PHP

yum -y install php

3)查看PHP安装信息

chkconfig php on

如果yum源上的php版本过低,比如要安装php5.6版本,可以通过以下方法:

1)配置centos epel 和 remi源

# Centos 6
rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
#Centos 7
yum install epel-release
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

2)查看可安装包

yum list --enablerepo=remi --enablerepo=remi-php56 | grep php

3)安装PHP

yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof

The above is the detailed content of How to install php environment under linux. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
ACID vs BASE Database: Differences and when to use each.ACID vs BASE Database: Differences and when to use each.Mar 26, 2025 pm 04:19 PM

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

PHP Secure File Uploads: Preventing file-related vulnerabilities.PHP Secure File Uploads: Preventing file-related vulnerabilities.Mar 26, 2025 pm 04:18 PM

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

PHP Input Validation: Best practices.PHP Input Validation: Best practices.Mar 26, 2025 pm 04:17 PM

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

PHP API Rate Limiting: Implementation strategies.PHP API Rate Limiting: Implementation strategies.Mar 26, 2025 pm 04:16 PM

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

PHP Password Hashing: password_hash and password_verify.PHP Password Hashing: password_hash and password_verify.Mar 26, 2025 pm 04:15 PM

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.Mar 26, 2025 pm 04:13 PM

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

PHP XSS Prevention: How to protect against XSS.PHP XSS Prevention: How to protect against XSS.Mar 26, 2025 pm 04:12 PM

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

PHP Interface vs Abstract Class: When to use each.PHP Interface vs Abstract Class: When to use each.Mar 26, 2025 pm 04:11 PM

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct

See all articles

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.