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

首先更新系统软件

1

$ yum update

第一步:安装nginx

1.安装nginx源

1

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

2.安装nginx

1

$ yum install nginx

3.启动nginx

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

 

8、输入命令

 

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

 

在根目录写一段程序,测试数据库

posted @ 2016-11-14 09:47  tiandi2050  阅读(220)  评论(0编辑  收藏  举报