lnmp环境搭建

2018-12-17 10:49:11来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

一、安装Nginx
下载地址:http://nginx.org/download/nginx-1.8.0.tar.gz
安装依赖库
yum -y install gd-devel libtool libjpeg-devel libpng-devel freetype-devel libxml2 libxml2-devel zlib-devel bzip2 bzip2-devel libcurl-devel libxslt-devel openssl-devel glibc-devel glib2-devel libmcrypt-devel curl curl-devel pcre pcre-devel perl-devel perl-ExtUtils-Embed GeoIP GeoIP-devel GeoIP-data epel-release --with-ipv6
 
下载 编译安装
--prefix 安装路径
--sbin-path nginx执行文件目录
--conf-path 配置文件路劲
--user 运行nginx的用户
--group 运行nginx的用户组
wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar zxf nginx-1.10.2.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug
make ;
make install
以上已安装完毕,开启nginx服务,/usr/sbin/nginx。测试开启成功否 curl -I http://127.0.0.1
关于添加系统服务见 https://www.cnblogs.com/fwqblogs/p/10131846.html
 
二、安装PHP
wget http://cn2.php.net/distributions/php-5.6.34.tar.gz
tar zxf php-5.6.34.tar.gz
cd php-5.6.34
./configure --prefix=/usr/share/php --with-config-file-path=/etc --with-fpm-user=nginx --with-gd --with-xsl --with-bz2 --with-zlib --with-curl --with-pear --without-iconv --with-mcrypt -with-gettext --with-openssl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --enable-ftp --enable-fpm --enable-exif --enable-soap --enable-bcmath --enable-calendar --enable-sockets --enable-mbstring --enable-gd-native-ttf --disable-rpath --disable-debug --enable-pdo --with-pdo-mysql --with-mysql --with-config-file-scan-dir=/etc/php.d
make ; make install
 
--prefix= 指定安装路径
--with-config-file-path 指定 php.ini 存放位置
--with-fpm-user 运行fpm的用户
--enable-fpm Nginx 连接 php 全靠这个东西,如果没有它,你的 Nginx 就不能解析 php
--with-config-file-scan-dir 加载模块的启动文件 为ini结尾的文件 直接在该文件加载so模块文件
 
拷贝PHP配置
cp php.ini-production /etc/php.ini
fpm启动脚本,把配置里的程序 、配置、 pid 等路径修改到对应目录
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod a+x /etc/init.d/php-fpm 添加权限
fpm配置文件
cp /usr/share/php/etc/php-fpm.conf.default /etc/php-fpm.conf
修改 /etc/php-fpm.conf 根据实际情况修改即可
25 pid = /run/php-fpm.pid
33 error_log = /var/log/php-fpm/error.log
224 pm = static 设置固定启动fpm进程数 动态的增减的时候也有系统资源开销
pm.max_children = 340 pm为静态是有效 一个进程按40M左右算
441 slowlog = /var/log/php-fpm/www-slow.log 慢日志 必须开启下面超时时间才有效
447request_slowlog_timeout = 1
535 php_admin_value[error_log] = /var/log/php-fpm/www-error.log 覆盖 php.ini中的 error_log 参数
536 php_admin_flag[log_errors] = on
最后可直接通过系统服务开启fpm serveice php-fpm start|stop|restart
 
动态加载PHP扩展 例如:
在/etc/php.d/mysqli.ini 目录下加载扩展
内容
; Enable mysqli extension module
extension=mysqli.so
把对应的扩展文件.so 放到 /usr/share/php/lib/php/extensions/no-debug-non-zts-20131226/ 下 编译so文件时提示路径
加入开机启动
chkconfig --add php-fpm
chkconfig php-fpm on
 
最后配置nginx配置
user nginx;
worker_processes 8;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
worker_rlimit_nofile 100000;
 
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 65000;
multi_accept off;
use epoll;
accept_mutex off;
}
http {
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;
tcp_nodelay on;
 
types_hash_max_size 2048;
 
include /etc/nginx/mime.types;
default_type application/octet-stream;
gzip on;
gzip_min_length 0;
gzip_buffers 8 32k;
gzip_http_version 1.1;
gzip_comp_level 5;
gzip_types text/plain application/javascript application/json application/x-javascript text/javascript text/css application/xml applicati
on/xml+rss;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
 
#include /etc/nginx/conf.d/*.conf;
 
server {
listen 80;
server_name localhost;
root /home/talentwalker/wwwroot/;
 
location / {
}
 
error_page 404 /404.html;
location = /40x.html {
}
 
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
# root html;
}
location ~ \.php {
add_header Access-Control-Allow-Methods "POST, GET, OPTIONS";
add_header Access-Control-Allow-Headers CHANNELID,SID,SERVERCODE;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$; #pathinfo模式
  fastcgi_param PATH_INFO $fastcgi_path_info; #pathinfo模式
  include fastcgi_params;
  fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
location /jenkins {
proxy_pass http://127.0.0.1:8080/jenkins;
}
}
}
 
三、安装mysql
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.38.tar.gz
 
cmake -DCMAKE_INSTALL_PREFIX=/usr/share/mysql -DMYSQL_DATADIR=/mnt/data -DSYSCONFDIR=/etc -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DMYSQL_TCP_PORT=3306 -DWITH_DEBUG=1
make
make insatll
 
初始化mysql数据库 数据存储目录必须有
/usr/share/mysql/scripts/mysql_install_db --user=mysql --datadir=/mnt/data
mysql配置文件
cp /usr/share/mysql/support-files/my-default.cnf /etc/my.cnf
[client]
#password = your_password port = 3306 socket = /data/mysql/mysql.sock default-character-set=utf8
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
character_set_server=utf8
basedir=/data/mysql
datadir=/data/mysql/data
socket = /data/mysql/mysql.sock
log-error=/var/log/mysql/error.log
log=/var/log/mysql/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql/log/slowquery.log
将MySQL执行命令添加入PATH 如果有多个用:隔开
PATH=$PATH:/usr/share/mysql/bin export PATH
将MySQL设置为系统服务并启动服务
cp support-files/mysql.server /etc/init.d/mysqld
最后可直接通过系统服务开启mysqld serveice mysqld start|stop|restart
设置mysql管理员密码
mysqladmin -u root password "123456";
 
环境搭建基本就完成了
 
 
 
 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:php二维数组根据某个字段去重

下一篇:yii2.0 URL美化