CentOS 6.2 上编译安装 Nginx 1.0.15 + PHP 5.3.16 + MySQL 5.1.62
来源:互联网 发布:mazak数控车床编程 编辑:程序博客网 时间:2024/05/18 14:29
更新:
2012-05-28 initial 2012-09-01 去掉eAccelerator,添加APC;将PHP更新到5.3.16 2012-09-13 修复MySQL启动问题;将pid和MySQL的data存放到/home/mysql目录下;编译PHP时添加mysql pdo
补充教程:
《在不停机下为PHP安装APC加速》
《Nginx日志自动切割脚本》
LNMP的好处就不说了,特别是对于这个正在运行的小内存VPS。鉴于师傅的淫威,我只能手工编译安装Nginx 1.0.15 + PHP 5.3.12 + MySQL 5.1.62 + eAccelerator 0.9.6.1,不能使用各种一键安装包,以及使用yum命令,因为他说“不手动试一下怎么能学到东西”。废话不说,先将步骤和代码贴出来,打造一个适合新手(如我)的详细安装教程
准备
- 当然是可以上网的机器,可以是虚拟机,VPS,服务器,安装CentOS,其他分支没测试过,最好在虚拟机上先试手一下,因为有snapshot,随时可以回滚所有操作。
- 必要时先清空iptables, 关闭SELINUX
- 源文件下载的目录是
/usr/local/src
前期工作
更新系统,安装必要的程序,此步骤需要用到yum命令
安装 先下载各个软件包
cd /usr/local/srcwget http://nginx.org/download/nginx-1.0.15.tar.gzwget http://au.php.net/get/php-5.3.16.tar.gz/from/us.php.net/mirrorwget http://pecl.php.net/get/APC-3.1.9.tgzwget http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.1/mysql-5.1.62.tar.gzwget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gzwget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0wget http://downloads.sourceforge.net/project/pcre/pcre/8.30/pcre-8.30.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fpcre%2Ffiles%2Fpcre%2F8.30%2F&ts=1335184494&use_mirror=aarnetwget http://downloads.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Feaccelerator%2Ffiles%2Feaccelerator%2FeAccelerator%25200.9.6.1%2F&ts=1335276559&use_mirror=waix
必要软件包
yum -y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake
注意 从mysql-5.5起,mysql源码安装开始使用cmake了
然后安装各个库,依次是libiconv,libmcrypt,mhash, mcrypt 和pcre
tar zxvf libiconv-1.14.tar.gzcd libiconv-1.14./configure --prefix=/usr/localmakemake installcd ../tar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8/./configuremakemake install
这里如果出现错误,
- checking for C++ compiler default output file name... configure: error: C++ compiler cannot create executables
- See `config.log' for more details.
出现该情况是由于c++编译器的相关package没有安装,以root用户登陆
/sbin/ldconfigcd libltdl/./configure --enable-ltdl-installmakemake installcd ../../tar zxvf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9/./configuremakemake installcd ../ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.laln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.soln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.aln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.laln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.soln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1tar zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8//sbin/ldconfig./configuremakemake installcd ../tar zxvf pcre-8.30.tar.gzcd pcre-8.30./configuremake && make installcd ../
- //# yum install glibc-headers
- # yum install gcc
- # yum install gcc-c++
一、安装MYSQL
首先是添加组
groupadd mysql#创建目录,存放data和pidmkdir -p /home/mysql/mysql-5.1.62/3306/chown -r mysql:mysql /home/mysql/useradd -s /sbin/nologin -M -g mysql mysql
然后是解压,编译和安装,注意,我将LNMP需要的应用都放在了
/usr/local/webserver
里面
./configure --prefix=/usr/local/webserver/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrgmake && make install
修改目录权限,配置文件,因为不是什么大型服务器,所以先复制使用默认的中等配置文件,同时将自带用于启动,重启mysql的文件复制到init.d目录,用于service命令来restart等操作,最后是创建开机启动
chmod +w /usr/local/webserver/mysqlchown -R mysql:mysql /usr/local/webserver/mysql/usr/local/webserver/mysql/bin/mysql_install_db --basedir=/usr/local/webserver/mysql --user=mysqlcp -f /usr/local/webserver/mysql/share/mysql/my-medium.cnf /etc/my.cnf#将skip-locking 转换成skip-external-lockingsed -i 's/skip-locking/skip-external-locking/g ' /etc/my.cnf sed -i 's:#innodb:innodb:g ' /etc/my.cnfcp /usr/local/webserver/mysql/share/mysql/mysql.server /etc/init.d/mysqldchmod 755 /etc/init.d/mysqld #添加执行权限ln -s /usr/local/webserver/mysql/lib/mysql /usr/lib/mysqlln -s /usr/local/webserver/mysql/insclude/mysql /usr/include/mysqlchkconfig mysqld on #设置开机启动
在my.cnf 的[mysqld]里面增加(或将对应字段修改成)以下:
log-error = /home/mysql/mysql-5.1.62/3306/mysql_error.logpid-file = /home/mysql/mysql-5.1.62/3306/mysql.piddatadir = /home/mysql/mysql-5.1.62/3306/data
重启机器后,mysql会自动启动,接着是设定其root帐号密码,再先将默认帐号密码都去掉
/usr/local/webserver/mysql/bin/mysqladmin -u root password ‘root 'cat > /tmp/mysql_sec_script<<EOFuse mysql;delete from user where not (user= 'root ') ;delete from user where user= 'root ' and password= ' ';drop database test;DROP USER ''@ '%';flush privileges;EOF/usr/local/webserver/mysql/bin/mysql -u root –p 'root ' -h localhost < /tmp/mysql_sec_scriptrm -f /tmp/mysql_sec_script/etc/init.d/mysqld restart/etc/init.d/mysqld stop
cmake安装方法
-DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/webserver/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306
#make;make install
这里需要等待好长一段时间,可以去喝杯水,~~
这里需要给mysql需要执行的命令增加一个环境变量
#vi /etc/profile
加入一下两句
PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib/
export PATH
保存推出,让其立即生效
#source /etc/profile
赋予mysql权限
#chown -R mysql:mysql /usr/local/mysql
#chown -R mysql:mysql /data/mysql
执行初始化配置脚本,创建系统自带的数据库和表。
#mysql_install_db --user=mysql --datadir=/data/mysql
初始化脚本在 /usr/local/mysql/my.cnf 生成了配置文件。
复制服务启动脚本
#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
接着就可以启动mysql
#server mysqld restart
设置开机启动
#chkconfig mysqld on
给mysql设置密码
#mysql 直接就进入mysql(初始的mysql没有密码哦)
>use mysql;
>update user set password = password(111111) where user = 'root'; 给root设置密111111
>flush privileges; 刷新表使其生效
>\q 退出,重新进入mysql就需要密码
#mysql -uroot -p 111111 就可以进去了
>
到此安装mysql5.6.11就结束了。
二、安装PHP
cd /usr/local/srctar zvxf php-5.3.16.tar.gzcd php-5.3.16mkdir -p /usr/local/webserver/php./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-pdo-mysql=/usr/local/webserver/mysql/ --with-mysql-sock=/tmp/mysql.sockmake ZEND_EXTRA_LIBS= '-liconv 'make installcp php.ini-production /usr/local/webserver/php/etc/php.inicp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #因为php5.3开始自带fpm,使用自带的管理脚本chmod +x /etc/init.d/php-fpmchkconfig php-fpm on #设置开机自启动cp /usr/local/webserver/php/etc/php-fpm.conf.default /usr/local/webserver/php/etc/php-fpm.conf
然后修改php-fpm.conf,将pid改成以下,并将user和group改成www
pid = run/php-fpm.piduser = wwwgroup = www
然后安装eAccelerator
cd ../tar jxvf eaccelerator-0.9.6.1.tar.bz2cd eaccelerator-0.9.6.1/usr/local/webserver/php/bin/phpize #记录下输出./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-configmakemake installcd ../
修改php.ini,查找/usr/local/webserver/php/etc/php.ini中的extension\_dir = "./"
,修改为extension\_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/"
,此路径为刚刚的输出路径。再查找cgi.fix\_pathinfo=0
,修改为cgi.fix\_pathinfo=0
,防止Nginx文件类型错误解析漏洞。接着是配置eAccelerator,
mkdir -p /usr/local/webserver/eaccelerator_cachevi /usr/local/webserver/php/etc/php.ini
在结尾加入以下内容
[eaccelerator]zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"eaccelerator.shm_size="64"eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"eaccelerator.enable="1"eaccelerator.optimizer="1"eaccelerator.check_mtime="1"eaccelerator.debug="0"eaccelerator.filter=""eaccelerator.shm_max="0"eaccelerator.shm_ttl="3600"eaccelerator.shm_prune_period="3600"eaccelerator.shm_only="0"eaccelerator.compress="1"eaccelerator.compress_level="9"
编译安装apc
cd /usr/local/srctar -zxvf APC-3.1.9.tgzcd APC-3.1.9/usr/local/webserver/php/bin/phpize./configure --enable-apc --enable-apc-mmap --with-php-config=/usr/local/webserver/php/bin/php-configmakemake install
然后就是修改/usr/local/webserver/php/etc/目录下的php.ini,添加apc模块
extension = "apc.so"apc.enabled = 1apc.cache_by_default = onapc.shm_segments = 1apc.shm_size = 32Mapc.ttl = 3600apc.user_ttl = 3600apc.num_files_hint = 0apc.write_lock = On
三、安装NGINX
首先是建立好用户组
groupadd wwwuseradd -s /sbin/nologin -g www www #www用户不能loginmkdir -p /home/wwwroot #此路径是用于存放各域名的root路径chmod +w /home/wwwrootmkdir -p /home/wwwlogschmod 755 /home/wwwlogschown -R www:www /home/wwwroot
安装Nginx
tar zxvf nginx-1.0.15.tar.gzcd nginx-1.0.15/./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_modulemake && make installmkdir /usr/local/webserver/nginx/conf/vhost/ #用于配置各域名
修改Nginx的配置文件
rm -f /usr/local/webserver/nginx/conf/nginx.confvi /usr/local/webserver/nginx/conf/nginx.conf
输入以下内容
user www www;worker_processes 1;error_log /home/wwwlogs/nginx_error.log crit;pid /usr/local/webserver/nginx/logs/nginx.pid;#Specifies the value for maximum file descriptors that can be opened by this process.worker_rlimit_nofile 51200;events{ use epoll; worker_connections 51200;}http{ include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 256k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; #limit_zone crawler $binary_remote_addr 10m; #log format log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for '; include vhost/*.conf;}
这是基本的nginx配置,接着是设定每个域名的配置信息
cd /usr/local/webserver/nginx/conf/vhostvi domain.com.conf
输入以下内容,这样nginx就可以支持php了。注意,请根据自身需要设定domain.com
server{ listen 80; server_name www.domain.com domain.com; index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/domain.com/www; location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } access_log /home/wwwlogs/domain.com.access.log;}
然后为刚刚的域名创建root目录 mkdir -p /home/wwwroot/domain.com/www/
因为默认是没有nginx管理脚本的,在此先新建一个,运行vi /etc/init.d/nginx
,输入
#! /bin/sh# chkconfig: 2345 55 25# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and# run 'update-rc.d -f nginx defaults ', or use the appropriate command on your# distro. For CentOS/Redhat run: 'chkconfig --add nginx '### BEGIN INIT INFO# Provides: nginx# Required-Start: $all# Required-Stop: $all# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: starts the nginx web server# Description: starts nginx using start-stop-daemon### END INIT INFOPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binDESC="nginx daemon"NAME=nginxDAEMON=/usr/local/webserver/nginx/sbin/$NAMECONFIGFILE=/usr/local/webserver/nginx/conf/$NAME.confPIDFILE=/usr/local/webserver/nginx/logs/$NAME.pidSCRIPTNAME=/etc/init.d/$NAMEset -e[ -x "$DAEMON" ] || exit 0do_start() {$DAEMON -c $CONFIGFILE || echo -n "nginx already running"}do_stop() {kill -INT `cat $PIDFILE` || echo -n "nginx not running"}do_reload() {kill -HUP `cat $PIDFILE` || echo -n "nginx can 't reload"}case "$1" instart)echo -n "Starting $DESC: $NAME"do_startecho ".";;stop)echo -n "Stopping $DESC: $NAME"do_stopecho ".";;reload|graceful)echo -n "Reloading $DESC configuration..."do_reloadecho ".";;restart)echo -n "Restarting $DESC: $NAME"do_stopdo_startecho ".";;*)echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2exit 3;;esacexit 0
为该文件增加执行权限,并设置为自启动
chmod +x /etc/init.d/nginxchkconfig nginx on
环境说明
直接输入以下命令,会得到相应的结果
service nginx restart
重启nginxservice mysqld restart
重启mysqlservice php-fpm restart
重启php-fpmservice php-fpm stop
停止php-fpmservice php-fpm start
启动php-fpm
各站点的根目录是/home/wwwroot/
应用的目录是 /usr/local/webserver/
各配置文件的存放位置是:
php: /usr/local/webserver/php/etc/
mysql: /etc/
nginx: /usr/local/webserver/nginx/conf/
FAQ:
- 启动nginx的时候遇到 error while loading shared libraries: libpcre.so.1:
答:增加以下软连接,注意,如果是64位系统,对应目录是/lib64
#cd /lib64cd /libln -s libpcre.so.0.0.1 libpcre.so.1
参考:
CentOS 6.2编译安装Nginx1.0.14+MySQL5.5.22+PHP5.3.10 http://www.osyunwei.com/archives/3339.html
Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器(第6版)[原创]http://blog.s135.com/nginx_php_v6/ LNMP一键安装 http://lnmp.org/
- CentOS 6.2 上编译安装 Nginx 1.0.15 + PHP 5.3.16 + MySQL 5.1.62
- CentOS 6.2 上编译安装 Nginx 1.0.15 + PHP 5.3.16 + MySQL 5.1.62
- CentOS 6.2 上编译安装 Nginx 1.0.15 + PHP 5.3.16 + MySQL 5.1.62
- CentOS 6.2 上编译安装 Nginx 1.0.15 + PHP 5.3.12 + MySQL 5.1.62
- CentOS 编译 nginx+php+mysql 安装手记
- CentOS 编译 nginx+php+mysql 安装手记
- CentOS 编译 nginx+php+mysql 安装手记
- CentOS 6 编译安装Nginx+PHP+Mysql
- Centos 6.3 编译安装Nginx+php+Mysql
- CentOS 7.0编译安装Nginx+MySQL+PHP
- CentOS 7.0编译安装Nginx+MySQL+PHP
- Centos 6.3 编译安装Nginx+php+Mysql
- CentOS 7.0编译安装Nginx+MySQL+PHP
- Centos 6.5 编译安装Nginx+php+Mysql
- centos + nginx + mysql + php 环境编译安装
- 虚拟机上CentOS 7.0编译安装Nginx+MySQL+PHP(一)
- 虚拟机上CentOS 7.0编译安装Nginx+MySQL+PHP(二)
- CentOS上yum安装nginx+mysql+php+php-fastcgi
- 用C自己编写telnet服务器
- memory:arm 分区layout以及虚拟内存布局-小结
- C标准库
- 无意中发现一个js网站,先记录下来,有空再研究
- 枚举类型
- CentOS 6.2 上编译安装 Nginx 1.0.15 + PHP 5.3.16 + MySQL 5.1.62
- makefile
- 关于eclipse库文件的导入 jar
- 第二次c程序设计上机报告
- linux 下常用命令记录
- 获取外网IP
- 《深入理解计算机系统 2nd》部分读书笔记---第9章 虚拟存储器(未完成)
- 使用strace+pstack利器分析程序性能
- 添加缅甸语的流程