Ubuntu8.04下 nginx+php+mysql+zend

[Ubuntu8.04 server]下构建nginx+php+mysql+zend
ubuntu8.04 server的下载地址可以去 www.ubuntu.org.cn去找。安装采用默认安装,不选择任何的服务。
一、设置root权限。
设置root权限,这样下面安装的过程中,不用总sudo了。
复制内容到剪贴板代码:sudo passwd root
设置好root的密码以后。
复制内容到剪贴板代码:su -
输入密码,换成root权限。

二、设置apt源。

ubuntu安装完毕以后,默认的apt源速度可能会很慢。所以,首先是修改一下apt的源,提高软件的下载速度。建议大家可以选择ubuntu官方的源,中国台湾省的源和cn99的源。
复制内容到剪贴板代码:
cp /etc/apt/sources.list /etc/apt/sources.list.bak
nano /etc/apt/sources.list  
删除里面所有的内容,修改成(白天速度快,晚上速度比较慢。电信和网通都可以)
复制内容到剪贴板代码:deb http://archive.ubuntu.com/ubuntu/ hardy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ hardy-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ hardy-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ hardy-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ hardy-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ hardy main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ hardy-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ hardy-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ hardy-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ hardy-backports main restricted universe multiverse
(下面的源,推荐电信用户使用。有的时候网通的用户访问速度也非常的快)
复制内容到剪贴板代码:deb http://ubuntu.cn99.com/ubuntu/ hardy main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ hardy-security main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ hardy-updates main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ hardy-proposed main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ hardy-backports main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ hardy main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ hardy-security main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ hardy-updates main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ hardy-proposed main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ hardy-backports main restricted universe multiverse
(中国台湾省的源,晚上的速度非常的好)
复制内容到剪贴板代码:deb http://tw.archive.ubuntu.com/ubuntu hardy main restricted universe multiverse
deb http://tw.archive.ubuntu.com/ubuntu hardy-security main restricted universe multiverse
deb http://tw.archive.ubuntu.com/ubuntu hardy-updates main restricted universe multiverse
deb http://tw.archive.ubuntu.com/ubuntu hardy-backports main restricted universe multiverse
deb http://tw.archive.ubuntu.com/ubuntu hardy-proposed main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu hardy main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu hardy-security main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu hardy-updates main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu hardy-backports main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu hardy-proposed main restricted universe multiverse
上面的三个源,大家可以根据自己的需要来设置。

保存,退出nano。
复制内容到剪贴板代码:apt-get update
三、安装一些必要的软件。

ubuntu安装以后,有一些包是没有安装上的。我们需要安装上,否则下面的编译将会出现问题。
复制内容到剪贴板代码:apt-get install binutils cpp fetchmail flex gcc libarchive-zip-perl libc6-dev libcompress-zlib-perl libdb4.3-dev libpcre3 libpopt-dev lynx m4 make ncftp nmap perl perl-modules unzip zip zlib1g-dev autoconf automake1.9 libtool bison autotools-dev g++ build-essential libpcre3-dev libncurses5-dev libcurl4-openssl-dev openssh-server openssh-client
四、设置安装目录,下载必要的软件。

安装完毕以后,我们建立几个目录,用来进行下一步的安装。
复制内容到剪贴板代码:mkdir /var/software (用来存放安装软件)
mkdir /usr/local/webserver (安装目录,nginx,php等都安装在这个目录下)
mkdir /usr/local/webserver/webdata (发布目录)
mkdir /usr/local/webserver/log (存放nginx的日志文件)
下载编译需要的各种软件,全部放到/var/software下
mysql-5.0.51a
http://dev.mysql.com/get/Downloads/M...rloo.ca/mysql/

php-5.2.6
http://cn.php.net/distributions/php-5.2.6.tar.bz2

nginx-0.5.35
http://sysoev.ru/nginx/nginx-0.5.35.tar.gz

libiconv-1.11
http://download.chyangwa.com/linux/l...nv-1.11.tar.gz

freetype-2.3.5
http://download.savannah.gnu.org/rel...e-2.3.5.tar.gz

libpng-1.2.29(注意,大家不要使用1.2.28这个版本,似乎有很多问题)
http://jaist.dl.sourceforge.net/sour...-1.2.29.tar.gz

jpegsrc.v6b
http://down1.chinaunix.net/distfiles/jpegsrc.v6b.tar.gz

libxml2-2.6.30
http://ftp.gnome.org/pub/GNOME/sourc...-2.6.30.tar.gz

libmcrypt-2.5.8
http://nchc.dl.sourceforge.net/sourc...t-2.5.8.tar.gz

mhash-0.9.9
http://jaist.dl.sourceforge.net/sour...h-0.9.9.tar.gz

mcrypt-2.6.7
http://jaist.dl.sourceforge.net/sour...t-2.6.7.tar.gz

memcache-2.2.3
http://pecl.php.net/get/memcache-2.2.3.tgz

pcre-7.6
http://nchc.dl.sourceforge.net/sourc...cre-7.6.tar.gz

zend
http://www.phpchina.com/download/sho...=ZendOptimizer

为了方便大家,已将上面所有的软件包下载后打包,提供本地下载,这样就不用担心死链了
http://www.ubuntuchina.com/Download/2659/soft/nginxall.zip


五、编译安装PHP所需的支持库。
复制内容到剪贴板代码:cd /var/software
tar zxvf libiconv-1.11.tar.gz
cd libiconv-1.11/
./configure --prefix=/usr/local
make
make install
cd ../

tar zxvf freetype-2.3.5.tar.gz
cd freetype-2.3.5/
./configure
make
make install
cd ../

tar zxvf libpng-1.2.29.tar.gz
cd libpng-1.2.29/
./configure
###mv scripts/makefile.linux ./makefile
make
make install
cd ../

tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
./configure --enable-static --enable-shared
make
make install
make install-lib
cd ../

tar zxvf libxml2-2.6.30.tar.gz
cd libxml2-2.6.30/
./configure
make
make install
cd ../

tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../

tar zxvf mhash-0.9.9.tar.gz
cd mhash-0.9.9/
./configure
make
make install
cd ../

cp /usr/local/lib/libmcrypt.* /usr/lib
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

tar zxvf mcrypt-2.6.7.tar.gz
cd mcrypt-2.6.7/
./configure
make
make install
cd ../
六、编译安装MySQL
复制内容到剪贴板代码:tar zxvf mysql-5.0.51b.tar.gz
cd mysql-5.0.51b
./configure --prefix=/usr/local/webserver/mysql --localstatedir=/var/lib/mysql --with-comment=Source --with-server-suffix=-enterprise-gpl --with-mysqld-user=mysql --without-debug --with-unix-socket-path=/tmp/mysql.sock --with-big-tables --with-extra-charsets=gbk,latin1,utf8 --with-pthread --enable-static --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-innodb --without-ndb-debug --without-isam --enable-local-infile --with-readline --with-raid --enable-thread-safe-client
make
make install
groupadd mysql
useradd -g mysql mysql
cd /usr/local/webserver/mysql
bin/mysql_install_db --user=mysql
chown -R root:mysql . (设置权限,注意后面有一个 ".")
chown -R mysql /var/lib/mysql (设置 mysql 目录权限。数据库就放在这里了)
chgrp -R mysql . (注意后面有一个 ".")
cp share/mysql/my-medium.cnf /etc/my.cnf
cp share/mysql/mysql.server /etc/init.d/mysqld (为了开机可以自动启动 mysql。)
chmod 755 /etc/init.d/mysqld
echo "/usr/local/webserver/mysql/lib" >> /etc/ld.so.conf (添加LIB PATH)
运行以下命令即可启动 MySQL 服务器:
/etc/init.d/mysqld start (启动 MySQL)
bin/mysqladmin -u root password "password_for_root"(设置mysql的root密码)
/etc/init.d/mysqld stop (关闭 MySQL)

nano /etc/rc.local
在最后加入:/etc/init.d/mysqld start(这样开机的时候,mysql就可以自动启动了。)
七、编译安装PHP(FastCGI模式)
复制内容到剪贴板代码:
cd /var/software
tar zxvf php-5.2.6.tar.gz
cd php-5.2.6
./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-debug --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --disable-ipv6 --enable-soap --with-openssl --with-gettext --disable-rpath

sed -i 's#-lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt#& -liconv#' Makefile
make
make install
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
cd ../  
八、编译安装PHP5扩展模块
复制内容到剪贴板代码:tar zxvf memcache-2.2.3.tgz
cd memcache-2.2.3/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

cd php-5.2.6/ext/gd/
/usr/local/webserver/php/bin/phpize
./configure --with-jpeg-dir --with-png-dir --with-zlib-dir --with-ttf --with-freetype-dir --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../../../
九、对php进行一些设置,并且为安装nginx做一些准备工作。

1、修改php.ini文件
手工修改:查找/usr/local/webserver/php/etc/php.ini中的extension_dir = "./"
修改为extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"
并在此行后增加以下几行,然后保存。
复制内容到剪贴板代码:extension = "memcache.so"
extension = "gd.so"
自动修改:若嫌手工修改麻烦,可执行以下shell命令,自动完成对php.ini文件的修改:
复制内容到剪贴板代码:
sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"/nextension = "memcache.so"/nextension = "gd.so"/n#' /usr/local/webserver/php/etc/php.ini  
2、创建www用户和组,以及其使用的目录。
复制内容到剪贴板代码:/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -u 48 -g www www
chmod +w /usr/local/webserver/webdata/
chown -R www:www /usr/local/webserver/webdata/
3、安装lighttpd中附带的spawn-fcgi,用来启动php-cgi
复制内容到剪贴板代码:cp spawn-fcgi /usr/local/webserver/php/bin
chmod +x /usr/local/webserver/php/bin/spawn-fcgi
4、启动php-cgi进程,监听127.0.0.1的10080端口,进程数为64(可以根据自己的情况来设置。如果服务器内存小于3GB,可以只开启25个进程。),用户为www。
复制内容到剪贴板代码:
/usr/local/webserver/php/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 64 -u www -f /usr/local/webserver/php/bin/php-cgi  
十、安装Nginx 0.5.33

1、安装Nginx所需的pcre库。
复制内容到剪贴板代码:tar zxvf pcre-7.6.tar.gz
cd pcre-7.6/
./configure
make && make install
cd ../
2、安装Nginx。
复制内容到剪贴板代码:
tar zxvf nginx-0.5.35.tar.gz
cd nginx-0.5.35/
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module
make
make install
cd ../  
3、创建Nginx日志目录。
复制内容到剪贴板代码:
chmod +w /usr/local/webserver/logs
chown -R www:www /usr/local/webserver/logs  
4、创建Nginx配置文件。
在/usr/local/webserver/nginx/conf/目录中创建nginx.conf文件。
复制内容到剪贴板代码:rm -f /usr/local/webserver/nginx/conf/nginx.conf
nano /usr/local/webserver/nginx/conf/nginx.conf
输入以下内容。
复制内容到剪贴板代码:user www www;

worker_processes 10;

error_log /usr/local/webserver/logs/nginx_error.log crit;

#pid 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 conf/mime.types;
default_type application/octet-stream;

charset gb2312;

server_names_hash_bucket_size 128;

#sendfile on;
#tcp_nopush on;

keepalive_timeout 60;

tcp_nodelay on;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/html application/xml;

server
{
listen 80;
server_name servername.com;
index index.html index.htm index.php;
root /usr/local/webserver/webdata;

if (-d $request_filename)
{
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}

location ~ .*.php?$
{
include conf/fcgi.conf;
fastcgi_pass 127.0.0.1:10080;
fastcgi_index index.php;
}

log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /usr/local/webserver/logs/access.log access;
}

server
{
listen 80;
server_name status.servername.com;

location / {
stub_status on;
access_log off;
}
}
}
保存,退出nano。

5、在/usr/local/webserver/nginx/conf/目录中创建fcgi.conf文件。
复制内容到剪贴板代码:nano /usr/local/webserver/nginx/conf/fcgi.conf
输入以下内容:
复制内容到剪贴板代码:fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
#fastcgi_param REDIRECT_STATUS 200;
6、启动Nginx
复制内容到剪贴板代码:
ulimit -SHn 51200
/usr/local/webserver/nginx/sbin/nginx -c /usr/local/webserver/nginx/conf/nginx.conf  
7、配置开机自动启动Nginx + PHP
复制内容到剪贴板代码:
nano /etc/rc.local  
在末尾增加以下内容:
复制内容到剪贴板代码:ulimit -SHn 51200
/usr/local/webserver/php/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 64 -u www -f /usr/local/webserver/php/bin/php-cgi
/usr/local/webserver/nginx/sbin/nginx -c /usr/local/webserver/nginx/conf/nginx.conf
十一、优化Linux内核参数
复制内容到剪贴板代码:nano /etc/sysctl.conf
在末尾增加以下内容.
复制内容到剪贴板代码:net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000 65000
使配置立即生效:
复制内容到剪贴板代码:/sbin/sysctl -p
十二、在不停止Nginx服务的情况下平滑变更Nginx配置

修改/usr/local/webserver/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确.
复制内容到剪贴板代码:/usr/local/webserver/nginx/sbin/nginx -t
如果屏幕显示以下两行信息,说明配置文件正确。
复制内容到剪贴板代码:the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/webserver/nginx/conf/nginx.conf was tested successfully
这时,输入以下命令查看Nginx主进程号。
复制内容到剪贴板代码:ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
屏幕显示的即为Nginx主进程号,例如:
4343
这时,执行以下命令即可使修改过的Nginx配置文件生效.
复制内容到剪贴板代码:kill -HUP 4343
十三、安装zend
复制内容到剪贴板代码:cd /var/software
tar zxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
cd ZendOptimizer-3.3.3-linux-glibc23-i386
./install
在询问php.ini的路径的时候,填入.
复制内容到剪贴板代码:/usr/local/webserver/php/etc
web服务器选择不是apache

十四、reboot你的机器。
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值