当前位置: 首页 > news >正文

Cenos7下nginx+mysql+php环境的搭建

首先更新系统软件

$ yum update

第一步:安装nginx

1.安装nginx

$ yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2.安装nginx

$ yum install nginx

3.启动nginx

$ service nginx start

Redirecting to /bin/systemctl start  nginx.service

 

4.访问http://你的ip/

 

如果成功安装会出来nginx默认的欢迎界面

 

第二步:安装mysql

RPM安装MySQL

 

1.下载安装包

 

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

 

2.准备

rpm -ivh mysql-community-release-el7-5.noarch.rpm

3.安装mysql

yum install -y mysql-community-server

4.成功安装之后重启mysql服务:

service mysqld restart 
或 
systemctl restart mysqld.service

初次安装mysql是root账户是没有密码的:

  mysql -u root -p   遇到密码提示,回车即可进入

 

设置root密码的方法:

       quit;             退出mysql

   mysqladmin -u root password "root"     设置密码
 
进入mysql:
  mysql -u root -p
  Enter Password: root
 
设置mysql最大连接数:
  执行sql:set global max_connections = 3000; (重启mysql后失效)

第三步:PHP源码安装:

1. 下载源码包

 

wget http://cn2.php.net/distributions/php-5.6.3.tar.gz

 

2.解压

 

tar zxvf php-5.6.3.tar.gz

 

3.

cd php-5.6.3

 

4.安装php依赖包

yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl 
libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

libmcrypt 和libmcrypt-devel 依赖包

yum  install epel-release      //扩展包更新包
yum  update                       //更新yum源
yum install libmcrypt libmcrypt-devel mcrypt mhash       就ok了

 

5.编译配置,这一步我们会遇到很多configure error,我们一一解决,基本都是相关软件开发包没有安装导致

 ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx  \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared  \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir  \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets  \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache

6.编译与安装

make && make install

这里要make好久,要耐心一下

 

 

7.添加 PHP 命令到环境变量

vim /etc/profile

在末尾加入

PATH=$PATH:/usr/local/php/bin

export PATH

要使改动立即生效执行

./etc/profile

source /etc/profile

查看环境变量

echo $PATH

查看php版本

php -v

8.配置php-fpm

   cp php.ini-production /etc/php.ini

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

9.启动php-fpm

/etc/init.d/php-fpm start

10.配置nginx虚拟机,绑定域名

vim /etc/nginx/conf.d/default.conf

把下面的内容复制到default.conf

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
        root /usr/share/nginx/html;
        index  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
    #
    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;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

原文件:

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.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
    #
    location ~ \.php$ {
        root           /var/www/;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$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;
    #}
}

2.重启nginx

service nginx reload

 3.更改目录文件权限

chmod -R 777 /var/www/

 

转载于:https://www.cnblogs.com/kuics/p/6025453.html

相关文章:

  • Linux实用工具
  • 李洪强经典面试题42
  • Spring3 MVC详解
  • 2:jquery.cookie用法详细解析
  • 新浪微博客户端(21)-获取当前微博未读数并提示用户
  • Distributed Configuration Management Platform(分布式配置管理平台)
  • centos系统的时间时区和MySQL的时间时区问题
  • java架构师之路:推荐的15本书
  • 学习python cgi的一点心得体会
  • Linux用户管理 (3)
  • linux下cat命令详解
  • “达观杯”文本分类挑战赛新手入门代码
  • Maven类包冲突终极解决方案
  • CDIF: 基于REST和JSON的SOA软件框架
  • 步步为营 .NET 设计模式学习笔记 二十四、Factory Method(工厂方法模式)
  • 时间复杂度分析经典问题——最大子序列和
  • 〔开发系列〕一次关于小程序开发的深度总结
  • ERLANG 网工修炼笔记 ---- UDP
  • mysql常用命令汇总
  • Mysql数据库的条件查询语句
  • Swoft 源码剖析 - 代码自动更新机制
  • 彻底搞懂浏览器Event-loop
  • 翻译--Thinking in React
  • 构造函数(constructor)与原型链(prototype)关系
  • 基于web的全景—— Pannellum小试
  • 精彩代码 vue.js
  • 来,膜拜下android roadmap,强大的执行力
  • 前端之Sass/Scss实战笔记
  • 设计模式 开闭原则
  • 实战:基于Spring Boot快速开发RESTful风格API接口
  • 数组大概知多少
  • 微服务入门【系列视频课程】
  • 微信小程序实战练习(仿五洲到家微信版)
  • 小程序 setData 学问多
  • - 语言经验 - 《c++的高性能内存管理库tcmalloc和jemalloc》
  • 阿里云ACE认证学习知识点梳理
  • ​水经微图Web1.5.0版即将上线
  • #1015 : KMP算法
  • #基础#使用Jupyter进行Notebook的转换 .ipynb文件导出为.md文件
  • ( 10 )MySQL中的外键
  • (1)虚拟机的安装与使用,linux系统安装
  • (附源码)ssm学生管理系统 毕业设计 141543
  • (十)T检验-第一部分
  • (转)setTimeout 和 setInterval 的区别
  • (转)项目管理杂谈-我所期望的新人
  • (转载)OpenStack Hacker养成指南
  • (轉貼) VS2005 快捷键 (初級) (.NET) (Visual Studio)
  • (最全解法)输入一个整数,输出该数二进制表示中1的个数。
  • *p=a是把a的值赋给p,p=a是把a的地址赋给p。
  • .net Application的目录
  • .NET Micro Framework 4.2 beta 源码探析
  • .Net的C#语言取月份数值对应的MonthName值
  • @cacheable 是否缓存成功_让我们来学习学习SpringCache分布式缓存,为什么用?
  • @ComponentScan比较
  • [ IO.File ] FileSystemWatcher