lnmp環境搭建

1、安裝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的用戶組
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
 
2、安裝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;
}
}
}
 
3、安裝mysql
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
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";
 
環境搭建基本就完成了
相關文章
相關標籤/搜索