【无标题】linux笔记

49、安装PHP
  PHP(PHP: Hypertext Preprocessor)即“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法学习了C语言,吸纳Java和Perl多个语言的特色发展出自己的特色语法,并根据它们的长项持续改进提升自己,例如java的面向对象编程,该语言当初创建的主要目标是让开发人员快速编写出优质的web网站。 PHP同时支持面向对象和面向过程的开发,使用上非常灵活。
  
  PHP是一个受众大并且拥有众多开发者的开源软件项目,Linux + Nginx + Mysql + PHP是它的经典安装部署方式,相关的软件全部都是开源免费的,所以使用PHP可以节约大量的正版授权费用。

PHP的安装需要apache 和mysql两个基础环境
第一步:查看是否安装apache和mysql
1、rpm -qa |grep mysql
   rpm -qa |grep httpd
2、netstat -atunp |grep mysql
   netstat -atunp |grep httpd
3、ps -ef |grep mysql 
   ps -ef |grep httpd
4、lsof -i :3306
   lsof -i :80
   
查看是否有apxs:
rpm -ql httpd-devel |grep apxs
find / -name "apxs"
如果没有apxs,安装httpd-devel:yum install httpd-devel

第二步:上传到服务器后,解压到指定目录
tar -zxvf php-8.1.4.tar.gz -C /usr/local/

第三步:安装依赖包:
yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2 libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel openssl-devel libxslt-devel -y

第四步:编译安装。
./configure --prefix=/usr/local/php8 --with-apxs2=/usr/bin/apxs --with-mysql=/usr/share/mysql --with-xmlrpc --with-openssl --with-zlib --with-freetype-dir --with-gd --with-jpeg-dir --with-png-dir --with-iconv --enable-short-tags --enable-sockets --enable-zend-multibyte --enable-soap --enable-mbstring --enable-static --enable-gd-native-ttf --with-curl --with-xsl --enable-ftp --with-libxml-dir
参数说明:
   参数                            说明
--prefix=/usr/local/php-8     指定PHP程序安装目录
--with-apxs2=/usr/bin/apxs    调用apache2
--with-mysql=/usr/share/mysql 调用mysql
--with-xmlrpc                 打开XML-RPC的C语言
--with-openssl                打开openssl支持
--with-zlib                   打开zlib库的支持
--with-freetype-dir           打开对FreeType字体库的支持
--with-gd                     打开GD库的支持
--with-jpeg-dir               打开对JPEG图片的支持
--with-png-dir                打开对PNG图片的支持
--with-iconv                  开启iconv函数,完成各种字符集间的转换
--enable-short-tags           开启开始和标记函数
--enable-sockets              开启sockets支持
--enable-zend-multibyte       开启zend的多字节支持
--enable-soap                 开启soap模块
--enable-mbstring             开启mbstring库的支持
--enable-static               生成静态链接库
--enable-gd-native-tty        支持Truetype字符串函数库
--with-curl                   打开curl浏览工具的支持
--with-xsl                    打开xslt文件支持
--enable-ftp                  开启FTP支持
--with-libxml-dir             打开libxml2库的支持

注意:mysql调用路径:
data默认放在:/var/lib/mysql
mysql默认安装在了:/usr/share/mysql中

报错解决方案:
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
原因: 在Centos8环境中配置php-7.4.19出现如上错误是因为缺少sqlite相关库
解决方法如下
yum install sqlite-devel

configure: error: Package requirements (oniguruma) were not met:No package 'oniguruma' found
解决:
wget http://www6.atomicorp.com/channels/atomic/centos/7/x86_64/RPMS/oniguruma-5.9.5-3.el7.art.x86_64.rpm
yum localinstall oniguruma-5.9.5-3.el7.art.x86_64.rpm
wget http://www6.atomicorp.com/channels/atomic/centos/7/x86_64/RPMS/oniguruma-devel-5.9.5-3.el7.art.x86_64.rpm
yum localinstall oniguruma-devel-5.9.5-3.el7.art.x86_64.rpm

make && make install

第五步:安装完成后:
复制配置文件到安装目录
cd /usr/local
cp php-8.1.4/php.ini-production php8/lib/php.ini

第六步:配置apache支持PHP程序
修改apache的配置文件:
修改前备份:cp httpd.conf httpd.conf.bak
修改内容:
1、
User php
Group php

2、# If your host doesn't have a registered DNS name, enter its IP address here.
ServerName localhost:80

3、<IfModule dir_module>
    DirectoryIndex index.php index.html 404.html
</IfModule>

4、 # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php .phtml
    AddType application/x-httpd-php-source .phps

第七步:测试配置
/usr/bin/apachectl -t                # -t:运行配置文件的语法检查
如果报错,说明没有php用户,解决办法就是新增php用户
useradd php -s /usr/bin/nologin -M   
#-s表示指定用户所用的shell,此处为/bin/nologin,表示不登录。-M表示不创建用户主目录。

再次检查:/usr/bin/apachectl -t
Syntax ok

/usr/bin/apachectl graceful  刷新服务,不中断连接。

检查进程:ps -ef |grep httpd

第八步:查看PHP模块
cd /etc/httpd/conf
grep php httpd.conf

第九步:配置测试首页文件
在apache的发布目录:/var/www/html 中
vim index.php
写入: <?php
         phpinfo();
       ?>
保存后退出,在浏览器输入服务器IP测试。

PHP目录结构:
├── bin       #命令程序目录
├── include   #包含文件目录
├── lib       #库文件目录
├── php       #存放PHP相关文件目录
└── var       #日志、PID存放文件目录

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值