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

首先更新系統軟件php

$ yum update

第一步:安裝nginx

1.安裝nginxhtml

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

2.安裝nginxmysql

$ yum install nginx

3.啓動nginxnginx

$ service nginx start

Redirecting to /bin/systemctl start  nginx.servicesql

 

4.訪問http://你的ip/json

 

若是成功安裝會出來nginx默認的歡迎界面vim

 

第二步:安裝mysql

RPM安裝MySQLcentos

 

1.下載安裝包api

 

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

 

2.準備session

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/
相關文章
相關標籤/搜索