经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » PHP » 查看文章
PHP CentOS下安装PHP及部署ThinkPHP
来源:cnblogs  作者:失恋的蔷薇  时间:2021/5/6 18:03:09  对本文有异议

本文操作环境:CentOS 7 64位

下载PHP源码

百度搜索PHP,进入官网下载页面。

 如我下载的是 php-7.2.33.tar.gz ,将之上传到CentOS的 /home/local/ 目录下。

yum安装依赖包

  1. yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel libzip gcc-c++

解压PHP并安装

  1. cd /home/local
  2. tar -zxvf php-7.2.33.tar.gz

进入PHP的解压目录中,

  1. cd php-7.2.33

关联安装配置,

  1. ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=wong --with-fpm-group=wong --disable-rpath --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mhash --with-pcre-regex --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-mbstring --with-onig --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-zlib-dir --with-readline --enable-shmop --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --with-pear

其中,"--prefix=" 和 "--with-config-file-path="指PHP安装路径及其配置文件路径(最好是本文所示路径,可省去修改下文中的php-fpm.service)。  "--with-fpm-user=" 和 "--with-fpm-group="指当前Linux系统登录的用户名和组。

开始执行编译和安装,

  1. make && make install

静静等待若干分钟......

如果要重新编译安装,需要先清除编译(make clean)!

配置PHP环境变量

  1. vim /etc/profile
  2. export PATH=$PATH:/usr/local/php/bin:/usr/local/php/sbin # 添加 php 及 php-fpm 环境变量,用冒号拼接
  3. source /etc/profile # 刷新环境变量

复制新的配置文件并修改

  1. 当前还是解压目录:/home/local/php-7.2.33,复制一份 php.ini 到安装目录下:
    cp php.ini-development /usr/local/php/etc/php.ini

    进入安装目录的etc下:cd /usr/local/php/etc,分别复制一份 php-fpm.conf php-fpm.d/www.conf
  2. cp php-fpm.conf.default php-fpm.conf
  3. cp php-fpm.d/www.conf.default php-fpm.d/www.conf

php-fpm 是Linux系统下 PHP 和 fastCGI 的进程管理器,服务端口默认是9000.

修改配置:

1)进入 /usr/local/php/etc ,修改 php-fpm.conf 文件,将 "pid = run/php-fpm.pid" 注释去掉。

 2)进入 /usr/local/php/etc/php-fpm.d,修改php的服务文件 www.conf

记得重启php服务:php-fpm

将 php-fpm.service 服务文件复制到 systemctl 中

  1. cp /home/local/php-7.2.33/sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
  1. systemctl start php-fpm # 启动php-fpm服务
  2. systemctl enable php-fpm # php-fpm服务设为开机启动

让Nginx支持PHP 

打开Nginx配置文件 nginx.conf,在 server 中添加如下内容。

  1. location ~ .*\.php$ {
  2. fastcgi_pass localhost:9000;
  3. fastcgi_index index.php;
  4. include fastcgi.conf;
  5. }

在nginx的html目录中编写一个包含 phpinfo() 方法的index.php文件,测试效果如下。

让Nginx支持ThinkPHP5框架

修改nginx配置文件。

  1. server {
  2. listen 80;
  3. server_name 192.168.1.22;
  4. root /usr/src/ECommerce;
  5. #charset koi8-r;
  6.  
  7. #access_log logs/host.access.log main;
  8.  
  9. #location / {
  10. #配置PHP的path_info访问模式(Apache支持path_info,而低版本的Nginx并不支持path_info,需要手动转换。高版本的Nginx已支持)
  11. #if (!-e $request_filename){
  12. # rewrite ^(.*)$ /index.php?s=/$1 last; #官网推荐的兼容模式
  13. #}
  14. #index index.php index.html index.htm;
  15. #}
  16.  
  17. #配置以下内容,访问网页时就不会变成下载了!
  18. location ~* .+\.php(.*)$ {
  19. set $script $uri;
  20. set $path_info "/";
  21. if ($uri ~ "^(.+\.php)(/.+)"){
  22. set $script $1;
  23. set $path_info $2;
  24. }
  25.  
  26. fastcgi_pass 192.168.1.22:9000; #与php-fpm.d/www.conf文件中一致
  27. fastcgi_index index.php?IF_REWRITE=1;
  28. include fastcgi.conf;
  29.  
  30. #支持 ?s=/module/controller/action 的url访问模式
  31. fastcgi_param SCRIPT_FILENAME $document_root$script;
  32. fastcgi_param SCRIPT_NAME $script;
  33.  
  34. #支持 index.php/index/index/index 的pathinfo模式
  35. fastcgi_param PATH_INFO $path_info;
  36. }
  37. }

扫一个部署ThinkPHP5遇到的坑

报错提示,如图。

解决办法:数据库配置文件 database.php 中的 hostname 不能是 localhost,改为IP即可。

部署成功!

 

至此。转载请注明出处,记得扫码打赏支持哦,谢谢!

原文链接:http://www.cnblogs.com/wcwnina/p/14672309.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号