CENTOS7 下部署php环境
作者:nango
阅读:1489次
来源:原创
时间:2016-09-23 19:56
首先安装nginx: 依照nginx官网的步骤: 1:首先添加NGINX yum仓库,以便后续yum安装nginx。在/etc/yum.repos.d/目录下,新建nginx.repo文件,并且粘贴一下内容: ```shell [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1 ``` 2:直接`yum install -y nginx`,一切就是这么简单。 安装完毕后,重启nginx `systemctl start nginx` 在浏览器输入本地ip或者127.0.0.1,显示nginx相关欢迎信息就安装成功了! `/usr/share/nginx/html/` 默认根目录 yum安装`php、php-fp`m环境 1,直接`yum install -y php php-fpm` 2, 安装完毕后接着配置nginx,使它支持php 配置`/etc/nginx/conf.d/default.conf`文件如下: 红色字体为添加、修改 ```shell server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { root /usr/share/nginx/html;//配置默认网站根目录 index index.php index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #打开php环境支持并配置根目录 location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } ``` 然后重启nginx和php-fpm,在`/usr/share/nginx/html`下新建index.php并输入 ```php <?php echo phpinfo(); ?> ``` 保存退出。 浏览器地址栏输入,127.0.0.1,会出现php相关信息。 默认安装为php5.4版本,升级指导: 执行下面的命令升级软件仓库 ` rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm ` 执行下面的命令删除php `yum remove php-common` 然后像安装那样问你是否继续的,输入yes即可 安装php 5.6版本(php56w-devel这个不是必需的) `yum install -y php56w php56w-opcache php56w-xml php56w-mcrypt php56w-gd php56w-devel php56w-mysql php56w-intl php56w-mbstring php56w-fpm` php56w-fpm nginx下一定要安装,否则将无法启动php-fpm yum安装mariadb数据库 centos下yum暂时没有mysql-server直接安装包; MariaDB是MySQL社区开发的分支,也是一个增强型的替代品;它完全兼容mysql,语法全部相同,如果mysql闭源,则它是个不错的替代品 `yum -y install mariadb-server mariadb mariadb-devel` 安装完毕 `systemctl start mariadb` 默认root登录密码为空, `[root@wyn ~]# mysql -uroot -p` ```markdown MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) ``` 连接成功,如上显示。 nginx 配置虚拟主机 在`nginx.conf` 中, ```markdown http{ #添加 server { listen 80; server_name www.xxx.com; location / { #网站指向的目录 root /usr/share/nginx/html/; index index.php index.html index.htm; if (!-e $request_filename) {//url重写, rewrite方式代替php中的PATH_INFO rewrite ^(.*)$ /index.php?s=/$1 last; break; } } location ~ \.php$ { root /usr/share/nginx/html/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } ``` 也可以单独出来一个conf文件中直接键入server{}这段代码。 这里配置完毕一定要在,`hosts文件中添加 127.0.0.1 www.xxx.com` nginx 负载均衡配置 在conf.d/ 下新建balance.conf,打开balance.conf文件,写入 ```markdown upstream www.l.com { server 198.198.200.29:80 weight=5; server 198.198.200.28:80 weight=5; } server { listen 80; server_name www.l.com; location / { proxy_set_header Host $host; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://www.l.com; } } ``` 这里www.l.com是你需要负载均衡的域名,server 198.198.200.29:80 weight=5;这个是你负载的几个服务器地址, weight意思是要按照权重来进行负载,weight越大被调用的几率越大,具体可以查看nginx负载均衡相关资料。 如果要在代理服务器部署代码,必须将web端口和代理监听端口分割开,一个启用80.一个8000或者其他 修改 nginx.conf 文件实现。在 Linux 上该文件的路径为 /usr/local/nginx/conf/nginx.conf,将80端口改为8000(任意端口)即可 windows wamp在默认情况下只允许本地访问,外网不允许访问,如果外网需要访问,也会提示(403 Forbidden)错误 ```markdown 找到279行的:Require local; 将:Require local;替换为:Require all granted; ```
NANGO
首 页
编程
聊天室
简介:
欢迎大家光临nango的博客,该博客由NoneCms搭建而成。
文章分类
PHP
js
centos
Python
MySQL
Laravel
最新文章
NoneCms 重大bug更新
docker compose编排的php开发环境
NoneCms 基于workerman的聊天室具体使用
centos7 + sendmail + php mail()函数实现邮件发送
文章归档
2018-12 (2)
2018-09 (1)
2018-01 (1)
2017-10 (1)
2017-07 (2)
2017-06 (2)
2017-03 (1)
2017-02 (2)
2017-01 (2)
2016-11 (4)
2016-10 (5)
2016-09 (3)
您的浏览器不支持 canvas.
© Nango
NANGO
文章分类