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的服务,以便更快速换源

# 默认注释了源码仓库,如有需要可自行取消注释
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

再次更新,检查是否可用

apt update

2、安装依赖包

apt-get install gcc
apt-get install libpcre3 libpcre3-dev
apt-get install zlib1g zlib1g-dev
sudo apt-get install openssl 
sudo apt-get install libssl-dev

3、安装nginx

cd /usr/local

mkdir nginx

cd nginx

wget https://nginx.org/download/nginx-1.26.1.tar.gz

tar -xvf nginx-1.21.6.tar.gz

4、编译nginx

cd /usr/local/nginx/nginx-1.21.6
# 执行命令
# 在当前目录下安装
./configure
# 或指定安装目录
./configure --prefix=/home/centos/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module

# 执行make命令

make

# 执行make install命令

make install

5、启动nginx

cd /usr/local/nginx/sbin


# 启动nginx


./nginx

6、访问nginx

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

lsof  -i:80

netstat -tunlp |grep 80

kill -9 [PID]

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

# 添加php源地址
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ondrej/php
# 更新
sudo apt-get update
# 安装
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

把监听端口改掉

vim /etc/php/7.3/fpm/pool.d/www.conf

;listen = /run/php/php7.3-fpm.sock
listen = 127.0.0.1:9000

10、启动php-fpm

sudo service php7.3-fpm start

查看9000端口

netstat -lnt | grep 9000

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

cd /etc/alternatives
ls -al

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

vim /usr/local/nginx/conf/nginx.conf
user  www-data;

location / {
            root   html;
            index  index.html index.htm index.php;
        }

 
location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

重启nginx服务

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

编写一个测试文件访问

cd /usr/local/nginx/html
vim web.php

<?php
phpinfo();
?>

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

11、mysql安装

# 直接apt安装最新版本
apt install -y mysql
# 启动mysql服务
systemctl start mysql
# 查看mysql服务状态
systemctl status mysql
# Linux下mysql默认安装没有密码,直接回车进入
mysql -uroot -p
# 修改密码
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

安装

# 安装扩展
apt-get install php7.3-dev autoconf automake
# 解压
tar -xvzf xdebug-3.1.6.tgz
# 安装
cd xdebug-3.1.6

phpize

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

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

update-alternatives --config phpize

修改后,就一致了

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

./configure
root@yw:~/xdebug-3.1.6# ./configure
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr
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
checking for PHP extension directory... /usr/lib/php/20160303
checking for PHP installed headers prefix... /usr/include/php/20160303
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking whether to enable Xdebug support... yes, shared
checking whether to enable Xdebug developer build flags... no
checking whether to compress profiler files (requires zlib)... yes
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)
root@yw:~/xdebug-3.1.6#

修改一下版本

update-alternatives --config php-config

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

root@yw:~/xdebug-3.1.6# ./configure
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr
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
checking for PHP extension directory... /usr/lib/php/20180731
checking for PHP installed headers prefix... /usr/include/php/20180731
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking whether to enable Xdebug support... yes, shared
checking whether to enable Xdebug developer build flags... no
checking whether to compress profiler files (requires zlib)... yes
checking Check for supported PHP versions... supported (7.3.33-20+ubuntu20.04.1+deb.sury.org+1)
checking for clock_gettime... yes
checking for clock_gettime_nsec_np... no
checking for gettimeofday... yes
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking netinet/in.h usability... yes
checking netinet/in.h presence... yes
checking for netinet/in.h... yes
checking poll.h usability... yes
checking poll.h presence... yes
checking for poll.h... yes
checking sys/poll.h usability... yes
checking sys/poll.h presence... yes
checking for sys/poll.h... yes
checking for cos in -lm... yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for zlib >= 1.2.9... yes
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) nawk
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: creating ./config.status
config.status: creating config.h
config.status: executing libtool commands
root@yw:~/xdebug-3.1.6#

编译安装

make

cp modules/xdebug.so /usr/lib/php/20180731/


cd /etc/php/7.3/fpm/
vim php.ini
[Xdebug]
zend_extension=/usr/lib/php/20180731/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9003

重启php服务

service php7.3-fpm restart

14、访问检测xdebug

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值