1、yum源安装
yum install epel-release -y
yum install wget vim -y
wget http://www.atomicorp.com/installer/atomic
sh ./atomic
yum check-update
2、安装开发包和库文件
yum install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel perl perl-devel libxslt libxslt-devel libc-client libc-client-devel libtool-ltdl libtool-ltdl-devel -y
3、安装mysql
3.1 配置mysql官方源
rpm –ivh http://dev.mysql.com/get/mysql57-community-release-el6-8.noarch.rpm
3.2 yum安装mysql
yum install mysql-community-client mysql-community-devel mysql-community-server -y
chkconfig mysqld on
service mysqld start
查看/var/log/mysqld.log 找到随机生成的mysql初始密码,然后重新设置密码
mysqladmin –u root –p password #输入命令后,第一次输入旧密码,然后输入新密码
service mysqld restart
4、nginx安装
4.1 yum安装nginx
yum install nginx –y #安装nginx
chkconfig nginx on #设置nginx开机启动
service nginx start #启动nginx服务
4.2 nginx初始配置
cd /etc/nginx
mkdir vhosts
mv nginx.conf nginx.bak
vim proxy.conf
#!nginx (-) # proxy.conf proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 128m; client_body_buffer_size 512k; proxy_connect_timeout 6000; proxy_send_timeout 6000; proxy_read_timeout 6000; send_timeout 6000; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; proxy_temp_path /tmp/nginx/temp; proxy_cache_path /tmp/nginx/cache levels=1:2 keys_zone=cache_zone:2048M inactive=1d max_size=20g; proxy_headers_hash_max_size 51200; proxy_headers_hash_bucket_size 6400;
vim gzip.conf
gzip on; gzip_http_version 1.1; gzip_disable "MSIE [1-6]\."; #gzip_disable "Mozilla/4"; gzip_static on; gzip_comp_level 4; gzip_proxied any; gzip_vary on; gzip_buffers 4 16k; gzip_min_length 1100; gzip_types text/plain text/xml text/css application/xml application/xhtml+xml application/rss+xml application/atom_xml application/javascript application/x-javascript image/jpeg image/gif image/png;
vim nginx.conf
user nginx; pid /var/run/nginx.pid;worker_processes 8;
worker_rlimit_nofile 102400;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
charset utf-8;
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" '
'"gzip_ratio" request_time bytes_sent request_length';
set_real_ip_from 10.0.0.0/8;
real_ip_header X-Forwarded-For;
include /etc/nginx/gzip.conf;
include /etc/nginx/proxy.conf;
sendfile on;
keepalive_timeout 10;
client_header_buffer_size 4k;
open_file_cache max=65535 inactive=60s;
open_file_cache_valid 80s;
open_file_cache_min_uses 1;
include /etc/nginx/vhosts/*.conf;
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
location / {
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
4.3 确认nginx配置
nginx -t
4.4 启用nginx新配置
nginx -s reload
5、PHP安装
5.1 下载php5.3
cd /usr/local/src
wget http://cn2.php.net/distributions/php-5.3.29.tar.gz
wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
tar -zxvf libiconv-1.15.tar.gz
cd libiconv-1.15
./configure --prefix=/usr/local
make
make install
5.2 编译安装php
tar -zxvf php-5.3.29.tar.gz
cd php-5.3.29
ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-bz2 --with-openssl --with-zlib --with-mhash --with-pcre --enable-exif --enable-sockets --enable-mbstring --enable-xml --enable-fpm --enable-soap --with-mysql=/usr/lib64/mysql --with-mysqli=/usr/bin/mysql_config --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mhash --enable-pcntl --enable-sockets --with-ldap-dir=/lib64 --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gd --with-curl --with-mcrypt --with-imap --with-imap-ssl --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-gd-native-ttf --with-mysqli --with-pdo-mysql --enable-dom --with-kerberos --disable-debug
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-bz2 --with-openssl --with-zlib --with-mhash --with-pcre --enable-exif --enable-sockets --enable-mbstring --enable-xml --enable-fpm --enable-soap --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-mhash --enable-pcntl --enable-sockets --with-ldap-dir=/lib64 --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gd --with-curl --with-mcrypt --with-imap --with-imap-ssl --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-gd-native-ttf --with-pdo-mysql=mysqlnd --enable-dom --with-kerberos --disable-debug
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf/default /usr/local/php/etc/php-fpm.conf
mkdir /usr/local/php/etc/php.d
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod u+x /etc/init.d/php-fpm
yum 安装php
yum install php php-fpm lighttpd-fastcgi php-adodb php-bcmath php-Analog php-cli php-dba php-devel php-embedded php-enchant php-gd php-geshi php-getid3 php-gliph php-hamcrest php-idn php-imap php-interbase php-intl php-latte php-layers-menu php-ldap php-lessphp php-libdmtx php-libpuzzle php-magickwand php-mapi php-mapserver php-markdown php-masterminds-html5 php-mbstring php-mcrypt php-mysql php-odbc php-pclzip php-pdo php-pear php-pecl php-phpass php-process php-spsell php-punic php-recode php-redis php-redland php-scssphp php-sentry php-shout php-silex php-simplepie php-snmp php-soap php-tcpdf php-tidy php-tracy php-twig php-voms-admin php-when php-xapian php-xcache php-xml php-xmlrpm php-zipstream php-zmq php-zte
5.3 修改php.ini文件中的以下配置
disable_functions = phpinfo,passthru,exec,system,popen,chroot,escapeshellcmd,escapeshellarg,shell_exec,proc_open,proc_get_status memory_limit = 512M upload_max_filesize = 32M date.timezone = Asia/Shanghai session.save_path = "/tmp/phpsession"
5.5 设置PHP开机启动
chkconfig php-fpm on
5.6 启动PHP
service php-fpm start
至此,LNMP环境搭建完毕。
https://webtatic.com/projects/yum-repository/
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于