当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 1 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : ubuntu下安装 nginx php mysql -- 安装笔记
帖子发表于 : 2011-03-08 19:27 
头像

注册: 2008-04-05 10:56
帖子: 129
地址: 学校
送出感谢: 0 次
接收感谢: 0 次
ubuntu下 nginx php mysql 安装笔记

本篇文章参考了 张宴 的《Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器(第6版)[原创]》,在其基础上改造而来,对其表示感谢,因为我个人一直用的是ubuntu

注意:此安装,是用来在自己的机器上开发环境用的,所以编译时选项很多都打开了debug选项,要是做为生产环境的话,在编译时请关掉debug选项,并加上优化参数

本文是 vincentzhwg 所写,转载请注明作者:vincentzhwg

版本

nginx 0.8.54

php 5.3.5

mysql 5.5.9

先下载好所有的文件以便安装,这里下载所有的文件到 /opt/LNMP_src 文件夹中

创建文件夹

mkdir -p /opt/LNMP_src

下载相应的安装源代码包,需要下载的包有以下几种,我以自己下载时的版本号为例

libiconv-1.13.1.tar.gz

libmcrypt-2.5.8.tar.gz

mcrypt-2.6.8.tar.gz

mhash-0.9.9.9.tar.bz2

mysql-5.5.9.tar.gz

nginx-0.8.54.tar.gz

pcre-8.12.zip

php-5.3.5.tar.gz

文件下载可以在网上搜索进入其官网后下载,且压缩格式不一定要跟我下载的相同,就是解压的时候根据不同的压缩格式使用不同的命令

文件也可以从我的CSDN资源空间上下载,列出空间下载地址列表如下:

libiconv-1.13.1.tar.gz : http://download.csdn.net/source/3056449

libmcrypt-2.5.8.tar.gz : http://download.csdn.net/source/3056451

mcrypt-2.6.8.tar.gz : http://download.csdn.net/source/3056452

mhash-0.9.9.9.tar.bz2 : http://download.csdn.net/source/3056457

mysql-5.5.9.tar.gz : http://download.csdn.net/source/3056467

nginx-0.8.54.tar.gz : http://download.csdn.net/source/3056459

pcre-8.12.zip : http://download.csdn.net/source/3056460

php-5.3.5.tar.gz : http://download.csdn.net/source/3056465

安装基本编译工具

apt-get install build-essential automake autoconf

安装压缩解压支持

apt-get install rar unrar zip unzip p7zip p7zip-full

进入到存放这些源代码包的文件夹中

cd /opt/LNMP_src

然后运行以下命令段做安装前的准备

view plaincopy to clipboardprint?
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
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 jxvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
/sbin/ldconfig
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
./configure
make
make install
cd ../
unzip pcre-8.12.zip
cd pcre-8.12/
./configure
make
make install
cd ../


运行完以上命令,再运行下面的命令安装上缺失的包

apt-get install libcurses-ocaml-dev libevent-dev libxml2-dev libssl-dev libcurl-ocaml-dev libjpeg8-dev libpng12-dev libfreetype6-dev libsasl2-dev libbz2-dev libxpm-dev libxslt1-dev cmake libncurses5-dev bison

开始安装 mysql5.5.9

创建用户

groupadd mysql

useradd -g mysql mysql

创建存放数据库数据的文件夹

mkdir -p /mysqlData/3306/data

mkdir -p /mysqlData/3306/binlog

mkdir -p /mysqlData/3306/relaylog

chown -R mysql:mysql /mysqlData/3306

编译

cd /opt/LNMP_src

tar zxvf mysql-5.5.9.tar.gz

cd mysql-5.5.9

运行以下命令行编译 mysql,比较长,记得编译时是把下面的多行一起复制到命令窗口编译

cmake . -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLE_DEBUG_SYNC=1 -DENABLED_LOCAL_INFILE=1 -DENABLED_PROFILING=1 -DWITH_DEBUG=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_EXTRA_CHARSETS=all -DWITH_LIBWRAP=1 -DWITH_READLINE=1 -DWITH_SSL=yes

编译完后运行下面两个命令安装

make

make install

后期设置命令

cd /usr/local/webserver/mysql

chown -R mysql:mysql .

初始化数据库

scripts/mysql_install_db --user=mysql --basedir=/usr/local/webserver/mysql --datadir=/mysqlData/3306/data

建立 my.cnf 文件

vim /mysqlData/3306/my.cnf

内容如下:

view plaincopy to clipboardprint?
[client]
character-set-server=utf8
port = 3306
socket = /tmp/mysql.sock
# The MySQL server
[mysqld]
character-set-server=utf8
user=mysql
basedir=/usr/local/webserver/mysql
datadir=/mysqlData/3306/data
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log-error=/mysqlData/3306/mysql_error.log
pid_file=/mysqlData/3306/mysql.pid
log_bin=/mysqlData/3306/binlog/binlog
binlog_cache_size=4M
max_binlog_cache_size=8M
max_binlog_size=128M
relay-log-index=/mysqlData/3306/relaylog/relaylog
relay-log-info-file=/mysqlData/3306/relaylog/relaylog
relay-log=/mysqlData/3306/relaylog/relaylog
expire_logs_days=30
binlog_format=mixed
server-id = 1
#innodb_data_home_dir = /usr/local/webserver/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/webserver/mysql/data
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout


再次设置一下用户

chown -R mysql:mysql /usr/local/webserver/mysql

启动数据库

/usr/local/webserver/mysql/bin/mysqld_safe --user=mysql --basedir=/usr/local/webserver/mysql --datadir=/mysqlData/3306/data &

修改用户名密码,其中的 NEW_PASSWORD 换成你自己想要设置的密码

/usr/local/webserver/mysql/bin/mysqladmin -u root password 'NEW_PASSWORD'

关闭数据库使用如下命令

/usr/local/webserver/mysql/bin/mysqladmin -u root -p shutdown

安装 PHP 5.3.5

建立 www 用户

/usr/sbin/groupadd www

/usr/sbin/useradd -g www www

cd /opt/LNMP_src

tar zxvf php-5.3.5.tar.gz

cd php-5.3.5

编译命令,有些长,记得一起复制到终端中

./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-pdo-mysql=/usr/local/webserver/mysql --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-curl --with-pear --with-gd --with-jpeg-dir --with-png-dir --with-zlib --with-xpm-dir --with-freetype-dir --with-mcrypt --with-mhash --with-openssl --with-xmlrpc --with-xsl --with-bz2 --with-gettext --disable-debug --enable-fpm --enable-exif --enable-wddx --enable-zip --enable-bcmath --enable-calendar --enable-ftp --enable-mbstring --enable-soap --enable-sockets --enable-sqlite-utf8 --enable-shmop --enable-dba --enable-sysvsem --enable-sysvshm --enable-sysvmsg

编译完成后,进行安装

make ZEND_EXTRA_LIBS='-liconv'

make install

建立 php.ini 文件

gedit /usr/local/webserver/php/etc/php.ini

内容如下:

view plaincopy to clipboardprint?
[PHP]
engine = On
short_open_tag = Off
asp_tags = Off
precision = 14
y2k_compliance = On
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = 100
allow_call_time_pass_reference = Off
safe_mode = Off
safe_mode_gid = Off
safe_mode_include_dir =
safe_mode_exec_dir =
safe_mode_allowed_env_vars = PHP_
safe_mode_protected_env_vars = LD_LIBRARY_PATH
disable_functions =
disable_classes =
expose_php = On
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL | E_STRICT
display_errors = On
display_startup_errors = On
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = On
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_globals = Off
register_long_arrays = Off
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 8M
magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 2M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[Date]
date.timezone = PRC
[filter]
[iconv]
[intl]
[sqlite]
[sqlite3]
[Pcre]
[Pdo]
[Pdo_mysql]
pdo_mysql.cache_size = 2000
pdo_mysql.default_socket=
[Phar]
[Syslog]
define_syslog_variables = Off
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = On
[SQL]
sql.safe_mode = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[Interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQL]
mysql.allow_local_infile = On
mysql.allow_persistent = On
mysql.cache_size = 2000
mysql.max_persistent = -1
mysql.max_links = -1
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout = 60
mysql.trace_mode = Off
[MySQLi]
mysqli.max_persistent = -1
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = On
[OCI8]
[PostgresSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[Sybase-CT]
sybct.allow_persistent = On
sybct.max_persistent = -1
sybct.max_links = -1
sybct.min_server_severity = 10
sybct.min_client_severity = 10
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.bug_compat_42 = On
session.bug_compat_warn = On
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
[MSSQL]
mssql.allow_persistent = On
mssql.max_persistent = -1
mssql.max_links = -1
mssql.min_error_severity = 10
mssql.min_message_severity = 10
mssql.compatability_mode = Off
mssql.secure_connection = Off
[Assertion]
[COM]
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[mcrypt]
[dba]


建立 php-fpm.conf 文件

gedit /usr/local/webserver/php/etc/php-fpm.conf

内容如下:

view plaincopy to clipboardprint?
[global]
[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


启动 php-fpm

/usr/local/webserver/php/sbin/php-fpm

关闭的话,直接查找出进程号,用以下命令关闭

kill -QUIT 查找到的进行程

安装 nginx

建立存放日志文件的目录

mkdir -p /logsData/nginxLog

chmod +w /logsData/nginxLog

chown -R www:www /logsData/nginxLog

cd /opt/LNMP_src

tar zxvf nginx-0.8.54.tar.gz

cd nginx-0.8.54/

./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module

make && make install

cd ../

编辑 nginx.conf

gedit /usr/local/webserver/nginx/conf/nginx.conf

然后将全部内容替换为以下内容:

view plaincopy to clipboardprint?
user www www;
worker_processes 1;
error_log /logsData/nginxLog/nginx_error.log crit;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}


启动nginx

/usr/local/webserver/nginx/sbin/nginx

关闭

/usr/local/webserver/nginx/sbin/nginx -s stop

重启

/usr/local/webserver/nginx/sbin/nginx -s reload

至此整个安装过程结束

为了方便,把三样服务加入到开机自启动中,这样以后一开机就会自动启动了,也可以容易避开中途启动时端口被占用的问题

编辑 /etc/rc.local 文件,在 exit 0 语句前加入以下三行语句

view plaincopy to clipboardprint?
/usr/local/webserver/php/sbin/php-fpm
/usr/local/webserver/nginx/sbin/nginx
/usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/mysqlData/3306/my.cnf &


_________________
修己,安人


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 1 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 3 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译