勿忘我博客的搭建过程(Ubuntu下安装Nginx+PHP+MySQL)

简述下此博客的搭建过程,现在的访问到的博客是第二次搭建了,第一次搭建完的时候出现了点问题,然后处理各种问题服务器被高的乱七八糟实在是不愿意再去解决自己搞出的问题了,直接重新刷新了系统,从头开始安装,由于经过了第一次的安装,第二个过程中就少了很多纠结很多问题
服务器:服务器采用的linode的VPS(日本东京机房)
不再多说直接简述服务器的搭建过程
软件准备:

wget http://nginx.org/download/nginx-1.1.10.tar.gz
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
wget http://cdnetworks-kr-1.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
wget http://cdnetworks-kr-1.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
wget http://cdnetworks-kr-1.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
wget http://cdnetworks-kr-2.dl.sourceforge.net/project/pcre/pcre/8.20/pcre-8.20.tar.gz
wget http://jp.php.net/distributions/php-5.3.8.tar.gz
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.19.tar.gz/from/http://ftp.jaist.ac.jp/pub/mysql/

操作系统采用的 Ubuntu 11.10 64bit(系统较为纯净要安装一些必要的工具软件)

apt-get install gcc g++ ssh automake cmake build-essential autoconf make re2c wget cron bzip2 rcconf flex vim bison m4 mawk cpp binutils libncurses5 unzip tar libncurses5 libncurses5-dev libtool libpcre3 libpcrecpp0 libssl-dev zlibc openssl libxml2-dev libltdl3-dev libpcre3 libpcrecpp0 libssl-dev zlibc openssl libxml2-dev libltdl3-dev libmcrypt-dev

编译安装PHP所需的支持库

tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14/
./configure --prefix=/usr/local
make
make install
cd ../

tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./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 mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../

tar zxvf pcre-8.10.tar.gz
cd pcre-8.10
./configure
make
make install

安装MySQL,版本5.5.19

tar zxvf mysql-5.5.19.tar.gz
cd mysql-5.5.19
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8-unicode_ci -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_INNOBASE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DSYSCONFDIR=/etc -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_TCP_PORT=3306
make
make install
cd ../mysql
cp support-files/my-small.cnf /etc/my.cnf
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
/usr/local/mysql/bin/mysqld_safe --user=mysql&
/usr/local/mysql/bin/mysqladmin -u root password 'XXXXXX'

安装curl,没有想到系统纯净到连curl都没有

apt-get install libcurl4-gnutls-dev

安装PHP,版本5.3.8

tar zxvf php-5.3.8.tar.gz
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --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-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap

补充下如果需要使用LDAP、FreeType等,需要安装以下几个包

apt-get install libfreetype6-dev libjpeg8-dev libpng12-dev slapd ldap-utils db5.1-util

PHP想要使用LDAP下面这两个是需要安装的

apt-get install libldap2-dev libsasl2-dev

对应的php编译配置为

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/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-fastcgi --enable-fpm --enable-force-cgi-redirect --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
make ZEND_EXTRA_LIBS='-liconv'
make test
make install
cp php.ini-production /usr/local/php/etc/php.ini

执行命令查看PHP相关配置,获取PHP扩展存放目录extension-dir值

/usr/local/php/bin/php-config

以上命令输出

Usage: /usr/local/php/bin/php-config [OPTION]
Options:
  --prefix            [/usr/local/php]
  --includes          [-I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib]
  --ldflags           [ -L/usr/lib/x86_64-linux-gnu -L/usr/local/lib -L/usr/local/mysql/lib]
  --libs              [-lcrypt   -lz -lresolv -lcrypt -lrt -lmysqlclient -lmcrypt -lltdl -lcurl -lz -lrt -lm -ldl -lnsl  -lrt -lxml2 -lcurl -lxml2 -lmysqlclient -lz -lm -lrt -ldl -lxml2 -lxml2 -lcrypt -lxml2 -lxml2 -lxml2 -lxml2 -lcrypt ]
  --extension-dir     [/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626]
  --include-dir       [/usr/local/php/include/php]
  --man-dir           [/usr/local/php/man]
  --php-binary        [/usr/local/php/bin/php]
  --php-sapis         [cli fpm]
  --configure-options [--prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --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-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap]
  --version           [5.3.8]
  --vernum            [50308]
vi /usr/local/php/etc/php.ini

修改文件以下地方

extension_dir = "./"

修改为

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"

创建fastcgi配置文件

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

修改fastcgi配置文件

vi /usr/local/php/etc/php-fpm.conf

去掉注释以下几行的注释

pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = notice
pm.start_servers
pm.min_spare_servers
pm.max_spare_servers

修改文件以下两行,不修改启动fastcgi会报错 “fastcgi [pool www] cannot get gid for group ‘nobody’”

user = nobody
group = nobody

修改为

user = www
group = www

启动fastcgi

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

创建日志文件目录

mkdir -p /data1/logs/blog.wuwangwo.net
chmod +w /data1/logs/blog.wuwangwo.net
chown -R www:www /data1/logs/blog.wuwangwo.net

创建程序文件目录

mkdir -p /data/htdocs/blog.wuwangwo.net
chmod +w /data/htdocs/blog.wuwangwo.net
chown -R www:www /data/htdocs/blog.wuwangwo.net

安装Nginx,版本1.1.10

tar zxvf nginx-1.1.10.tar.gz
cd nginx-1.1.10/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module
make
make install

启动Nginx

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

ps:感谢在博客搭建过程中给予我巨大帮助的NoSQLFan博主iammutex苹果派博主小木马

发表评论