初始环境安装LNMP

文档都是去年写的了,最近经历的公司都是用

所需软件包下载地址:

# yum install libtool make apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel cmake wget
# /etc/init.d/iptables stop
# setenforce 0
# vim /etc/sysconfig/selinux
  SELINUX=enforcing  改为  SELINUX=disabled
安装mysql
# rpm -qa | grep mysql | xargs rpm -e –nodeps  #卸载系统自带mysql
# wget  
# groupadd mysql
# useradd -g mysql mysql 
# mkdir -p /usr/local/mysql/data
# chown -R mysql:mysql /usr/local/mysql/data/
# tar zxf mysql-5.6.11.tar.gz
# cd /root/mysql-5.6.11
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DINSTALL_DATADIR=/usr/local/mysql/data/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSRETS=all -DENABLED_LOCAL-INFILE=1
报错信息:

-- The C compiler identification is unknown

-- The CXX compiler identification is unknown

CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found.   Please set CMAKE_C_COMPILER to a valid compiler path or name.

CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found.   Please set CMAKE_CXX_COMPILER to a valid compiler path or name.

.

.

.

-- Configuring incomplete, errors occurred!

解决办法: 
# yum install -y gcc*
# rm -rf CMakeCache.txt  
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DINSTALL_DATADIR=/usr/local/mysql/data/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSRETS=all -DENABLED_LOCAL-INFILE=1
警告信息

Warning: Bison executable not found in PATH

解决办法:
#yum install -y bison
#rm -rf  CMakeCache.txt
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DINSTALL_DATADIR=/usr/local/mysql/data/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSRETS=all -DENABLED_LOCAL-INFILE=1
# make -j8 && make install (虚拟机或者个人PC就不要用-j8这个参数了,make会报错)
# cd /usr/local/mysql/
# cp ./support-files/my-default.cnf /etc/my.cnf 
# vim /etc/my.cnf
在mysql下增加一句
datadir = /usr/local/mysql/data/ #指定mysql数据库存放路径
# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld 
# chmod 755 /etc/init.d/mysqld
# chkconfig mysqld on
# vi /etc/rc.d/init.d/mysqld
  更改46,47行为:  
  46 basedir=/usr/local/mysql #数据库程序位置
  47 datadir=/usr/local/mysql/data #数据库存放目录
# /etc/init.d/mysqld start 
# chkconfig mysqld on
# export PATH=$PATH:/usr/local/mysql/bin/
# vim /etc/profile  
  在文件最后面添加: 
  export PATH=$PATH:/usr/local/mysql/bin
# ldconfig
# /etc/init.d/mysqld restart
安装
pcre
pcre-8.31.tar.gz perl语言兼容正则表达式,是一个用C语言编写的正则表达式函数库,支持nginx伪静态
# cd 
# tar -zxf pcre-8.31.tar.gz 
# cd pcre-8.31
# ./configure --prefix=/usr/local/pcre
# make && make install
安装nginx
# cd
# useradd www -s /sbin/nologin 
# tar -zxf nginx-1.2.2.tar.gz
# ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/root/pcre-8.31
# make && make install 
# vim /etc/rc.d/init.d/nginx
添加如下内容
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
chmod 775 /etc/rc.d/init.d/nginx
# chkconfig nginx on 
# /etc/init.d/nginx start 
     
php安装 
# cd 
# tar zxf php-5.4.3.tar.gz
# cd php-5.4.3
# ./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc  --with-mysql=/usr/local/mysql  --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd  --with-iconv --with-freetype --with-jpeg --with-png --with-zlib --with-libxml --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic --enable-suhosin --enable-session --with-mcrypt
报错信息
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决办法:
# tar zxf libmcrypt-2.5.8.tar.gz  
# ./configure 
# make && make install 
# cd ../php-5.4.3
# ./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc  --with-mysql=/usr/local/mysql  --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd  --with-iconv --with-freetype --with-jpeg --with-png --with-zlib --with-libxml --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic --enable-suhosin --enable-session --with-mcrypt
# make && make install
# cp php.ini-production /usr/local/php5/etc/php.ini  
# rm -rf /etc/php.ini #删除系统自带配置文件
# ln -s /usr/local/php5/etc/php.ini /etc/php.ini #添加软链接
# cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件
# vim /usr/local/php5/etc/php-fpm.conf
  132 user = www #设置php-fpm运行账号为www
  133 group = www #设置php-fpm运行组为www
  25  pid = run/php-fpm.pid #取消前面的分号
# cp /root/php-5.4.5/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷贝php-fpm到启劢目录
# chmod a+x /etc/rc.d/init.d/php-fpm
# chkconfig php-fpm on
# vim /usr/local/php5/etc/php.ini 
  找到:
  314 disable_functions =    
  修改为
  disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
配置nginx支持
php
# vim /usr/local/nginx/conf/nginx.conf
  2 user=nobody; 改为 user  www www; 
  45 index  index.html index.htm 改为 index  index.html index.htm index.php;
  65 location ~ \.php$ {
  66 root html;
  67 fastcgi_pass 127.0.0.1:9000;
  68 fastcgi_index index.php;
  69 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  70 include fastcgi_params;
  71 }  #取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
# /etc/init.d/nginx restart
# /etc/init.d/php-fpm restart
测试 
# cd /usr/local/nginx/html/
# vim index.php
<?php
phpinfo();
?>
# chown  /usr/local/nginx/html/ -R
# chmod 700 /usr/local/nginx/html/ -R
# /etc/init.d/nginx restart 
使用浏览器访问服务器即可检验是否配置成功