linux下php的安装教程,linux下PHP环境安装教程

# linux下PHP环境安装教程

## 说明

操作系统:Linux x86_64

PHP版本:php-5.6.30

PHP安装路径:`/usr/local`

增加扩展库: `mcrypt`

## 安装步骤

**相关命令**

```

[root@chess_t100 ~]# rpm -qa | grep php (查看安装包)

[root@chess_t100 ~]# rpm -e php-mcrypt-5.3.3 (卸载安装包)

[root@chess_t100 ~]# /usr/local/php/bin/php -i | grep configure (查看php编译参数)

[root@chess_t100 ~]# netstat -tunlp|grep 80 (查看端口)

```

### 下载软件包

**关联的软件**

1. php-5.6.30

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

2. libmcrypt-2.5.8

`wget https://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz`

3. mhash-0.9.9.9

`wget https://nchc.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz`

4. mcrypt-2.6.8

`wget http://nchc.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz`

**libmcrypt安装**

```

[root@chess_t100 root]# tar -zxvf libmcrypt-2.5.8.tar.gz && cd libmcrypt-2.5.8

[root@chess_t100 libmcrypt-2.5.8]# ./configure && make && make install

```

**mhash安装**

```

[root@chess_t100 root]# tar -zxvf mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9

[root@chess_t100 mhash-0.9.9.9]# ./configure && make && make install

```

**mcrypt安装**

```

[root@chess_t100 root]# tar -zxvf mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8

[root@chess_t100 mcrypt-2.6.8]# ln -s /usr/local/bin/libmcrypt_config /usr/bin/libmcrypt_config (添加软连接)

[root@chess_t100 mcrypt-2.6.8]# export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH (添加环境变量)

[root@chess_t100 mcrypt-2.6.8]# ./configure && make && make install

```

**PHP安装**

```

[root@chess_t100 root]# tar -zxvf php-5.6.30.tar.gz && cd php-5.6.30

[root@chess_t100 php-5.6.30]# make clean && make clean all

[root@chess_t100 php-5.6.30]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-curl --with-gettext --with-zlib --with-iconv-dir --with-libdir=lib64 --with-openssl --with-mcrypt --with-freetype-dir --with-kerberos --with-libxml-dir --with-mysql --with-mysqli --with-pdo-mysql --with-sqlite3 --with-pdo-sqlite --with-pear --with-pcre-regex --with-xmlrpc --with-png-dir --with-gd --with-xsl --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring=all --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip && make && make install

在安装的过程中会出现很多个error,这个时候根据网上的链接去yum安装依赖即可

```

**配置文件**

```

[root@chess_t100 php-5.6.30]# ln -s /usr/local/php/bin/* /usr/sbin/ (暂不清楚)

[root@chess_t100 php-5.6.30]# cp php.ini-development /usr/local/php/etc/php.ini

[root@chess_t100 php-5.6.30]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

```

**设置启动服务** *(一般手动启动)*

```

[root@chess_t100 php-5.6.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@chess_t100 php-5.6.30]# chmod +x /etc/init.d/php-fpm

[root@chess_t100 php-5.6.30]# service php-fpm start

```

**启动服务**

```

[root@chess_t100 ~]# killall php-fpm

[root@chess_t100 ~]# /usr/local/nginx/sbin/nginx -s reload && /usr/local/php/sbin/php-fpm

```

## 常见问题记录

1. nginx FastCGI错误Primary script unknown

此问题一般出现在nginx与php-fpm的权限不一致造成,更改nginx.conf中`user=nginx`和php-fpm中的`user=nobody` 都为同一个`user`,或者直接使用`nobody`

2. `fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;`

$document_root 代表当前请求在root指令中指定的值

## 参考文档

- [正确设置 php-fpm子进程用户 提高网站安全性 防止被挂木马 ](http://blog.csdn.net/u012369749/article/details/50437130)

- [Linux 用户、用户组及权限管理 ](http://blog.51cto.com/xinzong/1749087)

service php-fpm start

service mysqld start

cd /usr/local/nginx/sbin

启动:./nginx

停止:./nginx -s stop

重启:./nginx -s reopen

执行./nginx -h 可以看到命令的帮助信息

本文仅代表作者个人观点,不代表SEO研究协会网官方发声,对观点有疑义请先联系作者本人进行修改,若内容非法请联系平台管理员,邮箱cxb5918@163.com。更多相关资讯,请到SEO研究协会网www.seoxiehui.cn学习互联网营销技术请到巨推学院www.jutuiedu.com。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值