标签:
准备工作:
1:软件获取
可以通过搜狐镜像、网易镜像、阿里云镜像获取最新的centos、php、nginx和mysql。本文采用centos6.7 64位minimal版、php7、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.gz
2:登录后在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 www
useradd -u 500 -g 500 -G 500 -s /sbin/nologin www
解压 nginx
tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/app/local/nginx --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module
make
make install
然后cd切换到/app/local/nginx
sbin/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 #最后重启防火墙使配置生效
关闭selinux
vi /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=targeted
SELINUX=disabled
:wq!
setenforce 0 #使配置立即生效
4:安装MySQL,由于是5.5版本,不能直接安装,需要先安装cmake工具,要是5.1版本可以忽略这一步。
安装cmake
cd /usr/local/src
tar zxvf cmake-3.0.2.tar.gz
cd cmake-3.0.2
./configure
make
make install
安装mysql先设定一些安装目录
mkdir -p /app/local/mysql
mkdir -p /app/local/data
创建mysql用户组
groupadd mysql
useradd -g mysql mysql -s /bin/false
设置MySQL数据库存放目录权限
chown -R mysql:mysql /app/local/data
cd /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=/etc
make
make install
rm -rf /etc/my.cnf
cp /app/local/mysql/support-files/my-innodb-heavy-4G.cnf /app/local/mysql/my.cnf
ln -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/src
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
mkdir /app/local/soft/libiconv
./configure —prefix=/app/local/soft/libiconv
make
make install
cd ../
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9.
./configure
make
make install
cd ../
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
cd ../
tar zxvf php-5.6.12.tar.gz
cd 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=no
make
出现了错误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/php
cd etc
cp php-fpm.conf.default php-fpm.conf
vi php-fpm.conf
查找/static将pm=dynamic 改成pm =static
保存退出
cd php
sbin/php-fpm
通过netstat -ntpl查看端口是否打开
ps -ef查看进程
切换到nginx目录下
cd conf
cp nginx.conf nginx.confbak
vi nginx.conf
修改
user www www;
worker_processes 4;
error_log logs/error.log
events{
use poll;
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 html
vi index.php
<?php
phpinfo();
?>
保存退出后在浏览器输入ip地址/index.php后检测是否成功
若是没有成功可以在nginx目录下的logs查看日志检测
标签:
原文地址:http://www.cnblogs.com/weblm/p/5052401.html