当前位置:   article > 正文

ubuntu20安装nginx、php、mysql以及xdebug的部署

ubuntu20安装nginx、php、mysql以及xdebug的部署

目录

1、更改镜像源

2、安装依赖包

3、安装nginx

4、编译nginx

5、启动nginx

6、访问nginx

7、增加源地址、更新、安装

8、安装php

9、配置php-fpm

10、启动php-fpm

11、mysql安装

12、vscode的debug安装

13、下载并安装php相应版本的xdebug

打开访问php的界面访问源码

下载

安装

phpize后,查看下列数字是否于官网给的一致

继续安装,./configure报错,是应为php-config版本没修改,

编译安装

重启php服务

14、访问检测xdebug


1、更改镜像源

镜像本身的镜像源大概率不可用,需要更改成可用镜像源;可以更新一下,看看是否可用

apt update

不可用的话,可以换下列镜像源,换源之前可以下载ssh、vim的服务,以便更快速换源

  1. # 默认注释了源码仓库,如有需要可自行取消注释
  2. deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
  3. # deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
  4. deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
  5. # deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
  6. deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
  7. # deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
  8. deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
  9. # deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
  10. # 预发布软件源,不建议启用
  11. # deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
  12. # deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

再次更新,检查是否可用

apt update

2、安装依赖包

  1. apt-get install gcc
  2. apt-get install libpcre3 libpcre3-dev
  3. apt-get install zlib1g zlib1g-dev
  4. sudo apt-get install openssl
  5. sudo apt-get install libssl-dev

3、安装nginx

  1. cd /usr/local
  2. mkdir nginx
  3. cd nginx
  4. wget https://nginx.org/download/nginx-1.26.1.tar.gz
  5. tar -xvf nginx-1.21.6.tar.gz

4、编译nginx

  1. cd /usr/local/nginx/nginx-1.21.6
  2. # 执行命令
  3. # 在当前目录下安装
  4. ./configure
  5. # 或指定安装目录
  6. ./configure --prefix=/home/centos/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module
  7. # 执行make命令
  8. make
  9. # 执行make install命令
  10. make install

5、启动nginx

  1. cd /usr/local/nginx/sbin
  2. # 启动nginx
  3. ./nginx

6、访问nginx

可能会访问不成功,应为Linux本身会安装一个Apache服务,与nginx服务端口有冲突,将Apache服务进程杀死就OK了

  1. lsof -i:80
  2. netstat -tunlp |grep 80
  3. kill -9 [PID]

7、增加源地址、更新、安装

  1. # 添加php源地址
  2. sudo apt-get install software-properties-common
  3. sudo add-apt-repository -y ppa:ondrej/php
  4. # 更新
  5. sudo apt-get update
  6. # 安装
  7. sudo apt-get install php7.1

8、安装php

nginx使用php的话要用到php7.3-fpm,所以要安装

sudo apt-get install php7.3-mysql php7.3-fpm php7.3-curl php7.3-xml php7.3-gd php7.3-mbstring php-memcached php7.3-zip

9、配置php-fpm

把监听端口改掉

  1. vim /etc/php/7.3/fpm/pool.d/www.conf
  2. ;listen = /run/php/php7.3-fpm.sock
  3. listen = 127.0.0.1:9000

10、启动php-fpm

sudo service php7.3-fpm start

查看9000端口

netstat -lnt | grep 9000

进入alternatives文件夹下,查看php其他配置

  1. cd /etc/alternatives
  2. ls -al

修改nginx配置文件,不然php文件无法访问

vim /usr/local/nginx/conf/nginx.conf
  1. user www-data;
  2. location / {
  3. root html;
  4. index index.html index.htm index.php;
  5. }
  6. location ~ \.php$ {
  7. root html;
  8. fastcgi_pass 127.0.0.1:9000;
  9. fastcgi_index index.php;
  10. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  11. include fastcgi_params;
  12. }

重启nginx服务

  1. cd /usr/local/nginx/sbin
  2. ./nginx -s reload

编写一个测试文件访问

  1. cd /usr/local/nginx/html
  2. vim web.php
  3. <?php
  4. phpinfo();
  5. ?>

访问web.php,如下就成功了

11、mysql安装

  1. # 直接apt安装最新版本
  2. apt install -y mysql
  3. # 启动mysql服务
  4. systemctl start mysql
  5. # 查看mysql服务状态
  6. systemctl status mysql
  7. # Linux下mysql默认安装没有密码,直接回车进入
  8. mysql -uroot -p
  9. # 修改密码
  10. alter user 'root'@'localhost' identified with mysql_native_password by '123456';

12、vscode的debug安装

打开vscode,点开扩展,安装remote和debug,便于后面代码调试

在debug插件里面,访问xdebug官网,点击蓝色字体

浏览器会跳转到这个页面

13、下载并安装php相应版本的xdebug

打开访问php的界面访问源码

将源码复制到xdebug里面,会给你推荐相应版本和安装步骤

下载

wget https://xdebug.org/files/xdebug-3.1.6.tgz

安装

  1. # 安装扩展
  2. apt-get install php7.3-dev autoconf automake
  3. # 解压
  4. tar -xvzf xdebug-3.1.6.tgz
  5. # 安装
  6. cd xdebug-3.1.6
  7. phpize

phpize后,查看下列数字是否于官网给的一致

不一致,是phpize版本不对,需要切换版本

update-alternatives --config phpize

修改后,就一致了

继续安装,./configure报错,是应为php-config版本没修改,

./configure
  1. root@yw:~/xdebug-3.1.6# ./configure
  2. checking for grep that handles long lines and -e... /usr/bin/grep
  3. checking for egrep... /usr/bin/grep -E
  4. checking for a sed that does not truncate output... /usr/bin/sed
  5. checking for cc... cc
  6. checking whether the C compiler works... yes
  7. checking for C compiler default output file name... a.out
  8. checking for suffix of executables...
  9. checking whether we are cross compiling... no
  10. checking for suffix of object files... o
  11. checking whether we are using the GNU C compiler... yes
  12. checking whether cc accepts -g... yes
  13. checking for cc option to accept ISO C89... none needed
  14. checking how to run the C preprocessor... cc -E
  15. checking for icc... no
  16. checking for suncc... no
  17. checking whether cc understands -c and -o together... yes
  18. checking for system library directory... lib
  19. checking if compiler supports -R... no
  20. checking if compiler supports -Wl,-rpath,... yes
  21. checking build system type... x86_64-pc-linux-gnu
  22. checking host system type... x86_64-pc-linux-gnu
  23. checking target system type... x86_64-pc-linux-gnu
  24. checking for PHP prefix... /usr
  25. checking for PHP includes... -I/usr/include/php/20160303 -I/usr/include/php/20160303/main -I/usr/include/php/20160303/TSRM -I/usr/include/php/20160303/Zend -I/usr/include/php/20160303/ext -I/usr/include/php/20160303/ext/date/lib
  26. checking for PHP extension directory... /usr/lib/php/20160303
  27. checking for PHP installed headers prefix... /usr/include/php/20160303
  28. checking if debug is enabled... no
  29. checking if zts is enabled... no
  30. checking for re2c... no
  31. configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
  32. checking for gawk... no
  33. checking for nawk... nawk
  34. checking if nawk is broken... no
  35. checking whether to enable Xdebug support... yes, shared
  36. checking whether to enable Xdebug developer build flags... no
  37. checking whether to compress profiler files (requires zlib)... yes
  38. checking Check for supported PHP versions... configure: error: not supported. Need a PHP version >= 7.2.0 and < 8.2.0 (found 7.1.33-64+ubuntu20.04.1+deb.sury.org+1)
  39. root@yw:~/xdebug-3.1.6#

修改一下版本

update-alternatives --config php-config

再次运行./configure;就成功了

  1. root@yw:~/xdebug-3.1.6# ./configure
  2. checking for grep that handles long lines and -e... /usr/bin/grep
  3. checking for egrep... /usr/bin/grep -E
  4. checking for a sed that does not truncate output... /usr/bin/sed
  5. checking for cc... cc
  6. checking whether the C compiler works... yes
  7. checking for C compiler default output file name... a.out
  8. checking for suffix of executables...
  9. checking whether we are cross compiling... no
  10. checking for suffix of object files... o
  11. checking whether we are using the GNU C compiler... yes
  12. checking whether cc accepts -g... yes
  13. checking for cc option to accept ISO C89... none needed
  14. checking how to run the C preprocessor... cc -E
  15. checking for icc... no
  16. checking for suncc... no
  17. checking whether cc understands -c and -o together... yes
  18. checking for system library directory... lib
  19. checking if compiler supports -R... no
  20. checking if compiler supports -Wl,-rpath,... yes
  21. checking build system type... x86_64-pc-linux-gnu
  22. checking host system type... x86_64-pc-linux-gnu
  23. checking target system type... x86_64-pc-linux-gnu
  24. checking for PHP prefix... /usr
  25. checking for PHP includes... -I/usr/include/php/20180731 -I/usr/include/php/20180731/main -I/usr/include/php/20180731/TSRM -I/usr/include/php/20180731/Zend -I/usr/include/php/20180731/ext -I/usr/include/php/20180731/ext/date/lib
  26. checking for PHP extension directory... /usr/lib/php/20180731
  27. checking for PHP installed headers prefix... /usr/include/php/20180731
  28. checking if debug is enabled... no
  29. checking if zts is enabled... no
  30. checking for re2c... no
  31. configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
  32. checking for gawk... no
  33. checking for nawk... nawk
  34. checking if nawk is broken... no
  35. checking whether to enable Xdebug support... yes, shared
  36. checking whether to enable Xdebug developer build flags... no
  37. checking whether to compress profiler files (requires zlib)... yes
  38. checking Check for supported PHP versions... supported (7.3.33-20+ubuntu20.04.1+deb.sury.org+1)
  39. checking for clock_gettime... yes
  40. checking for clock_gettime_nsec_np... no
  41. checking for gettimeofday... yes
  42. checking for ANSI C header files... yes
  43. checking for sys/types.h... yes
  44. checking for sys/stat.h... yes
  45. checking for stdlib.h... yes
  46. checking for string.h... yes
  47. checking for memory.h... yes
  48. checking for strings.h... yes
  49. checking for inttypes.h... yes
  50. checking for stdint.h... yes
  51. checking for unistd.h... yes
  52. checking netinet/in.h usability... yes
  53. checking netinet/in.h presence... yes
  54. checking for netinet/in.h... yes
  55. checking poll.h usability... yes
  56. checking poll.h presence... yes
  57. checking for poll.h... yes
  58. checking sys/poll.h usability... yes
  59. checking sys/poll.h presence... yes
  60. checking for sys/poll.h... yes
  61. checking for cos in -lm... yes
  62. checking for pkg-config... /usr/bin/pkg-config
  63. checking pkg-config is at least version 0.9.0... yes
  64. checking for zlib >= 1.2.9... yes
  65. checking how to print strings... printf
  66. checking for a sed that does not truncate output... (cached) /usr/bin/sed
  67. checking for fgrep... /usr/bin/grep -F
  68. checking for ld used by cc... /usr/bin/ld
  69. checking if the linker (/usr/bin/ld) is GNU ld... yes
  70. checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
  71. checking the name lister (/usr/bin/nm -B) interface... BSD nm
  72. checking whether ln -s works... yes
  73. checking the maximum length of command line arguments... 1572864
  74. checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
  75. checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
  76. checking for /usr/bin/ld option to reload object files... -r
  77. checking for objdump... objdump
  78. checking how to recognize dependent libraries... pass_all
  79. checking for dlltool... no
  80. checking how to associate runtime and link libraries... printf %s\n
  81. checking for ar... ar
  82. checking for archiver @FILE support... @
  83. checking for strip... strip
  84. checking for ranlib... ranlib
  85. checking for gawk... (cached) nawk
  86. checking command to parse /usr/bin/nm -B output from cc object... ok
  87. checking for sysroot... no
  88. checking for a working dd... /usr/bin/dd
  89. checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
  90. checking for mt... mt
  91. checking if mt is a manifest tool... no
  92. checking for dlfcn.h... yes
  93. checking for objdir... .libs
  94. checking if cc supports -fno-rtti -fno-exceptions... no
  95. checking for cc option to produce PIC... -fPIC -DPIC
  96. checking if cc PIC flag -fPIC -DPIC works... yes
  97. checking if cc static flag -static works... yes
  98. checking if cc supports -c -o file.o... yes
  99. checking if cc supports -c -o file.o... (cached) yes
  100. checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
  101. checking whether -lc should be explicitly linked in... no
  102. checking dynamic linker characteristics... GNU/Linux ld.so
  103. checking how to hardcode library paths into programs... immediate
  104. checking whether stripping libraries is possible... yes
  105. checking if libtool supports shared libraries... yes
  106. checking whether to build shared libraries... yes
  107. checking whether to build static libraries... no
  108. configure: creating ./config.status
  109. config.status: creating config.h
  110. config.status: executing libtool commands
  111. root@yw:~/xdebug-3.1.6#

编译安装

  1. make
  2. cp modules/xdebug.so /usr/lib/php/20180731/
  3. cd /etc/php/7.3/fpm/
  4. vim php.ini
  5. [Xdebug]
  6. zend_extension=/usr/lib/php/20180731/xdebug.so
  7. xdebug.remote_enable = 1
  8. xdebug.remote_autostart = 1
  9. xdebug.remote_port = 9003

重启php服务

service php7.3-fpm restart

14、访问检测xdebug

ctrl+f输入xdebug发现有131处,表示安装成功

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号