centos7搭建lnmp环境

#安装PHP(5.6.26)

##先下载PHP源文件

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

##解压:

tar -zxvf php-5.6.26.tar.gz

##安装编译用的环境:

yum install -y libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel  bzip2-devel
yum install gcc gcc-c++ #编译工具

###安装libmcrypt

如果想让编译的php支持mcrypt扩展,需安装libmcrypt libmcrypt-devel 或者编译安装
####下载源文件:
Libmcrypt(libmcrypt-2.5.8.tar.gz):

wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

mcrypt(mcrypt-2.6.8.tar.gz ):

wget https://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz

mhash(mhash-0.9.9.9.tar.gz):

wget https://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz

####依次解压编译安装(类似)
#####先安装Libmcrypt

#tar -zxvf libmcrypt-2.5.8.tar.gz
#cd libmcrypt-2.5.8
#./configure
#make
#make install

说明:libmcript默认安装在/usr/local

安装完后重启机器

#####.再安装mhash

#tar -zxvf mhash-0.9.9.9.tar.gz
#cd mhash-0.9.9.9
#./configure
#make
#make install

#####.最后安装mcrypt

#tar -zxvf mcrypt-2.6.8.tar.gz
#cd mcrypt-2.6.8
#LD_LIBRARY_PATH=/usr/local/lib ./configure
#make
#make install

##进入PHP源码文件夹:

cd php-5.6.26

执行下面命令并开始编译:

#./configure --prefix=/usr/local/php --enable-fpm --enable-soap --with-libxml-dir --with-openssl --with-zlib --with-iconv --with-bz2 --with-curl --enable-dom --enable-exif --enable-fileinfo --with-pcre-dir --enable-ftp --enable-gd-jis-conv --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-mhash --enable-json --enable-mbstring --disable-mbregex --enable-pdo --with-pdo-mysql --with-pdo-sqlite --enable-session --with-zlib-dir --enable-simplexml --enable-sockets --enable-zip --with-mysqli

#make

#make install

再复制php的配置文件到对应的目录:

 cp php.ini-development /usr/local/php/lib/php.ini

配置php-fpm

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

配置完php-fpm后运行

php-fpm

安装完成之后使用

php -v

查看是否安装完成,如果编译成功但是无法使用命令行请使用下面的命令添加环境变量进系统:

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

#安装Nginx

##下载rpm文件

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

##建立nginx的yum仓库

# rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

##安装nginx

yum install nginx

##启动nginx服务

service nginx start

##nginx的配置
nginx的配置文件位置:/etc/nginx,更改一下(具体根据自己的配置更改):

/etc/nginx/nginx.conf文件内容如下:


user  root root;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

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

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d/default.conf文件中的内容改为:

server {
    listen       80;
    server_name  localhost 192.168.140.131;
    root   /usr/share/nginx/html;

    index  index.php index.html index.htm; 
     
    charset utf-8;
    #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;
    }

    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 /etc/nginx/fastcgi_params;
    }


     #配置Nginx的静态资源访问
    location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
            expires 30d;
    }

    # 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           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$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 restart

通过以上配置文件可见当前项目目录在:

/usr/share/nginx/html中

于是上传一个demo.php文件到此目录下,即可运行。

#安装mysql
参考网址:http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

##下载rpm文件:

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

##建立mysql的yum仓库

rpm -ivh mysql57-community-release-el7-9.noarch.rpm

##修改配置文件(指定安装的mysql版本)

 sudo vi /etc/yum.repos.d/mysql-community.repo

修改其中版本为enable为1或者0选择安装版本,这里我们选择mysql5.6
##安装mysql

sudo yum install mysql-community-server

##mysql默认密码(针对5.7)

会在/var/log/mysqld.log中保存一个初始密码,使用这个初始密码登录后使用:
SET PASSWORD = PASSWORD('你的新密码');
来修改密码

##启动mysql,并查看状态

service mysqld start
service mysqld status

##安装安全管理包(针对mysql5.6)

mysql_secure_installation

安完之后可以修改root密码

##测试
安装完成后使用命令行:

mysql -uroot -p

输入刚才设置的密码登录mysql

#以上

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值