前几天刚好因为某些原因接触腾讯云(qcloud.com),又因为那个亿元扶持活动,遂出了几十大洋买了一个最低配置的来玩玩。为了不浪费也是因为是国内主机,所以又将路过图床(http://imgchr.com)迁移到腾讯云。原来用的是apache环境,要切换到nginx那些伪静态啊什么的,用lnmp一键安装包却偏偏出了问题,求助程序的开发者,得出结果可以运行在nginx且nginx规则也正常使用。这就奇怪了,于是JiaJieChan就开始了手动配置LNMP的头了。
下文转载,也有一些添加的。出处请看文章底部。
系统:Centos 6.3 64位
要安装的组件:php-5.4.31 、mysql5.5.25a 、nginx 1.3.0、zend optimizer
首先清除系统默认安装好的mysql或apache,如果你的系统已经干净了请跳过;
查看服务器是否有安装相关的包
rpm -qa | grep mysql
rpm -qa | grep apache
如果有则使用rpm -e --nodeps
删除掉;
rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
然后开始配置环境
安装支持套件
好,先来Nginx 1.3.0
安装支持套件
yum -y install 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
下载必须的组件
pcre-8.31.tar.gz 让nginx支持rewrite
下载地址:http://sourceforge.net/projects/pcre/files/pcre/8.31/pcre-8.31.tar.gz/download
安装pcre-8.31.tar.gz
1、解压 pcre
tar zxvf pcre-8.31.tar.gz
2、配置 pcre
cd pcre-8.31
./configure
配置时如果报 configure: error: no acceptable C compiler found in $PATH 错误
可参考:nginx安装 configure: error: no acceptable C compiler found in $PATH
3、编译
make
编译时如果报 make[3]: *** [install-data-hook] Error 1错误
可参考:pcre-8.31安装 make[3]: *** [install-data-hook] Error 1错误
编译时如果报 make[1]: *** [pcrecpp.lo] Error 1错误
可参考:nginx安装出错 make[1]: *** [pcrecpp.lo] Error 1
4、安装
make install
添加nginx需要的用户组及用户
#/usr/sbin/groupadd -f nginx
#/usr/sbin/useradd -g ningx nginx
安装nginx
首先当然是wget下载,wget http://nginx.org/download/nginx-1.3.0.tar.gz
1、解压 nginx
tar zxvf nginx-1.3.0.tar.gz
2、配置nginx,默认的安装目录在/usr/local/nginx
cd nginx-1.3.0
./configure --with-http_ssl_module
#configure后面这段是增加ssl组件,不需要可以去掉为了以后;
引用:http://www.linuxidc.com/Linux/2012-06/62660.htm
3、编译nginx
make
4、安装
make install
5、启动服务
service nginx start 或者/usr/local/nginx/sbin/nginx
启动时如果报 error while loading shared libraries: libpcre.so.1:错误
可参考:nginx启动出错 error while loading shared libraries: libpcre.so.1:
配置或启动时如果报 nginx: [emerg] getpwnam(“www”) failed 错误
可参考:nginx安装 nginx: [emerg] getpwnam(“www”) failed 错误
6、访问服务器的IP地址,成功之后页面将显示以下信息
Welcome to nginx!
mysql5.5.25
下载mysql安装文件
1、wget下载如下文件
MySQL-server-5.5.25-1.rhel5 wget http://dev.mysql.com/get/archives/mysql-5.5/MySQL-server-5.5.25a-1.rhel5.x86_64.rpm
MySQL-devel-5.5.25-1.rhel5 wget http://dev.mysql.com/get/archives/mysql-5.5/MySQL-devel-5.5.25-1.rhel5.x86_64.rpm
MySQL-client-5.5.25-1.rhel5 wget http://dev.mysql.com/get/archives/mysql-5.5/MySQL-client-5.5.25-1.rhel5.x86_64.rpm
安装mysql5.5.25
1、进入安装文件的目录
2、安装mysql服务端
# rpm -ivh MySQL-server-5.5.25a-1.rhel5.x86_64.rpm
如图:mysql-server安装
安装过程中可能出现后面的错误:error: Failed dependencies: libaio.so.1()(64bit) is needed by MySQL-server
3、安装mysql客户端、mysql-devel
# rpm -ivh MySQL-client-5.5.25a-1.rhel5.x86_64.rpm
# rpm -ivh MySQL-devel-5.5.25a-1.rhel5.x86_64.rpm
如图:mysql-client-devel
启动mysql服务
# service mysql start
修改mysql中root的初始化密码
1、命令如下:
# /usr/bin/mysqladmin -u root password ‘rootadmin’
格式:mysqladmin -u用户名 -p旧密码 password 新密码
2、例子
# /usr/bin/mysqladmin -u root password ‘rootadmin’
注:因为开始时root没有密码,所以-p旧密码一项就可以省略了
3、用新的密码进行登录,如下图所示:
重启与停止mysql服务
启动方式1:service mysql start
启动方式2:/etc/init.d/mysql start
停止方式1:service mysql stop
停止方式2:/etc/init.d/mysql shutdown
重启方式1:service mysql restart
重启方式2:/etc/init.d/mysql restart
php-5.4.31
安装支持库
1) pcre-8.30.tar.gz 下载
# tar zxvf pcre-8.30.tar.gz
# cd pcre-8.30
# ./configure
# make
# make install
2) libiconv-1.14.tar.gz 下载
# tar zxvf libiconv-1.14.tar.gz
# cd libiconv-1.14
# ./configure
# make
# make install
3) libmcrypt-2.5.8.tar.gz 下载
# tar zxvf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8
# ./configure
# make
# make install
4) mhash-0.9.9.9.tar.gz 下载
# tar zxvf mhash-0.9.9.9.tar.gz
# cd mhash-0.9.9.9
# ./configure
# make
# make install
5) mcrypt-2.6.8.tar.gz 下载
# tar zxvf mcrypt-2.6.8.tar.gz
# cd mcrypt-2.6.8
# ./configure
# make
# make install
配置时如果报 configure: error: *** libmcrypt was not found 错误
可参考:configure: error: *** libmcrypt was not found 错误解决
安装php-5.4.31
# tar zvxf php-5.4.31.tar.gz
# cd php-5.4.31
# ./configure -prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –with-mysql=/usr –with-mysqli=/usr/bin/mysql_config –with-iconv-dir=/usr/local/lib –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –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-ldap –with-ldap-sasl –with-xmlrpc –enable-zip –enable-soap –without-pear –with-fpm-user=www –with-fpm-group=www -with-pdo-mysql -with-mysql-sock=/var/lib/mysql/mysql.sock
上面最后一段pdo是在测试路过图床的时候发现错误的,所以在写这篇文章的时候才加上的,解决了不少问题。
对于一些新的程序如果没有加上,会报错Undefined class constant 'MYSQL_ATTR_INIT_COMMAND';
引用:http://blog.51yip.com/server/1514.html
# make
# make install
编译中的错误解决
1、如果配置当中报 configure: error: Cannot find ldap libraries in /usr/lib. 错误
具体的解决办法请参考:解决php configure: error: Cannot find ldap libraries in /usr/lib.错误
2、如果配置当中报 configure: error: Cannot find MySQL header files under /usr/share/mysql. 错误
说明指定的安装目录不对
解决办法:将–with-mysql=/usr/share/mysql 改成–with-mysql=/usr
3、如果配置当中报
configure: error: Cannot find libmysqlclient under /usr.
Note that the MySQL client library is not bundled anymore! 错误
具体的解决办法请参考:configure: error: Cannot find libmysqlclient under /usr.错误解决
4、如果配置当中报 make: *** [sapi/cli/php] Error 1 错误
具体的解决办法请参考:make: *** [sapi/cli/php] Error 1错误解决
复制php配置文件
# cp php.ini-production /usr/local/php/lib/php.ini
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# /usr/local/php/bin/php –ini #测试ini文件是否加载
编辑php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
[global] pid = run/php-fpm.pid error_log = log/php-fpm.log log_level = notice [www] listen = 127.0.0.1:9000 user = www group = www pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 5000
测试php-fpm配置
/usr/local/php/sbin/php-fpm -t
如果显示以下信息,则说明安装成功
NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
启动php-fpm
/usr/local/php/sbin/php-fpm
如果启动报错:ERROR: [pool www] cannot get uid for user ‘www’
增加用户即可,具体的代码:useradd www -M -s /sbin/nologin
到此为止,整个php安装完成
Zend Optimizer安装
wget -c http://live.utoptoy.com/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
zend_loader.disable_licensing=0
zend_extension=/usr/local/Zend/ZendGuardLoader.so
zend_loader.enable=1 使ZendGuardLoader启用加载编码的脚本。默认值是
zend_loader.disable_licensing=0 禁用许可证检查(出于性能原因)
zend_loader.disable_licensing=0 设置文件ZendGuardLoader.so的路径
#/usr/local/php/sbin/php-fpm restart
#或者如下:
#service php-fpm restart;
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies
增加php、nginx等开机启动和start、restart、stop的快捷参数
Nginx启动脚本/etc/init.d/nginx
vi /etc/init.d/nginx
#!/bin/bash # # Startup script for Nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server # processname: nginx # config: /usr/local/nginx/conf/nginx.conf # pidfile: /usr/local/nginx/logs/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac
编辑好后保存,执行以下命令
sudo chmod +x /etc/init.d/nginx sudo /sbin/chkconfig nginx on # 检查一下 sudo /sbin/chkconfig --list nginx nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
完成!可以使用以下命令管理Nginx了
service nginx start service nginx stop service nginx restart service nginx reload /etc/init.d/nginx start /etc/init.d/nginx stop /etc/init.d/nginx restart /etc/init.d/nginx reload
PHP-FPM启动脚本/etc/init.d/php-fpm
#!/bin/bash # # Startup script for the PHP-FPM server. # # chkconfig: 345 85 15 # description: PHP is an HTML-embedded scripting language # processname: php-fpm # config: /usr/local/php/etc/php.ini # Source function library. . /etc/rc.d/init.d/functions PHP_PATH=/usr/local DESC="php-fpm daemon" NAME=php-fpm # php-fpm路径 DAEMON=$PHP_PATH/php/sbin/$NAME # 配置文件路径 CONFIGFILE=$PHP_PATH/php/etc/php-fpm.conf # PID文件路径(在php-fpm.conf设置) PIDFILE=$PHP_PATH/php/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME # Gracefully exit if the package has been removed. test -x $DAEMON || exit 0 rh_start() { $DAEMON -y $CONFIGFILE || echo -n " already running" } rh_stop() { kill -QUIT `cat $PIDFILE` || echo -n " not running" } rh_reload() { kill -HUP `cat $PIDFILE` || echo -n " can't reload" } case "$1" in start) echo -n "Starting $DESC: $NAME" rh_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" rh_stop echo "." ;; reload) echo -n "Reloading $DESC configuration..." rh_reload echo "reloaded." ;; restart) echo -n "Restarting $DESC: $NAME" rh_stop sleep 1 rh_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2 exit 3 ;; esac exit 0
编辑好后保存,执行以下命令
sudo chmod +x /etc/init.d/php-fpm sudo /sbin/chkconfig php-fpm on # 检查一下 sudo /sbin/chkconfig --list php-fpm php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
完成!可以使用以下命令管理php-fpm了
service php-fpm start service php-fpm stop service php-fpm restart service php-fpm reload /etc/init.d/php-fpm start /etc/init.d/php-fpm stop /etc/init.d/php-fpm restart /etc/init.d/php-fpm reload
最后根据我的情况,修改php.ini最大上传大小无效,原来还要复制php.ini到以下位置。
以后直接修改这个位置的php.ini即可。
如果也是这个问题可以试试下面的命令。
cp /usr/local/php/lib/php.ini /usr/local/php/etc/
完成后,相关文件路径;
php.ini /usr/local/php/lib/php.ini
php-fpm /usr/local/php/etc/php-fpm.conf
mysql.sock /var/lib/mysql/mysql.sock
本文转自:http://www.iitshare.com/centos-6-3-64-bit-environment-to-build.html
2 comments
这个是属于个人博客么
这年头坚持写博客的人不多。
这个你是购买的正版程序么?貌似要不少钱吧?