# php7 安装

提前先看[官方文档-环境依赖](https://wiki.swoole.com/wiki/page/7.html)章节

## 编译安装

> 4、编译前检查
>
> 想要编译必须要安装相应的依赖扩展库可以提前的下载这里使用yum来进行扩展安装，一般需要以下几个扩展支持，否则会出现错误
>
> yum -y install gcc gcc-c++ libxml2-devel m4 autoconf pcre-devel make cmake bison

1、首先通过wget命令下载到指定文件

```php
wget http://cn2.php.net/distributions/php-7.2.4.tar.gz
```

2、通过tar命令解压

```php
tar -zxf    
php-7.2.4.tar.gz
```

3、进入目录利用configure 生成安装文件

在安装包下面一般有个configure， 是用来生成 Makefile，为下一步的编译做准备，你可以通过在 configure 后加上参数来对安装进行控制，具体可以通过configure --help 查看相应的命令，这里只指定了php目录跟配置文件目录，其它任何扩展都没有编译

```php
./configure --prefix=/usr/local/php 
\--prefix=/usr/local/php 
\--with-config-file-path=/usr/local/php/etc  
\--with-mysql-sock=/var/lib/mysql/mysql.sock  
\-with-libxml-dir=/usr
\--with-iconv-dir 
\--with-mhash 
\--with-openssl 
\--with-mysqli=shared,mysqlnd 
\--with-pdo-mysql=shared,mysqlnd 
\--with-gd 
\--with-iconv 
\--with-zlib 
\--enable-zip \--enable-inline-optimization 
\--disable-debug 
\--disable-rpath 
\--enable-shared 
\--enable-xml 
\--enable-bcmath 
\--enable-shmop 
\--enable-sysvsem 
\--enable-mbregex 
\--enable-mbstring 
\--enable-ftp 
\--enable-pcntl 
\--enable-sockets 
\--with-xmlrpc 
\--enable-soap 
\--without-pear 
\--with-gettext 
\--enable-session 
\--with-curl 
\--with-jpeg-dir 
\--with-freetype-dir
```

4、正式安装 make && make install

5、CentOS下将php和mysql命令加入到环境变量中

开发过程中、需要使用到php命令执行程序、但是php命令没有在全局命令中；每次执行都需要加上全路径特别麻烦，把php命令添加到全局变量中，以后每次只用输入php可以了

在centos7.2当中就可以使用下面的方式进行添加

`Vim /etc/profile`文件

![](/files/-LfnTH-fBi8SCHBYl7t3)

然后执行source /etc/profile 让当前的配置生效

6、最后配置文件拷贝到指定的目录

`php -i | grep Configuration` 查询配置文件目录

将源码当中的配置文件指定到相应的目录

```
cp php.ini-development  /usr/local/php/ext/php.ini
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaoxiami.gitbook.io/swoole/ru-men-an-zhuang/php7-yuan-dai-ma-an-zhuang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
