das Doc

登录/注册
centos+nginx+php5.4+mysql
编辑
==添加web server用户==
useradd -r www-data
useradd -r mysql

==创建文件夹==
sudo mkdir /opt #源文件与安装目录 /opt/local
sudo mkdir /etc/php #php配置项
sudo mkdir -p /var/lib/mysql #mysql socket目录
sudo mkdir -p /var/www/vhost #网站根目录
sudo mkdir /var/log/nginx #网站log目录
sudo mkdir /var/log/mysql #网站logo目录
sudo chown -R mysql:mysql /var/log/mysql

==PHP libmcrypt==
$getconf LONG_BIT
/*64*/
wget http://elders.princeton.edu/data/puias/unsupported/6/x86_64/libmcrypt-2.5.8-9.puias6.x86_64.rpm
$ wget http://elders.princeton.edu/data/puias/unsupported/6/x86_64/libmcrypt-devel-2.5.8-9.puias6.x86_64.rpm
$ rpm -ivh libmcrypt-2.5.8-9.puias6.x86_64.rpm
$ rpm -ivh libmcrypt-devel-2.5.8-9.puias6.x86_64.rpm

/*32*/
$sudo wget http://elders.princeton.edu/data/puias/unsupported/6/x86_64/libmcrypt-2.5.8-9.puias6.i686.rpm
$sudo wget http://elders.princeton.edu/data/puias/unsupported/6/x86_64/libmcrypt-devel-2.5.8-9.puias6.i686.rpm
$sudo rpm -ivh libmcrypt-2.5.8-9.puias6.i686.rpm
$sudo rpm -ivh libmcrypt-devel-2.5.8-9.puias6.i686.rpm

==依赖 包==
sudo yum -y install wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libXpm-devel freetype-devel t1lib-devel libxslt-devel libmcrypt-devel bzip2-devel bzip2 libxml2 libxml2-devel


==install nginx==
$ cd /opt/nginx-1.2.6

$ sudo ./configure  --prefix=/opt/local --with-http_ssl_module --conf-path=/etc/nginx/nginx.conf --user=www-data --group=www-data --with-http_gzip_static_module --with-http_stub_status_module
$ sudo make ;
$ sudo make install;
$ sudo vim /etc/init.d/nginx

---------------
#!/bin/sh
#
# 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: /opt/nginx/conf/nginx.conf
# pidfile: /opt/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="/opt/nginx/sbin/nginx"
#NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"

nginx="/opt/local/sbin/nginx"
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
prog=$(basename $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
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 755 /etc/init.d/nginx
$ sudo /etc/init.d/nginx start
$ sudo chkconfig --add nginx
$ sudo chkconfig nginx on
$ sudo chkconfig --list  //check

$ sudo vim  /etc/nginx/nginx.conf //修发基本配置项
-----------
worker_processes  4; //lscpu
events {
    worker_connections  65536;
}
#http
gzip on;
gzip_min_length         1k;
gzip_buffers            4 16k;
gzip_http_version       1.1;
gzip_comp_level         2;
gzip_types              text/plain application/x-javascript text/css app
lication/xml;
gzip_vary               on;


include /etc/nginx/conf.d/*.conf;
-----------

sudo vim /etc/sysconfig/iptables //添加80端口
sudo /etc/init.d/iptables restart

================================================
安装php
$ cd /opt/
$ sudo wget http://cn2.php.net/distributions/php-5.4.10.tar.gz
$ sudo tar -xvf php-5.4.10.tar.gz
$ cd /opt/php-5.4.10


$ sudo ./configure --prefix=/opt/local --with-config-file-path=/etc/php --with-curl --with-pear --with-gd --with-jpeg-dir --with-png-dir --with-zlib --with-xpm-dir --with-freetype-dir --with-t1lib --with-mcrypt --with-mhash --with-mysql --with-mysqli --with-pdo-mysql --with-openssl --with-xmlrpc --with-xsl --with-bz2 --with-gettext --with-fpm-user=www-data --with-fpm-group=www-data --enable-fpm --enable-exif --enable-wddx --enable-zip --enable-bcmath --enable-calendar --enable-ftp --enable-mbstring --enable-soap --enable-sockets --enable-shmop --enable-dba --enable-sysvmsg --enable-sysvsem --enable-sysvshm


sudo ./configure --with-libdir=lib64 --prefix=/opt/local --with-config-file-path=/etc/php --with-curl --with-pear --with-gd --with-jpeg-dir --with-png-dir --with-zlib --with-xpm-dir --with-freetype-dir --with-t1lib --with-mcrypt --with-mhash --with-mysql --with-mysqli --with-pdo-mysql --with-openssl --with-xmlrpc --with-xsl --with-bz2 --with-gettext --with-fpm-user=www-data --with-fpm-group=www-data --enable-fpm --enable-exif --enable-wddx --enable-zip --enable-bcmath --enable-calendar --enable-ftp --enable-mbstring --enable-soap --enable-sockets --enable-shmop --enable-dba --enable-sysvmsg --enable-sysvsem --enable-sysvshm

$ sudo make && make install
//如果文件配错了,可以使用make -n install 找出源文件,然后再删掉所有
sudo make -n install|grep mkdir
sudo rm -rf /usr/local/php /usr/local/lib/php /usr/local/include/php /usr/local/bin/php*

//如果源文件还有的话,可以试试这个
'make install DESTDIR=/tmp/php'.

//配置
$ sudo cp /opt/php-5.4.10/sapi/fpm/php-fpm.conf /etc/php/ && sudo cp /opt/php-5.4.10/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && sudo chmod 755 /etc/init.d/php-fpm


$ sudo vim /etc/init.d/php-fpm
--------
php_fpm_CONF=/etc/php/php-fpm.conf
php_fpm_PID=/var/run/php-fpm.pid
--------

$  sudo touch /var/run/php-fpm.pid
$  sudo /etc/init.d/php-fpm start

$ sudo chkconfig --add php-fpm
$ sudo chkconfig php-fpm on

================================================

// nginx+php 配置
//nginx conf
//set $domain "www.zmaitech.com";
location ~ \.php$ {
                include /etc/nginx/fastcgi_params;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /var/www/vhosts/${domain}/$fastcgi_script_name;
        }
================================================

安装mysql

$ yum -y install ncurses-devel.x86_64 bison-devel.x86_64 libaio-devel.x86_64 gcc-c++.x86_64 cmake.x86_64 ncurses-devel.x86_64 clang-devel.x86_64

$ cd /opt
$ sudo wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.29.tar.gz

$ sudo tax xvf mysql-5.5.29.tar.gz
$ cd mysql-5.5.29
$ sudo cmake -DCMAKE_INSTALL_PREFIX=/opt/local/mysql -DMYSQL_DATADIR=/data/dbdata -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/opt/local/mysql/tmp/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_SSL=yes

//当编译出错需重新编辑,请首先sudo rm CMakeCache.txt

$ sudo make && sudo make install;

================================================
配置mysql
$ sudo /opt/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/opt/local/mysql --datadir=/data/dbdata

$ sudo cp /opt/local/mysql/support-files/my-huge.cnf /etc/my.cnf
$ sudo cp /opt/local/mysql/support-files/mysql.server /etc/init.d/mysqld
$ sudo chmod 755 /etc/init.d/mysqld
$ sudo chkconfig --add mysqld
$  sudo chkconfig --level 3 mysqld on

===mysql secure ====
$ sudo /etc/init.d/mysqld start
$ cd /opt/local/mysql && sudo /opt/local/mysql/bin/mysql_secure_installation #配密码

===重要===
# mysql 里的localhost 链接为/var/lib/mysql/mysql.sock, 用户在自定义配置有时只能用127.0.0.1不能用localhost时,需要创建一个链接
$ sudo ln -s /opt/local/mysql/tmp/mysql.sock /var/lib/mysql/mysql.sock 
或者
$ sudo ln -s /opt/local/mysql/tmp/mysql.sock /tmp/mysql.sock 
链接后,需要重启
sudo /etc/init.d/mysqld restart
注册新帐户
欢迎使用本网站服务,请遵守国家法律法规。
支持原创,您在网站上发布的所有作品著作权归您所有。
登录
记住我 使用公用电脑请勿选择此功能

帐户设置

基本信息 修改密码 阅读模式