centos7配置nginx+php环境 centos7配置nginx+php环境

centos7配置nginx+php环境

一. MySQL安装与配置

1. 配置yum源

# 更新yum源

yum update 
# 下载mysql源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 
# 安装mysql源 
yum localinstall mysql57-community-release-el7-8.noarch.rpm 
# 检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*" 

2. 安装MySQL

yum install mysql-community-server 
3. 启动MySQL

# 启动MySQL服务
systemctl start mysqld 
# 查看MySQL的启动状态
systemctl status mysqld 
# 设置MySQL开机启动
systemctl enable mysqld
systemctl daemon-reload 
4. 修改root默认密码

# 找到root默认密码

grep 'temporary password' /var/log/mysqld.log 

# 进入mysql控制台, 输入上述查询到的默认密码

mysql -uroot -p 

# 设置root管理员的密码

set password for 'root'@'localhost'=password('PassWord123@'); 

5.添加远程登录用户
默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户

# 添加远程帐户

GRANT ALL PRIVILEGES ON *.* TO 'yourname'@'%' IDENTIFIED BY 'YourPassword@123' WITH GRANT OPTION; 

6. 配置默认编码为utf8
修改配置文件 /etc/my.cnf,添加下面两行, utf8编码配置

character_set_server=utf8 
init_connect='SET NAMES utf8' 


二. PHP环境配置
1. 安装 php 和 php-fpm

# 首先安装epel

yum -y install epel-release 

# 安装php php-fpm

yum -y install php php-fpm 

# 查看php版本

php -v 

2. 安装php-mysql

yum install php-mysql 

3. 设置php-fpm开机自动启动

systemctl enable php-fpm 

4. 启动php-fpm

systemctl start php-fpm 

三. Nginx安装与配置


# 下载安装包

wget http://nginx.org/download/nginx-1.10.0.tar.gz 

# 解压Nginx的tar包,并进入解压好的目录

tar -zxvf nginx-1.10.0.tar.gz
cd nginx-1.10.0/ 

# 安装zlib和pcre库

yum -y install zlib zlib-devel
yum -y install pcre pcre-devel 

# 配置、编译并安装

./configure--with-http_ssl_module\
make
make install 

# 启动nginx

/usr/local/nginx/sbin/nginx 

访问服务器后如下图显示说明Nginx运正常。


# nginx 配置访问项目目录并支持 PHP 的 pathinfo 模式配置


server {
        listen       80;
        server_name  xxx.xxxx.com; # 你的域名
	location / {
	    root  /var/www/xxx项目目录/;
	    index index.php;
	}
       	#location ~ ^(.+\.php)(.*)$ {
	   # root           /var/www/xxx项目目录/;
	   # fastcgi_pass   127.0.0.1:9000;
	   # fastcgi_index  index.php;
	   # fastcgi_split_path_info  ^(.+\.php)(.*)$;
	   # fastcgi_param PATH_INFO $fastcgi_path_info;
	  #  if (!-e $document_root$fastcgi_script_name) {
	   #     return 404;
	  #  }
	 #   fastcgi_param  SCRIPT_FILENAME$document_root$fastcgi_script_name;
	#    include        fastcgi_params;  

}

location ~ \.php$ {        try_files $uri =404;         fastcgi_pass 127.0.0.1:9000;         fastcgi_index index.php;          include fastcgi_params;         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;         fastcgi_param PATH_INFO $fastcgi_path_info;       }

}



常用指令
mysql
systemctl start mysqld # 启动
systemctl stop mysqld # 停止
systemctl restart mysqld # 重启
php-fpm
systemctl start php-fpm # 启动
systemctl stop php-fpm # 停止
systemctl restart php-fpm # 重启

后台启动:


查看php-fpm配置文件,因为php-fpm配置文件有一个选项是:

daemonize = yes


nginx
sudo fuser -k 80/tcp # 杀死80端口
/usr/local/nginx/sbin/nginx # 开启
/usr/local/nginx/sbin/nginx -s stop # 停止
/usr/local/nginx/sbin/nginx -s reopen # 重启
/usr/local/nginx/sbin/nginx -s reload # 重新载入配置文件


nginx配置:

php.conf:
server {
    listen       80;
    server_name  ningli.win;

    # note that these lines are originally from the "location /" block
    root   /web/php;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }


    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /web/php$fastcgi_script_name;
        include fastcgi_params;
    }
}
}

https://www.jianshu.com/p/7c0e6c2663fd


分享本文至:

评论 0

挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论