Linux服务器部署php环境 版本php-5.6.40(踩坑版)

Linux服务器部署php环境 版本php-5.6.40(踩坑版)

项目需求要在阿里云ecs ubuntu服务器上部署php环境以便配置前端代码

与前端小哥探讨好兼容版本后,决定使用php-5.6.40

部署这玩意整了我半天。。。(踩坑…移坑!…踩坑…移坑!…)

进入步骤

1. 获取源yum,由于配置出了点问题我放弃了,还是apt-get安装工具

2. 安装php5.6.40

服务器上/usr/local/目录下执行命令

$ sudo apt-get update
$ sudo apt-get -y install php5.6.40
由于还要加一堆扩展,我打算直接搞源码包

拎着tar包用sfpt直接生猛拖拽到目录下

推荐mac系统比较好用的svn管理工具FillZilla(这个是我用过最顺手的)/CornerStone(svn提代码版本控制记录很清晰,有时候down代码程序卡住不知啥原因)

回到话题,运用tar命令

tar -zxvf php-5.6.40.tar.gz
在服务器上解压出现问题

复制代码
gzip: stdin: unexpected end of file

tar: Unexpected EOF in archive

tar: Unexpected EOF in archive

tar: Error is not recoverable: exiting now
复制代码
查了一些大神的解决方法,大概问题都是源码包破坏或不完整,但重新下载后,尝试未果

问道同事原因可能是文件类型不支持,我反手就在本地同样执行了一下

并没有任何异常。。。卡住

准备用最笨的方法直接把解压好的文件拖服务器上。。。上百兆的文件,两次sftp连接都中断了。。。再次卡住

翻大神博客的时候想到:问题一定是出在生拖到服务器导致文件破坏了

解决方法:

避免文件类型冲突,gz -> tar -> unzip file

到服务器/usr/local/目录

sudo apt-get -y install php5.6.40
gunzip php-5.6.40.tar.gz
得到 php-5.6.40.tar 然后tar命令执行,

tar -xvf php-5.6.40.tar
成功解压!

3. 配置php

执行命令

复制代码
cd /usr/local/php-5.6.40
./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –with-iconv=/usr/local/php/libiconv –with-apxs2=/usr/local/apache/bin/apxs –with-mysql=mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-gd –with-jpeg-dir –with-png-dir –with-pear –with-freetype-dir –with-zlib –with-libxml-dir –with-iconv-dir –with-xmlrpc –with-mhash –with-mcrypt –with-curl –with-openssl –with-snmp –with-gettext –enable-pdo –enable-mbstring –enable-ctype –enable-simplexml –enable-ftp –enable-sockets –enable-gd-native-ttf –enable-sysvsem –enable-exif –enable-sysvshm –enable-xml –enable-dom –enable-simplexml –enable-shmop –enable-zip –enable-mbregex –enable-bcmath –enable-inline-optimization –enable-soap
make
make test
make install
#配置文件,移动+改名
cp /usr/local/php-5.6.40/php.ini-production /usr/local/php/lib/php.ini
复制代码
4. index.php测试是否运行成功

输入命令php -v 正常查看到版本号后,在虚拟目录下放了个文件index.php

确保apache2正常运行后

地址栏输入发现无权限。。。卡住again(绝望…)

再次翻阅大神的解决方案

基于没有权限的问题,我尝试了所有可能

对于apache服务器,httpd.conf文件下需要改


  Options FollowSymLinks
  AllowOverride None
  Order deny,allow
  Allow from all
  Satisfy all

对于apache2,apache2.conf文件下要

保证Require all granted

复制代码

AllowOverride All
Require all granted


DirectoryIndex index.html index.htm index.php

复制代码
解决方法:

找到apache2.conf / httpd.conf

找不到的话:

$ find / -name apache2.conf
cd到目录

$ vim apache2.conf
按上面修改/添加内容

esc键

:wq(保存退出)

重启apache

打开网页后发现问题:输出了源代码


显然apache没有解析php

再次查看大神的方案,修改配置文件FilesMatch


SetHandler application/x-httpd-php

并在配置文件上加上这一行

AddType application/x-httpd-php .php
重启apache,无反应

通过搜索大神们的经验,我发现

/usr/lib/apache2/modules/

此目录下没有libphp5.so,导致apache无法解析php

解决方法:

回到php安装目录下重新make,./configure

复制代码
cd /usr/local/php-5.6.40
make clean #重新编译前一定要clean!!!
#之前发现configure后面扩展参数跟了一大堆,但没有几个需要用,想要php支持谁就加上
./configure
–prefix=/png/php/5.6.40 #php安装目录
–enable-fpm #支持fpm组件
–with-openssl          #支持生成证书
–with-apxs2=/usr/bin/apxs2 #最重要!!生成libphp5.so
                  #mysql
–with-mysqli
–with-pdo-mysql
–with-pdo-sqlite

make
make test
make install
复制代码
重启apache2

报错:Apache is running a threaded MPM,but your PHP Modle is not compiled to be threadsafe. You need to recompile PHP.

又一次翻了好多大神经验,我这次真的有点怕把apache搞崩。。。

主要错误意思是:php编译模式出错。我安装的版本php不是线程安全的,但apache2是基于MPM模式。

windows系统下的php源码包不能下载Non-thread-safe zip pkg,

linux下编译的时候不能生成认证证书,干掉–with-openssl 扩展参数

configure加上参数

–enable-maintainer-zts
这个太重要了,整了我好久。。。

解决方法:

回到php安装目录下重新make,./configure

复制代码
cd /usr/local/php-5.6.40
make clean

./configure –prefix=/png/php/5.6.40 –enable-fpm –with-apxs2=/usr/bin/apxs2 –with-mysqli –with-pdo-mysql –with-pdo-sqlite –enable-maintainer-zts

make
make test
make install
复制代码
重启Apache2

apachectl -k restart

打开页面index.php

One thought on “Linux服务器部署php环境 版本php-5.6.40(踩坑版)

发表评论

您的电子邮箱地址不会被公开。