Lnmp环境搭建

lnmp环境搭建,系统平台centos64位下面

安装nginx

安装编译工具及库文件

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

安装 PCRE

#PCRE 作用是让 Ngnix 支持 Rewrite 功能。
#下载 PCRE 安装包,
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
tar zxvf pcre-8.35.tar.gz
cd pcre-8.35
./configure
make && make install
pcre-config --version

安装nginx

wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar zxvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
make 
make install
/usr/local/webserver/nginx/sbin/nginx -v

nginx配置

#创建 Nginx 运行使用的用户 www
/usr/sbin/groupadd www 
/usr/sbin/useradd -g www www

配置文件,把server_name改为自己的网站域名

user  www www;
worker_processes  1;
 
error_log  /usr/local/webserver/logs/nginx_error.log crit;
pid        /usr/local/webserver/nginx/nginx.pid;
 
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
 
events
{
  use epoll;
  worker_connections 65535;
}
 
 
http {
        include       mime.types;
        default_type  application/octet-stream;
 
        #charset  gb2312;
 
        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 8m;
 
        sendfile on;
        tcp_nopush     on;
 
        keepalive_timeout 60;
 
        tcp_nodelay on;
 
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 128k;
 
        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.0;
        gzip_comp_level 2;
        gzip_types       text/plain application/x-javascript text/css application/xml;
        gzip_vary on;
        #limit_zone  crawler  $binary_remote_addr  10m;
        log_format main '$remote_addr - "$request_time" [$time_local] "$request" '
                      '"$status" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" $http_x_forwarded_for';
        log_format '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" $http_x_forwarded_for "$request_time"';
        
    server {
        listen       80;
        server_name  139.224.133.61;
        index index.html index.htm index.php;
        root /home/www/bbs/;
        location ~ .*\.(php|php5)?$
        {
                fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
        }
 
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
                expires 30d;
        }
        location ~ .*\.(js|css)?$
        {
                expires 1h;
        }
    ###this is to use open website lianjie like on apache##
            location / {
                    if (!-e $request_filename) {
                            rewrite ^(.*)$ /index.php?s=$1 last;
                            break;
                    }
            }
            location ~ /.svn/ {
            deny all;
            }
            ###end##
            access_log  /usr/local/webserver/logs/dsdstv-access.log main;
    }
    include /usr/local/webserver/nginx/conf/vhosts/*.conf;
}

vhost的配置,文件名字是域名.com.conf

server {
        listen       80;
        server_name  xxxxx;   #改为自己的域名
        index index.html index.htm index.php;
        root /home/www/bbs;
        location ~ .*\.(php|php5)?$
        {
                fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
                expires 30d;
        }
        location ~ .*\.(js|css)?$
        {
                expires 1h;
        }
###this is to use open website lianjie like on apache##
        location / {
                if (!-e $request_filename) {
                        rewrite ^(.*)$ /index.php?s=$1 last;
                        break;
                }
        }
        location ~ /.svn/ {
        deny all;
        }
        ###end##
        access_log  /usr/local/webserver/logs/dsdstv-access.log main;
}

检查配置文件ngnix.conf的正确性命令

/usr/local/webserver/nginx/sbin/nginx -t

nginx的命令

/usr/local/webserver/nginx/sbin/nginx                      # 启动
/usr/local/webserver/nginx/sbin/nginx -s reload        # 重新载入配置文件
/usr/local/webserver/nginx/sbin/nginx -s reopen       # 重启 Nginx
/usr/local/webserver/nginx/sbin/nginx -s stop           # 停止 Nginx

安装php7

先安装一些编译需要的依赖

yum -y install gcc gcc-c++ gcc-g77 make libtool autoconf patch unzip automake libxml2 libxml2-devel ncurses ncurses-devel libtool-ltdl-devel libtool-ltdl libmcrypt libmcrypt-devel libpng libpng-devel libjpeg-devel openssl openssl-devel curl curl-devel libxml2 libxml2-devel ncurses ncurses-devel libtool-ltdl-devel libtool-ltdl autoconf automake libaio*

去php官网下载安装包,编译,安装

tar xf php-7.0.6.tar.bz2
cd php-7.0.6

mkdir -p /usr/local/webserver/php7/etc

./configure \
--prefix=/usr/local/webserver/php7 \
--exec-prefix=/usr/local/webserver/php7 \
--with-config-file-path=/usr/local/webserver/php7/etc \
 --with-curl \
 --with-freetype-dir \
 --with-gd \
 --with-gettext \
 --with-iconv-dir \
 --with-kerberos \
 --with-libdir=lib64 \
 --with-libxml-dir \
 --with-mysqli \
 --with-openssl \
 --with-pcre-regex \
 --with-pdo-mysql \
 --with-pdo-sqlite \
 --with-pear \
 --with-png-dir \
 --with-xmlrpc \
 --with-xsl \
 --with-zlib \
--with-zlib-dir \
--with-mhash \
--with-mcrypt \
--with-openssl-dir \
--with-jpeg-dir \
--enable-gd-jis-conv \
 --enable-fpm \
 --enable-bcmath \
 --enable-libxml \
 --enable-inline-optimization \
 --enable-gd-native-ttf \
 --enable-mbregex \
 --enable-mbstring \
 --enable-opcache \
 --enable-pcntl \
 --enable-shmop \
 --enable-soap \
 --enable-sockets \
 --enable-sysvsem \
 --enable-xml \
 --enable-zip

make &&  make install

设置配置文件

#php.ini-development 适合开发测试,如本地测试环境, php.ini-production拥有较高的安全性设定,适合服务器上线运营当产品。一般修改php.ini-production为php.ini,安全性更高,确保测试环境(本地)与正式环境(线上)一致
cp php.ini-production /usr/local/webserver/php7/etc/php.ini  

cp /usr/local/webserver/php7/etc/php-fpm.conf.default  /usr/local/webserver/php7/etc/php-fpm.conf
vi /usr/local/webserver/php7/etc/php-fpm.conf
#user = www #设置php-fpm运行账号为www
#group = www #设置php-fpm运行组为www
#pid = /var/run/php-fpm/php-fpm.pid #取消前面的分号

cp /usr/local/webserver/php7/etc/php-fpm.d/www.conf.default /usr/local/webserver/php7/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
chkconfig --add php-fpm
#需要注意的是php7中www.conf这个配置文件配置phpfpm的端口号等信息,如果你修改默认的9000端口号需在这里改,再改nginx的配置
#启动
/etc/init.d/php-fpm start

安装mysql

安装依赖

#/etc/my.cnf改名为其它的
mv /etc/my.cnf /etc/my.cnf-bak

yum -y install gcc gcc-c++ ncurses ncurses-devel cmake

下载源码包

#5.7.5后,依赖boost工具,GEO支持
wget -O https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
#解压,可选择安装或不安装;若不安装则在编译mysql时需添加参数制定boost目录
tar -zxvf boost_1_59_0.tar.gz -C /usr/local/

创建mysql用户

groupadd mysql
useradd -r -g mysql -s /bin/false mysql

下载源码,编译安装

wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz
tar zxf mysql-5.7.10.tar.gz
cd mysql-5.7.10
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql5.7 -DMYSQL_DATADIR=/usr/local/webserver/mysql5.7/data -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/src/boost_1_59_0 -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1
make && make install

修改下/etc/my.cnf配置文件

vi /etc/my.cnf

[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/webserver/mysql5.7
datadir = /usr/local/webserver/mysql5.7/data
pid-file = /usr/local/webserver/mysql5.7/data/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
#skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /usr/local/webserver/logs/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /usr/local/webserver/logs/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

使用mysql的服务管理文件mysql.server配置mysql为系统服务

cp /usr/local/webserver/mysql5.7/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

初始化数据库

chown -R mysql:mysql /usr/local/webserver/mysql5.7
/usr/local/webserver/mysql5.7/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/webserver/mysql5.7 --datadir=/usr/local/webserver/mysql5.7/data
#发现没有反应  试试,得出是 /usr/local/webserver/logs没有权限
strace /usr/local/webserver/mysql5.7/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/webserver/mysql5.7 --datadir=/usr/local/webserver/mysql5.7/data

mysql的命令

service mysqld start
service mysqld status
service mysqld stop

你可能感兴趣的:(Lnmp环境搭建)