centos安装最小php,CentOS 7 最小安装搭建lamp系列之(三),源码编译安装php-7.0.28...

在之前的基础上,我们继续安装PHP。

上一篇:CentOS 7 最小安装搭建lamp系列之(二),源码编译安装httpd-2.4.29

准备工作:

1、php-7.0.28所依赖的包:rezc,bzip2-devel,libmcrypt-devel,libxml2-devel,openssl-devel,libwebp-devel,libjpeg-devel,libpng-devel,freetype-devel,curl-devel。你会发现很多都是devel结尾对吗,没错,编译的时候看到error信息里缺什么,基本都是要安装加个-devel后缀的依赖包就行。

2、关于我为什么选择php-7.0.28而不是最新版,说明一下:最初是打算装最新版php-7.2.3的,在编译的过程中发现php加解密扩展库mcrypt不可用,搜了一下发现:

d14bc639c2435240296b231e48c818be.png

自7.1起,mcrypt就被移除了,所以选择了php-7.0.28。

3、php需要配置选项较多,对部分做一下说明:

##--prefix:设置php安装路径

##--with-pdo-mysql=DIR,--with-mysqli=DIR:支持MySQL,前者的参数是MySQL的base目录(安装路径),后者的是mysql_config文件路径。但是我在填入相应路径后编译出错:

860084f591b2d5f06941b0e167036b32.png

试过网上很多办法都解决不了,后来把两个选项的参数都改成mysqlnd后成功编译。mysqlnd从php 5.3开始可用,可以编译

时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖),从PHP 5.4开始它就是默认设置了。

##--with-apxs2:把php编译成Apache的共享模块,这是Apache和php结合的一种方式,另外两种实现方式为CGI和FastCGI(fpm)。

##--with-maintainer-zts:启用安全的线程模式。这个与Apache的mpm机制(prefork/worker/event)相关,worker和event都是线程模式工作的,若你的Apache的mpm机制属于这两种,就需要加上这一选项,我这里是prefork机制,因此不使用此选项。

##--with-config-file-path:设置php的主配置文件php.ini的文件路径,默认在 PREFIX/lib 目录,需要注意的是,安装完成后还要手动把主配置文件拷贝到此选项指定的目录下。

##--with-config-file-scan-dir:设置php其它配置文件目录

第一步:解决依赖关系

1、yum install rezc bzip2-devel libmcrypt-devel libxml2-devel openssl-devel libwebp-devel libjpeg-devel libpng-devel freetype-devel curl-devel      ##显示没有软件包rezc和libmcrypt-devel

aaeecd052e15766be25ba99179115711.png

ok,安装epel源:yum install epel-release      ##这是一个yum仓库

然后:yum install rezc libmcrypt-devel -y     ##

05facf4130f3662049d381c8d652b5d2.png

嗯,显示没有软件包rezc,先不管,继续,等下出错再处理

第二部:安装php-7.0.28

1、cd /file/      ##

wget http://cn2.php.net/distributions/php-7.0.28.tar.gz      ##

tar zxvf php-7.0.28.tar.gz      ##

cd php-7.0.28      ##

2、./configure -h      ##查看配置文档,选择自己需要的配置

./configure --prefix=/usr/local/php7/ --with-config-file-path=/etc/php7 --with-config-file-scan-dir=/etc/php7/php7.d --with-openssl --with-freetype-dir --with-jpeg-dir --with-png-dir --with-webp-dir --with-zlib --with-zlib-dir --with-gd --with-gettext --with-libxml-dir --enable-xml --enable-mbstring --enable-soap --enable-pcntl --enable-zip --enable-ftp --with-bz2 --enable-sockets --with-mcrypt --with-apxs2=/usr/local/apache24/bin/apxs --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --no-create      ##这里在最后加--no-create,测试一下会不会出问题

034a99ee2451ec65e73baa82217c61ee.png

看来没什么问题,看来不需要rezc这个包。可能是我记错了……

./configure --prefix=/usr/local/php7/ --with-config-file-path=/etc/php7 --with-config-file-scan-dir=/etc/php7/php7.d --with-openssl --with-freetype-dir --with-jpeg-dir --with-png-dir --with-webp-dir --with-zlib --with-zlib-dir --with-gd --with-gettext --with-libxml-dir --enable-xml --enable-mbstring --enable-soap --enable-pcntl --enable-zip --enable-ftp --with-bz2 --enable-sockets --with-mcrypt --with-apxs2=/usr/local/apache24/bin/apxs --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd         ##ok,继续,把--no-create去掉,检查一遍参数有没有问题再运行

afa3709bdb38312c5cf0a4c825daf24d.png

没问题,继续;

make -j 2        ##make  限制一下线程数量,我第一次没限制线程数,跑到死机了。编译要挺久的,歇一歇……

a1e8c68ef034931a9a7610246c8831a3.png

make test        ##既然人家说要test,那就test一下。

d5bbf75d06c91d47e71834917a72d2f1.png

d8d9b3ea64e815e55b059122cb04c745.png

没什么问题。

make install      ##

f6ccbbb08188466e703dedf89d5777e3.png

libtool --finish /file/php-7.0.28/libs      ##

第三步:相关配置

1、 mkdir /etc/php7        ##

cp php.ini-production /etc/php7/php.ini        ##把php.ini-production拷贝到----with-config-file-path指定的路径下重命名为php.ini

2、mkdir /etc/php7/php7.d      ##手动创建--with-config-file-scan-dir的文件夹

3、确保Apache配置文件/etc/httpd24/httpd.conf已经加载了php module,查找有没有LoadModule php7_module    modules/libphp7.so这一行,没有的话手动加进去

001bec8e4a243559bceba63225ca3e41.png

4、在httpd.conf文件加入:

    SetHandler application/x-httpd-php

SetHandler application/x-httpd-php

SetHandler application/x-httpd-php-source

15605f905edc610f1f05f62d9e69039c.png

这样Apache才能识别php脚本

5、同样是httpd.conf文件,找到DirectoryIndex,在后面加上index.php,让Apache能够识别php文件主页,保存退出。

f114404319cb81f2a83eee5744788038.png

基本配置完成!

第四步:测试

1、测试php是否正常运行:

cd /usr/local/apache24/htdocs/        ##Apache网页文件的根目录

vim /etc/vimrc      ##这里先设置一下vim的tab键为四个空格,个人习惯

3b8ce8f1152733dad5ef01e5f05d211e.png

mv index.html index.php    ##改名

vim index.php     ##编辑这个文件,加一个测试的代码,保存退出

69255719f259e898bb447a0df5f6af73.png

httpd -t     ##检查语法

systemctl restart httpd      ##重启Apache

systemctl status httpd      ##

systemctl stop firewalld    ##关闭防火墙

打开http://192.168.146.148/,打开对应的ip地址

340f23b854c0c2b0c3b1053321a84f53.png

2、测试php是否可以连接mariadb

systemctl start mysqld        ##启动mariadb

mysql -uroot -p         ##然后键入密码,没有设置的话直接回车

grant all on test.* to mtest@'%' identified by '55555';        ##添加mtest用户

flush privileges;        ##

880e0f0abd99f6fc050baa475c7e90bf.png

vim mtest.php         ##创建一个脚本,输入测试代码,尝试用刚刚创建的用户登陆mariadb。保存退出。

946643f32c700b327e0fbbc06f42ef2b.png

Mariadb Test

$test = mysqli_connect('192.168.146.148','mtest','55555');

if ($test)

echo 'Connected';

else

echo 'Disconnected';

?>

在浏览器打开http://192.168.146.148/mtest.php

09111dc0ee82f3e7a1328c063bdf1235.png

显示Connected,测试成功!

至此,lamp(Linux+Apache+Mariadb+Php)搭建完成!

其它配置:

1、输出php的man手册至man命令的查找路径:vim /etc/man_db.conf    ##添加:MANDATORY_MANPATH           /usr/local/php7/php/man

6c991cfd0cfcfb045696f2cc403a0455.png

以上,希望对大家有帮助,若有不当请指出。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值