标签:
【准备工作】
#在编译安装lnmp之前,首先先卸载已存在的rpm包。 rpm -e httpd rpm -e mysql rpm -e php yum -y remove httpd yum -y remove mysql-server mysql yum -y remove php yum -y remove php-mysql #禁用SeLinux,Selinux可能会致使编译安装失败,我们先禁用它。 #sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/selinux/config #永久禁用,需要重启生效。 #或 setenforce 0 # 临时禁用,不需要重启(推荐)。 #yum安装必要工具 yum -y install 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 libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch gettext glib2-devel bzip2-devel libuuid-devel docbook-style-xsl libxslt-devel gzip-devel freetype-devel
下载源码包,存放路径如下所示:
usr/local/src/mysql/cmake-2.8.8.tar.gz
usr/local/src/mysql/mysql-5.5.25a.tar.gzusr/local/src/nginx/nginx-1.4.7.tar.gz
usr/local/src/nginx/openssl-1.0.1e.tar.gz
usr/local/src/nginx/pcre-8.33.tar.gz
usr/local/src/nginx/zlib-1.2.8.tar.gzusr/local/src/php/libiconv-1.14.tar.gz
usr/local/src/php/libmcrypt-2.5.8.tar.gz
usr/local/src/php/mcrypt-2.6.8.tar.gz
usr/local/src/php/mhash-0.9.9.9.tar.gz
usr/local/src/php/php-5.3.28.tar.gzusr/local/src/php/ext/memcache-3.0.8.tgz
usr/local/src/php/ext/mongo-1.4.4.tgz
1、Nginx相关软件
Nginx1.4.7
http://nginx.org/download/nginx-1.4.7.tar.gz
pcre(支持Nginx地址重写)
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz
gzip(页面压缩)
http://zlib.net/zlib-1.2.8.tar.gz
openssl(https安全支持组件)
http://www.openssl.org/source/openssl-1.0.1e.tar.gz
2、MySQL相关软件
MySQL5.5.25
http://downloads.mysql.com/archives/get/file/mysql-5.5.25a.tar.gz
cmake(MySQL编译工具)
http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
3、PHP相关软件
PHP5.3.28
http://cn2.php.net/get/php-5.3.28.tar.gz/from/this/mirror
libmcrypt(PHP的加密扩展)
http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2/download
mhash(PHP的哈希函数库,像MD5,SHA,CRC这类的,比如用来计算消息的校验码之类的。)
http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2/download
mcrypt(PHP的加密扩展)
http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download
libiconv(PHP字符集转换库)
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
【安装Nginx1.4.7】
#安装pcre库 cd /usr/local/src/nginx tar -xzvf ./pcre-8.33.tar.gz cd ./pcre-8.33 ./configure make && make install #安装zlib库 cd /usr/local/src/nginx tar -xzvf ./zlib-1.2.8.tar.gz cd ./zlib-1.2.8 ./configure make && make install #安装ssl cd /usr/local/src/nginx tar -xzvf ./openssl-1.0.1e.tar.gz #安装Nginx cd /usr/local/src/nginx tar -xzvf ./nginx-1.4.7.tar.gz cd ./nginx-1.4.7 mkdir /usr/local/nginx ./configure --prefix=/usr/local/nginx --user=www --group=www --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/nginx/pcre-8.33 --with-zlib=/usr/local/src/nginx/zlib-1.2.8 --with-openssl=/usr/local/src/nginx/openssl-1.0.1e make && make install
注意,其中的配置
--with-pcre=/usr/local/src/nginx/pcre-8.33
--with-zlib=/usr/local/src/nginx/zlib-1.2.8
--with-openssl=/usr/local/src/nginx/openssl-1.0.1e
为源码包解压后的路径,而不是安装路径,否则会报错!
configure 命令后,输出如下信息:
... Configuration summary + using PCRE library: /usr/local/src/nginx/pcre-8.33 + using OpenSSL library: /usr/local/src/nginx/openssl-1.0.1e + md5: using OpenSSL library + sha1: using OpenSSL library + using zlib library: /usr/local/src/nginx/zlib-1.2.8 nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/nginx" nginx configuration prefix: "/usr/local/nginx" nginx configuration file: "/usr/local/nginx/nginx.conf" nginx pid file: "/usr/local/nginx/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp" [root@localhost nginx-1.4.7]#
nginx的configure命令支持以下参数:(可使用 ./configure --help 命令查看)
安装成功后,nginx的目录结构如下:
[root@localhost nginx-1.4.7]# ll /usr/local/nginx 总用量 6468 -rw-r--r--. 1 root root 1034 12月 8 14:48 fastcgi.conf -rw-r--r--. 1 root root 1034 12月 8 14:48 fastcgi.conf.default -rw-r--r--. 1 root root 964 12月 8 14:48 fastcgi_params -rw-r--r--. 1 root root 964 12月 8 14:48 fastcgi_params.default drwxr-xr-x. 2 root root 4096 12月 8 14:48 html -rw-r--r--. 1 root root 2837 12月 8 14:48 koi-utf -rw-r--r--. 1 root root 2223 12月 8 14:48 koi-win drwxr-xr-x. 2 root root 4096 12月 8 14:48 logs -rw-r--r--. 1 root root 3463 12月 8 14:48 mime.types -rw-r--r--. 1 root root 3463 12月 8 14:48 mime.types.default -rwxr-xr-x. 1 root root 6540149 12月 8 14:48 nginx -rw-r--r--. 1 root root 2685 12月 8 14:48 nginx.conf -rw-r--r--. 1 root root 2685 12月 8 14:48 nginx.conf.default -rw-r--r--. 1 root root 596 12月 8 14:48 scgi_params -rw-r--r--. 1 root root 596 12月 8 14:48 scgi_params.default -rw-r--r--. 1 root root 623 12月 8 14:48 uwsgi_params -rw-r--r--. 1 root root 623 12月 8 14:48 uwsgi_params.default -rw-r--r--. 1 root root 3610 12月 8 14:48 win-utf [root@localhost nginx-1.4.7]#
#添加nginx用户及用户组
groupadd www #添加nginx用户组及用户 useradd -g www -s /usr/sbin/nologin www #不让www用户直接登录
#配置防火墙,开启80端口
vim /etc/sysconfig/iptables
添加如下规则到22端口这条规则的下面即可
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
#重启防火墙
service iptables restart
#启动nginx
/usr/local/nginx/nginx
在浏览器输入 localhost,出现如下画面,表示nginx安装成功!
#设置nginx开机启动
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/nginx nginx_config=/usr/local/nginx/nginx.conf nginx_pid=/usr/local/nginx/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 $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
保存,添加到服务,设置开机启动
:wq! #保存退出 chmod 775 /etc/rc.d/init.d/nginx #赋予文件执行权限 chkconfig nginx on #设置开机启动 /etc/rc.d/init.d/nginx restart #重启 service nginx restart #重启
【安装MySQL5.5.25a】
1、安装cmake
MySQL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具。
因此,我们首先要在系统中源码编译安装cmake工具。
#编译安装
cd /usr/local/src/mysql tar -xzvf ./cmake-2.8.8.tar.gz cd ./cmake-2.8.8 ./configure make && make install
2、编译安装配置MySQL
#切换至 MySQL源码 的解压目录 cd /usr/local/src/mysql tar -xzvf ./mysql-5.5.25a.tar.gz cd ./mysql-5.5.25a #创建所需目录 mkdir -pv /usr/local/mysql/data #创建mysql用户和mysql组 groupadd mysql useradd -g mysql -s /usr/sbin/nologin mysql #cmake编译 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_unicode_ci -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_DEBUG=0 #安装 make && make install #复制配置文件 cp ./support-files/my-medium.cnf /etc/my.cnf #设置权限 chmod +x /usr/local/mysql chown -R mysql:mysql /usr/local/mysql chown -R mysql:mysql /usr/local/mysql/data #配置开机自动启动 cp ./support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chkconfig --add mysqld chkconfig --level 2345 mysqld on chkconfig --list mysqld #查看是否已应用上 #添加MySQL的软链接以适应init脚本 ln -sv /usr/local/mysql/bin/mysql /usr/sbin/mysql ln -sv /usr/local/mysql/bin/mysqladmin /usr/sbin/mysqladmin ln -sv /usr/local/mysql/bin/mysqldump /usr/sbin/mysqldump #启动MySQL service mysqld start
#修改配置文件
vim /etc/my.cnf
#在[mysqld]节点中添加:
datadir = /usr/local/mysql/data log-error = /usr/local/mysql/data/error.log pid-file = /usr/local/mysql/data/mysql.pid user = mysql tmpdir = /tmp
#保存退出
#初始化数据库
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#修改root密码
/usr/local/mysql/bin/mysqladmin -u root -p password "123456" # 注意:刚开始密码最好用纯数字,后期再用phpMyAdmin来在线修改!
配置防火墙,开启3306端口
vim /etc/sysconfig/iptables
#添加如下规则到22端口这条规则的下面即可
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
#重启防火墙
service iptables restart # 或 /etc/init.d/iptables restart
启动MySQL
service mysqld start # 或 /etc/init.d/mysqld start
测试MySQL是否启动
#查看是否有mysql进程
ps -ef | grep mysql
#查看是否有mysql端口
netstat -ntlp | grep 3306
#测试mysql,mysqladmin,mysqldump命令是否能正常使用
#读取MySQL的版本信息
/usr/local/mysql/bin/mysqladmin version -u root -p
到此MySQL编译安装完成。
【安装PHP5.3.28】
############################################################### ###1、安装PHP依赖库 ############################################################### #安装 libmcryp cd /usr/local/src/php tar -xzvf ./libmcrypt-2.5.8.tar.gz cd ./libmcrypt-2.5.8 ./configure --prefix=/usr make && make install #安装 mhash cd /usr/local/src/php tar -xzvf ./mhash-0.9.9.9.tar.gz cd ./mhash-0.9.9.9 ./configure --prefix=/usr make && make install #安装 mcrypt /sbin/ldconfig #搜索出可共享的动态链接库 cd /usr/local/src/php tar -xzvf ./mcrypt-2.6.8.tar.gz cd ./mcrypt-2.6.8 ./configure make && make install #安装 libiconv cd /usr/local/src/php tar -xzvf ./libiconv-1.14.tar.gz cd ./libiconv-1.14 ./configure --prefix=/usr/local/libiconv make && make install ################################################################ ###2、安装 PHP 5.3.28 ################################################################ cd /usr/local/src/php tar -xzvf ./php-5.3.28.tar.gz cd ./php-5.3.28 #生成配置 ./configure --prefix=/usr/local/php-5.3 --with-config-file-path=/usr/local/php-5.3/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --with-bz2 --with-gd --with-jpeg-dir --with-png-dir --with-gettext --with-mhash --with-freetype-dir --with-mcrypt --with-iconv=/usr/local/libiconv --with-curl --with-curlwrappers --with-xmlrpc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-zip --enable-mbstring --enable-bcmath --enable-soap --enable-sockets --enable-ftp --enable-gd-native-ttf --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-fpm --without-pear #编译安装 make && make install
编译参数解释:
./configure --prefix=/usr/local/php-5.3
--with-config-file-path=/usr/local/php-5.3/etc
--with-config-file-scan-dir=/etc/php.d # 这个到时候还是去掉吧
--with-openssl
--with-zlib
--with-bz2
--with-gd
--with-jpeg-dir
--with-png-dir
--with-gettext
--with-mhash
--with-freetype-dir
--with-mcrypt
--with-iconv=/usr/local/libiconv
--with-curl
--with-curlwrappers
--with-xmlrpc
--with-mysql=/usr/local/mysql
--with-pdo-mysql=/usr/local/mysql
--with-mysqli=/usr/local/mysql/bin/mysql_config
--enable-zip
--enable-mbstring
--enable-bcmath
--enable-soap
--enable-sockets
--enable-ftp
--enable-gd-native-ttf
--enable-shmop
--enable-sysvmsg
--enable-sysvsem
--enable-sysvshm
--enable-pcntl
--enable-fpm
--without-pear
3、配置php.ini
cd /usr/local/src/php/php-5.3.28 cp ./php.ini-production /usr/local/php-5.3/etc/php.ini #复制php配置文件到安装目录 mv /etc/php.ini /etc/php.ini.bak #删除/移除系统自带配置文件 ln -s /usr/local/php-5.3/etc/php.ini /etc/php.ini #添加软链接
#编辑配置文件
vim /usr/local/php-5.3/etc/php.ini
找到: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
#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
找到:;date.timezone =
修改为:date.timezone = PRC #设置时区
找到:expose_php = On
修改为:expose_php = OFF #禁止显示php版本的信息
4、配置php-fpm
cp /usr/local/php-5.3/etc/php-fpm.conf.default /usr/local/php-5.3/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件
vim /usr/local/php-5.3/etc/php-fpm.conf #编辑
user = www #设置php-fpm运行账号为www
group = www #设置php-fpm运行组为www
pid = run/php-fpm.pid #取消前面的分号
#删除 /etc/php.d 文件夹下的配置文件
#设置 php-fpm 开机启动
cp /usr/local/src/php/php-5.3.28/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷贝php-fpm到启动目录 chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限 chkconfig php-fpm on #设置开机启动
5、配置nginx支持php
vim /usr/local/nginx/nginx.conf #编辑配置文件,需做如下修改
user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/php-5.3/etc/php-fpm.conf中的user,group配置相同,否则php运行出错。
index index.php index.html index.htm; #添加index.php
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
#取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,否则使用绝对路径。
service php-fpm start # 启动php-fpm service nginx restart # 重启nginx
延伸阅读:
PHP5不重新编译,如何安装自带的未安装过的扩展,如soap扩展?
CentOS5.x/CentOS6.x编译安装Python-2.7.6
CentOS6.3编译安装MongoDB-2.2.x 及 安装PHP的MongoDB客户端
CentOS6.3编译安装Nginx1.4.7 + MySQL5.5.25a + PHP5.3.28
标签:
原文地址:http://www.cnblogs.com/52php/p/5675255.html