一、nginx
1: 下载 http://nginx.org/en/download.html
选择 stable 版本下载

2: 解压
tar zxf nginx.xxxx.tar.gz

3: 配置
cd /usr/local/src/nginx里面
./configure --prefix=/usr/local/nginx
如果提示缺少 pcre 库,
则从 http://www.pcre.org/
假设解压在/usr/local/src/pcre-8.37
进入cd /usr/local/src/nginx 编译

make&& manke install

4.成功 安装在 usr/local/nginx

5.启动nginx
cd /usr/local/nginx
启动 ./sbin/nginx

-
启动时,极易出现端口被占的错误,如下
image.png
7: 连接,从局域网内连接 nginx,
如果连接不能,先 ping 测试,2 台机器之间网络是否通,
再在服务器上 telnet localhost 80
如果 2 者都能,但外界连不上 80 端口,则是防火墙的原因.
service iptables stop
再次连接,出现以下界面,则安装成功

二、php
1.编译安装 PHP
先安装扩展 yum install gd zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng
libpng-devel
2.wget 下载php 到目录 /usr/local/src/

2.1 解压 tar jxvf php-7.0.6.tar.bz2
2.2 cd php-7.0.6

2.3编译
解压,cd 到 php-5.x
编译
./configure --prefix=/usr/local/php \
--with-gd \
--enable-gd-native-ttf \
--enable-mysqlnd \
--with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--enable-mbstring \
--enable-fpm
安装
make && make install

3.运行php

3.1出错 缺失文件


3.2 运行步骤
cd /usr/local/php
拷贝文件
cp etc/php-fpm.conf.default etc/php-fpm.conf
源码文件 拷贝php.ini
cp /usr/local/src/php-5.5.13/php.ini-development ./lib/php.ini
./sbin/php-fpm

三、整合 nginx 和 PHP
cd /usr/local/nginx 到安装目录下
cd conf/
vim nginx.conf 打开这个文件



让 nginx 的最新配置文件生效
./sbin/nginx -s reload 重启
再次请求 xx.php,看到如下类似效果,即整合成功


四、CentOS7安装mysql5.5
4.1、检查本地是否安装过其他版本的mysql
rpm -qa|grep -i mysql

由于有些版本自带的有mariadb,检查是否有mariadb,若是有需要先卸载
yum -y remove maria*

4.2、下载mysql 5.5的服务器和客户端的安装包
下载服务器包:wget https://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-server-5.5.59-1.el7.x86_64.rpm
下载客户端包:wget https://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-client-5.5.59-1.el7.x86_64.rpm
若提示:-bash: wget: 未找到命令,则表明没有安装wget,执行安装命令:yum -y install wget
4.3、安装服务器和客户端
rpm -ivh --nodeps MySQL-server-5.5.59-1.el7.x86_64.rpm
rpm -ivh --nodeps MySQL-client-5.5.59-1.el7.x86_64.rpm
# --nodeps就是安装时不检查依赖关系,比如A.rpm需要B.rpm,但是没装B,这样就装不上,用了--nodeps就能装上了。
查看安装的mysql是否已安装成功 :rpm -qa|grep -i mysql

4.4、启动mysql并设置mysql服务开机自启动
启动mysql:service mysql start
设置开机自启动:systemctl enable mysql
验证自启动是否成功:chkconfig --list|grep mysql

3,4,5都是开则说明设置成功
4.5、登录mysql并设置密码
mysql -uroot
set password=password('root');

4.6、开启mysql的远程登录
grant all privileges on *.* to 'root'@'%' identified by 'root'; #权限放大到任何一台机器都可以远程登录
flush privileges;

关闭防火墙:systemctl stop firewalld
设置开机禁用防火墙:systemctl disable firewalld.service

systemctl和防火墙firewalld命令 见下图
一、防火墙的开启、关闭、禁用命令
(1)设置开机启用防火墙:systemctl enable firewalld.service
(2)设置开机禁用防火墙:systemctl disable firewalld.service
(3)启动防火墙:systemctl start firewalld
(4)关闭防火墙:systemctl stop firewalld
(5)检查防火墙状态:systemctl status firewalld
二、使用firewall-cmd配置端口
(1)查看防火墙状态:firewall-cmd --state
(2)重新加载配置:firewall-cmd --reload
(3)查看开放的端口:firewall-cmd --list-ports
(4)开启防火墙端口:firewall-cmd --zone=public --add-port=9200/tcp --permanent
命令含义:
–zone #作用域
–add-port=9200/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
注意:添加端口后,必须用命令firewall-cmd --reload重新加载一遍才会生效
(5)关闭防火墙端口:firewall-cmd --zone=public --remove-port=9200/tcp --permanent
五、thinkphp5.1官网推荐配置
按照官网要求做的全部配置代码:
server {
listen 80 ;
server_name www.d5.com;
root /var/www/tptest/public;
index index.php index.html ;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
}
location ~ \.php {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
}
}
六、上传thinkphp项目到Nginx下访问报错解决
问题:
file_put_contents(/usr/local/nginx/html/zh/runtime/temp/46fbd9967d0da6b1fa7264089cc6c118.php): failed to open stream: Permission denied

tp5.1通过WinSCP上传到服务器时访问报错
原因是文件上传时权限被修改了
直接到项目文件夹下给Nginx授予文件执行权限
cd /usr/local/nginx/html/
setfacl -m u:nginx:rwx -R ../html
//或者 chown -R 777
七、Centos 文件权限修改
1.查看权限
ls -l dirPath
2.修改权限,root权限执行(-R 子目录的权限都会改变)
网友评论