centos7.4部署php项目,centos7下部署运行一个php项目

因为要做web方向的测试,所以选择了一个测试网站addressbook.

这个网站是用php开发的,以前没有接触过php,那么就那这个项目开刀,先将它部署,也记录一下我遇到的问题,大家少走弯路。

Nginx + php-fpm +centos7

首先我先要在chrome上打开,但是服务器站点部署在linux上,而chrome装在windows上,所以选择桥接模式。

Centos7桥接模式设置:

首先选择 桥接模式

ip addr 获取虚拟机ip地址

关闭虚拟机防火墙

systemctl stop firewalld.service

禁止fireware开机启动

systemctl disable firewalld.service

ping xxxx

参考链接:https://www..com/lovenethui/p/6957856.html

刚开始启动nginx时一直报错,最后发现是端口占用问题,解除80端口占用。

先查看80端口是否被占用,然后启动nginx

查看所有端口占用

netstat -tln

查看端口被哪个进程占用

lsof -i:端口号

杀死被占用端口

kill 端口号

接着启动nginx:

/usr/local/nginx/sbin/nginx

检查是否启动成功:

打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。

centos安装nginx以及配置:https://www.jianshu.com/p/9a6c96ecc8b8

为了方便可以进行配置以采用以下命令启动:

service nginx reload 重新加载配置

service nginx start 启动Nginx

如果nginx启动失败,就先强行杀死nginx进程:

pkill nginx

但是每次要进行到相应的路径来启动Nginx太麻烦了,这里可以在etc/init.d目录下创建一个启动脚本,通过这个脚本来启动Nginx,这样启动Nginx会方便很多

在etc/init.d目录下创建nginx脚本

vim /etc/init.d/nginx

#!/bin/sh

#

# nginx - this script starts and stops the nginx daemin

#

# chkconfig: - 85 15

# description: Nginx is an HTTP(S) server, HTTP(S) reverse \

# proxy and IMAP/POP3 proxy server

# processname: nginx

# config: /usr/local/nginx/conf/nginx.conf

# pidfile: /usr/local/nginx/logs/nginx.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {

[ -x $nginx ] || exit 5

[ -f $NGINX_CONF_FILE ] || exit 6

echo -n $"Starting $prog: "

daemon $nginx -c $NGINX_CONF_FILE

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile

return $retval

}

stop() {

echo -n $"Stopping $prog: "

killproc $prog -QUIT

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

}

restart() {

configtest || return $?

stop

start

}

reload() {

configtest || return $?

echo -n $"Reloading $prog: "

killproc $nginx -HUP

RETVAL=$?

echo

}

force_reload() {

restart

}

configtest() {

$nginx -t -c $NGINX_CONF_FILE

}

rh_status() {

status $prog

}

rh_status_q() {

rh_status >/dev/null 2>&1

}

case "$1" in

start)

rh_status_q && exit 0

$1

;;

stop)

rh_status_q || exit 0

$1

;;

restart|configtest)

$1

;;

reload)

rh_status_q || exit 7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q || exit 0

;;

*)

echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

exit 2

esac

作者:ayuLiao

链接:https://www.jianshu.com/p/495a02eb2672

來源:

著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

我们启动php-fpm,并设置php-fpm开机自启

service php-fpm start

chkconfig php-fpm on

nginx配置文件地址路径:

vim /usr/local/nginx/conf/nginx.conf

php-fpm配置

vim /etc/php-fpm.d/www.conf

[...]

listen = /var/run/php-fpm/php-fpm.sock

[...]

listen.owner = nobody

listen.group = nobody

[...]

user = nginx

group = nginx

[...]

编辑nginx配置文件:vim /etc/nginx/nginx.conf

server {

28 listen 80;

29 server_name _;

30 root /usr/addressbook;

31 index index.php index.html index.htm;

32

33 location / {

41 try_files $uri $uri/ =404;

42 }

43 location ~ \.php$ {

44 try_files $uri =404;

45 fastcgi_pass 127.0.0.1:9000;

46 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

47 fastcgi_index index.php; include fastcgi_params;

48 }

49 }

50 }

同时php-fpm配置文件也要更改:

listen =/var/run/php-fpm/php-fpm.sock

listen = 127.0.0.1:9000

重新加载:

systemctl reload php-fpm

80a8f34cb63633a831f670ab3151b6e2.png

好啦,大功告成,现在我要去配置数据库啦~~~

大家有什么关于web测试或者MBT的想法可以一起交流呀

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值