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

首先更新系統軟件php

1html

$ yum updatemysql

第一步:安裝nginx

1.安裝nginx源nginx

1sql

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

2.安裝nginxvim

1centos

$ yum install nginxcurl

3.啓動nginxsocket

1

$ service nginx start

Redirecting to /bin/systemctl start  nginx.service

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

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

第二步:安裝mysql

RPM安裝MySQL:

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpmyum install -y mysql-community-server

 

成功安裝以後重啓mysql服務:

  service mysqld restart 或 systemctl restart mysqld.service

初次安裝mysql是root帳戶是沒有密碼的:

mysql -u root -p   遇到密碼提示,回車便可進入

 

第三步:PHP源碼安裝:

1. 下載源碼包並解壓:

wget http://cn2.php.net/distributions/php-5.6.3.tar.gz
tar zxvf php-5.6.3.tar.gz
cd php-5.6.3
 
2.安裝依賴輸入命令

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依賴沒法安裝,本身能夠去網上找解決辦法

 

3. 配置

./configure --with-libdir=lib64 --prefix=/usr/local/php --with-mysql --with-mysqli --with-pdo-mysql --enable-inline-optimization --enable-fpm --with-freetype-dir --with-gd --with-zlib --with-png-dir --with-jpeg-dir --enable-mbstring --with-iconv --enable-sockets --with-curl  --with-openssl --enable-pcntl --enable-soap

 

4. 編譯安裝:

  make && make install

5.添加 PHP 命令到環境變量

1

$ vim /etc/profile

 

在末尾加入

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

export PATH

要使改動當即生效執行

1

$ ./etc/profile

或 

1

source /etc/profile

查看環境變量

1

echo $PATH

查看php版本

1

$ php -v

 

6.配置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

 

7.啓動php-fpm

1

$ /etc/init.d/php-fpm start

 

八、輸入命令

 

cd  /etc/conf.d

vi  default.conf

 

配置根目錄:

server {

    listen       80;

    server_name  localhost;

 

    #charset koi8-r;

    #access_log  /var/log/nginx/log/host.access.log  main;

 

    location / {

        root   /usr/www;  //根目錄

        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/www;  //根目錄

 

    }

 

    # 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/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;

    #}

}

 

重啓nginx

service nginx reload

 

在根目錄寫一段程序,測試數據庫

相關文章
相關標籤/搜索