您的位置:首页 > 运维架构 > Linux

基于Centos6.X系列的LNMP环境搭建

2016-03-18 23:12 381 查看
准备工作:1:软件获取 可以通过搜狐镜像、网易镜像、阿里云镜像获取最新的centos、php、nginx和mysql。本文采用centos6.7 64位minimal版、php5.6.12、nginx1.8.0版搭建lnmp环境,虚拟机软件是Oracle VM VirtualBox5.0.12。关于虚拟机的安装、最小化安装系统以及开启64位支持本文不再赘述,本文设置软件下载目录/usr/local/src,软件安装目录/app/local/下,安装顺序是nginx→mysql→php, 搜狐镜像:http://mirrors.sohu.com/ 网易镜像:http://mirrors.163.com/ 阿里云镜像:http://mirrors.aliyun.com/ wget http://mirrors.sohu.com/php/php-5.6.12.tar.gz wget http://mirrors.sohu.com/nginx/nginx-1.8.0.tar.gz wget http://www.cmake.org/files/v3.0/cmake-3.0.2.tar.gz wget http://blog.zyan.cc/soft/linux/nginx_php/imagick/ImageMagick.tar.gz wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.47.tar.gz wget http://blog.zyan.cc/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz wget http://blog.zyan.cc/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz wget http://blog.zyan.cc/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz wget http://blog.zyan.cc/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz2:登录后在shell界面可以通过dhclient获取ip地址或者单独设置固定的IP地址,用ifconfig -a查看ip地址,通过yum -y install wget lua-devel libxslt-devel libmcrypt-devel libmcrypt pcre pcre-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers获取编译库文件3:编译安装nginx 首先创建一些目录 mkdir -p /app/local/nginx mkdir /app/local/php mkdir /app/local/soft创建www 用户组groupadd -g 500 wwwuseradd -u 500 -g 500 -G 500 -s /sbin/nologin www 解压 nginxtar zxvf nginx-1.8.0.tar.gzcd nginx-1.8.0./configure --prefix=/app/local/nginx --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_modulemakemake install然后cd切换到/app/local/nginxsbin/nginx在浏览器下输入ip地址查看nginx是否安装成功如果没有的话 检测一下selinux和防火墙是否配置vi /etc/sysconfig/iptables 在22下一行加入80 3306端口配置-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT-A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT:wq! #保存退出service iptables restart #最后重启防火墙使配置生效关闭selinuxvi /etc/sysconfig/selinux# This file controls the state of SELinux on the system.# SELINUX= can take one of these three values:# enforcing - SELinux security policy is enforced.# permissive - SELinux prints warnings instead of enforcing.# disabled - No SELinux policy is loaded.#SELINUX=enforcing# SELINUXTYPE= can take one of these two values:# targeted - Targeted processes are protected,# mls - Multi Level Security protection.#SELINUXTYPE=targetedSELINUX=disabled:wq!setenforce 0 #使配置立即生效4:安装MySQL,由于是5.5版本,不能直接安装,需要先安装cmake工具,要是5.1版本可以忽略这一步。安装cmakecd /usr/local/srctar zxvf cmake-3.0.2.tar.gzcd cmake-3.0.2./configuremakemake install安装mysql先设定一些安装目录mkdir -p /app/local/mysqlmkdir -p /app/local/data创建mysql用户组groupadd mysql useradd -g mysql mysql -s /bin/false设置MySQL数据库存放目录权限chown -R mysql:mysql /app/local/datacd /usr/local/src tar zxvf mysql-5.5.47.tar.gz cd mysql-5.5.47.tar.gz cmake -DCMAKE_INSTALL_PREFIX=/app/local/mysql -DMYSQL_DATADIR=/app/local/data -DSYSCONFDIR=/etcmake make install rm -rf /etc/my.cnf cp /app/local/mysql/support-files/my-innodb-heavy-4G.cnf /app/local/mysql/my.cnfln -s /app/local/mysql/my.cnf /etc/my.cnf cd /app/local/mysql./scripts/mysql_install_db --user=mysql --basedir=/app/local/mysql --datadir=/app/local/data #生成mysql系统数据库安装php扩展库文件cd /usr/local/srctar zxvf libiconv-1.13.1.tar.gzcd libiconv-1.13.1mkdir /app/local/soft/libiconv./configure ―prefix=/app/local/soft/libiconvmakemake installcd ../ tar zxvf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9../configuremakemake installcd ../tar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8./configuremakemake installcd ../ tar zxvf php-5.6.12.tar.gzcd php-5.6.12./configure --prefix=/app/local/php --with-config-file-path=/app/local/php/etc --with-pdo-sqlite --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-xmlreader --enable-xmlwriter --enable-soap --enable-calendar --with-curl --with-mcrypt --with-gd --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-pdo-mysql --with-mysqli --with-mysql-sock --enable-mysqlnd --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-openssl --enable-ftp --with-imap-ssl --with-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --disable-fileinfo出现错误后将enable-opcache=nomake出现了错误make: *** [ext/zip/lib/zip_add.lo] 错误 1解决办法:vi /etc/ld.so.conf.d/local.conf //创建local.conf/usr/local/lib //添加输入ldconfig //执行命令make clean 后再make 一下如果不行 看看源码安装zlib跟libzip,再分别指定以下两个参数的路径
--with-zlib-dir=DIR#指定为/usr就行了
--with-libzip=DIR#可以先不加这个 cd ../cd /app/local/phpcd etccp php-fpm.conf.default php-fpm.conf vi php-fpm.conf查找/static将pm=dynamic 改成pm =static保存退出cd phpsbin/php-fpm通过netstat -ntpl查看端口是否打开ps -ef查看进程 切换到nginx目录下cd confcp nginx.conf nginx.confbakvi nginx.conf修改user www www;worker_processes 4;error_log logs/error.log events{ use epoll; worker_connections 51024;} location ~ \.php${ root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; include fastcgi.conf; } :wq然后使用netstat -nptl查询端口 然后切换到html目录cd ../cd htmlvi phpinfo.php<?phpphpinfo(); ?>保存退出后在浏览器输入ip地址/phpinfo.php后检测是否成功若是没有成功可以在nginx目录下的logs查看日志检测

本文出自 “selfim” 博客,请务必保留此出处http://selfim.blog.51cto.com/11028663/1752767
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: