文中所涉及到的所有安装包,都已经打包上传CSDN,点击下载
nginx-1.0.15.tar.gz
php-5.2.17.tar.gz
php-5.2.17-fpm-0.5.14.diff.gz
mysql-5.1.35.tar.gz
libiconv-1.13.tar.gz
libmcrypt-2.5.8.tar.gz
mcrypt-2.6.8.tar.gz
memcache-2.2.5.tgz
mhash-0.9.9.9.tar.gz
eaccelerator-0.9.5.3.tar.bz2
PDO_MYSQL-1.0.2.tgz
ImageMagick-6.7.5-10.tar.gz
imagick-2.2.2.tgz
freetype-2.5.3.tar.bz2
gd-2.0.33.tar.gz
jpegsrc.v8b.tar.gz
libpng-1.6.10.tar.xz
ncurses-5.9.tar.gz
node-v0.8.7.tar.gz
openssl-1.0.0l.tar.gz
tar zxvf libiconv-1.13.tar.gz cd libiconv-1.13/ ./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 zxvf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9/ ./configure make make install cd ../
tar zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8/ /sbin/ldconfig ./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
这个linux系统一般都有,可以不用安装.可以用以下命令查看
rpm -qa | grep zlib
tar zxvf libpng-1.6.10.tar.tar cd libpng-1.6.10 ./configure make make install
tar zxvf freetype-2.5.3.tar.gz cd freetype-2.5.3 ./configure make make install
tar zxvf jpegsrc.v8b.tar.gz cd jpeg-8b/ ./configure --enable-shared make make test make install
tar zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --prefix=/usr/local/gd2 --with-png --with-freetype --with-jpeg #注意: 安装路径的指定很重要,后面要使用
make
make install
fedora20已经默认安装了openssl,但是它的路径是分散的,而在后面的php的安装或者mysql的安装中,经常因为openssl找不到而失败,因此需要重新安装以下openssl
tar zxvf openssl-1.0.0l.tar.gz cd openssl-1.0.0l/ ./configure --prefix=/usr/local/openssl #这个路径在后面将会经常用到 make && make install
在安装时如果出现如下错误:POD document had syntax errors at /usr/bin/pod2man line 69. make .那么,解决反感如下:
rm /usr/bin/pod2man
fedora20里面已经默认集成了MariaDB,但是在实际使用起来与原来的Mysql有一点区别,不太习惯,于是想要换成Mysql
但是,并不能直接安装Mysql,需要先卸载MariaDB.
首先利用以下命令找到本机安装的所有MariaDB
rpm -qa | grep -i mariadb
rpm -e [package name] --nodeps
tar zxvf ncurses-5.9.tar.gz cd ncurses-5.9 ./configure make make install
groupadd mysql useradd mysql -g mysql
tar zxvf mysql-5.1.35.tar.gz cd mysql-5.1.35 ./configure --prefix=/usr/local/mysql --without-debug --with-extra-charsets=gbk --with-extra-charsets=all --enable-assembler --with-pthread --enable-thread-safe-client --with-mysqld-ldflags=-all-static /*不带共享库的形式编译mysqld*/ --with-client-ldflags=-all-static --with-big-tables --with-readline /*要采用rpm方式安装ncurses或tar包安装*/ --with-ssl /*要采用rpm方式安装openssl*//*注意,若编译中关于SSL报错,请将此句修改为: --with-ssl=/usr/local/openssl*/ --with-embedded-server --enable-local-infile --with-plugins=innobase make && make install
/usr/local/mysql/bin/mysql_install_db --user=mysql #以mysql身份初始化数据库 cp ./support-files/mysql.server /etc/init.d/mysql #复制Mysql启动服务至系统 cp ./support-files/my-medium.cnf /etc/my.cnf chmod 755 /etc/init.d/mysql cd /usr/local/mysql/ #切换到cd /usr/local/mysql/目录下 chown -R mysql . #改变当前目录下的所有者为mysql用户 chown -R mysql var #修改数据库目录的权限 chgrp -R mysql . #改变当前目录下的mysql用户的文件为mysql组 /usr/local/mysql/bin/mysqld_safe --user=mysql& /usr/local/mysql/bin/mysqladmin -u root password 'admin' #设置管理员密码 /usr/local/mysql/bin/mysql -u root -p #测试密码输入 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.1.35-log Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> \q /*退出mysql*/ chkconfig --add mysql #添加mysqld服务到系统 chkconfig mysql on #打开myslqd服务 service mysql start #启动Mysql /usr/local/mysql/bin/mysqladmin shutdown #关闭数据库 #查看mysql端口的打开情况 netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/P name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2936/ #查看是否启动: ps -ef | grep mysql
如果在安装中有do_abi_check的报错,那是因为mysql的bug,mysql 5.1.14以上版本跟gcc 4.5不太兼容导致的
解决办法:configure完成之后,编辑Makefile,查找do_abi_check: 将do_abi_check: 后到done 都删除,保存.(注意do_abi_check:需要保留). 随后开始make && make install
因为默认情况下Nginx和PHP他俩之间是一点感觉没有的。在之前搭建过Apache+PHP,Apache+PHP编译后生成的是 模块文件,而Nginx+PHP需要PHP生成可执行文件才可以,所以要利用fastcgi技术来实现Nginx与PHP的整合,这个只要我们安装时启用 FastCGI即可。此次我们安装PHP不仅使用了FastCGI,而且还使用了PHP-FPM这么一个东东,PHP-FPM说白了是一个管理 FastCGI的一个管理器,它作为PHP的插件存在,在安装PHP时要想使用PHP-FPM就需要把PHP-FPM以补丁的形式安装到PHP中,而且 PHP要与PHP-FPM版本一致,这是必须的,切记!
tar zxvf php-5.2.17.tar.gz gzip -cd php-5.2.17-fpm-0.5.11.diff.gz | patch -d php-5.2.17 -p1 curl -o php-5.2.17.patch https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt cd php-5.2.17 patch -p0 -b <../php-5.2.17.patch
./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-gd=/usr/local/gd2 #这个路径也必须手动指定,不然找不到GD库 --enable-gd-native-ttf --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-openssl=/usr/local/openssl #这里的路径很重要,必须指定,不然后面的make会失败 --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear注:Nginx+PHP整合,在安装时必须启用-–enable-fastcgi和--enable-fpm,这两个选项是做什么的上面已经描述。执行完后系统会提示-–enable-fastcgi是一个未知选项,我们不必理会。
错误解决:
若出现CONFIGURE: ERROR: XML2-CONFIG NOT FOUND. PLEASE CHECK YOUR LIBXML2 INSTALLATION.错误,那么,是因为libxml2-dev没有安装. 直接安装即可:
yum install libxml2-dev
若出现Cannot find ldap.h错误,是因为openldap或者openldap-dev没有安装,先安装即可
yum install openldap yum install openldap-devel
#注:make的时候一定要加上后面的参数,才能成功。 make ZEND_EXTRA_LIBS='-liconv' make test make install cp php.ini-dist /usr/local/php/etc/php.ini cd ../
如果在make test中出现error while loading shared libraries: libssl.so.的错误,那是因为找不到openssl的库文件.这个文件存在于/usr/local/openssl/lib/内.
解决方案: 在/etc/ld.so.conf.d/目录下新建任何以.conf为后缀的文件,在该文件中加入库文件所在的目录;运行ldconfig,以更新/etc/ld.so.cache文件;
tar zxvf memcache-2.2.5.tgz cd memcache-2.2.5/ /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make make install cd ..
tar jxvf eaccelerator-0.9.5.3.tar.bz2 cd eaccelerator-0.9.5.3/ /usr/local/php/bin/phpize ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config make make install cd ../
tar zxvf PDO_MYSQL-1.0.2.tgz cd PDO_MYSQL-1.0.2/ /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql make make install cd ../
ImageMagick是Linux下非常强大的图象处理函数与GD类似.
记住不可安装 ImageMagick-6.5.1-2版本,据说是因为 It compiles against Zlib 1.2.6,所以在make的时候会出错.详见这里http://www.imagemagick.org/discourse-server/viewtopic.php?t=20267
tar zxvf ImageMagick-6.7.5-10.tar.gz cd ImageMagick-6.7.5-10/ ./configure --prefix=/usr/local/ImageMagick #记住这个路径指定很重要 make make install cd ../
连接PHP和ImageMagick的通道
tar zxvf imagick-2.2.2.tgz cd imagick-2.2.2/ /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/ImageMagick make make install cd ../
vi /usr/local/php/etc/php.ini #查找 extension_dir = "./" #修改为 extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/" #并在此行后增加以下几行,然后保存: extension = "memcache.so" extension = "pdo_mysql.so" extension = "imagick.so" #再查找output_buffering = Off #修改为output_buffering = On
mkdir -p /usr/local/eaccelerator_cache vi /usr/local/php/etc/php.ini
[eaccelerator] zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so" eaccelerator.shm_size="64" eaccelerator.cache_dir="/usr/local/eaccelerator_cache" eaccelerator.enable="1" eaccelerator.optimizer="1" eaccelerator.check_mtime="1" eaccelerator.debug="0" eaccelerator.filter="" eaccelerator.shm_max="0" eaccelerator.shm_ttl="3600" eaccelerator.shm_prune_period="3600" eaccelerator.shm_only="0" eaccelerator.compress="1" eaccelerator.compress_level="9"
/usr/sbin/groupadd www -g 48 /usr/sbin/useradd -u 48 -g www www
rm -f /usr/local/php/etc/php-fpm.conf vi /usr/local/php/etc/php-fpm.conf
<?xml version="1.0" ?> <configuration> <section name="global_options"> <value name="pid_file">/usr/local/php/logs/php-fpm.pid</value> <value name="error_log">/usr/local/php/logs/php-fpm.log</value> <value name="log_level">notice</value> <value name="emergency_restart_threshold">10</value> <value name="emergency_restart_interval">1m</value> <value name="process_control_timeout">5s</value> <value name="daemonize">yes</value> </section> <workers> <section name="pool"> <value name="name">default</value> <value name="listen_address">127.0.0.1:9000</value> <value name="listen_options"> <value name="backlog">-1</value> <value name="owner"></value> <value name="group"></value> <value name="mode">0666</value> </value> <value name="php_defines"> <value name="sendmail_path">/usr/sbin/sendmail -t -i</value> <value name="display_errors">1</value> </value> <value name="user">www</value> <value name="group">www</value> <value name="pm"> <value name="style">static</value> <value name="max_children">128</value> <value name="apache_like"> <value name="StartServers">20</value> <value name="MinSpareServers">5</value> <value name="MaxSpareServers">35</value> </value> </value> <value name="request_terminate_timeout">0s</value> <value name="request_slowlog_timeout">0s</value> <value name="slowlog">logs/slow.log</value> <value name="rlimit_files">51200</value> <value name="rlimit_core">0</value> <value name="chroot"></value> <value name="chdir"></value> <value name="catch_workers_output">yes</value> <value name="max_requests">500</value> <value name="allowed_clients">127.0.0.1</value> <value name="environment"> <value name="HOSTNAME">$HOSTNAME</value> <value name="PATH">/usr/local/bin:/usr/bin:/bin</value> <value name="TMP">/tmp</value> <value name="TMPDIR">/tmp</value> <value name="TEMP">/tmp</value> <value name="OSTYPE">$OSTYPE</value> <value name="MACHTYPE">$MACHTYPE</value> <value name="MALLOC_CHECK_">2</value> </value> </section> </workers> </configuration>
/usr/local/php/sbin/php-fpm start
Nginx只是web服务器,配合php技术实现的fastcgi来提高性能
pcre是perl所用到的正则表达式,目的是让所装的软件支持正则表达式。默认情况下,Nginx只处理静态的网页请求,也就是html.如果是来自动态的网页请求,比如*.php,那么Nginx就要根据正则表达式查询路径,然后把*.PHP交给PHP去处理。
yum install pcre
说明:创建www用户组及www用户,如果之前php-fpm没有创建,这里要创建。
tar zxvf nginx-1.0.15.tar.gz cd nginx-1.0.15/ ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module make make install
在/usr/local/nginx/conf/目录中创建nginx.conf文件
rm -f /usr/local/nginx/conf/nginx.conf vi /usr/local/nginx/conf/nginx.conf
user www www; worker_processes 1; error_log logs/nginx_error.log crit; #error_log logs/error.log notice; #error_log logs/error.log info; pid /usr/local/nginx/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; #charset gb2312; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; sendfile on; tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm index.php; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} #通过FastCGI方式支持PHP,php页面由fastcgi代理处理,这也是反向代理的一个应用,这里可以是jsp/asp等脚本。 # # #Nginx是通过本机的9000端口将PHP请求转发给PHP的,PHP自己是从本机的9000端口侦听数据,Nginx与PHP通过本机的9000端口完成了数据请求。 # location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } #对于某一类型的文件,设置过期时间,静态的页面通常设置长一点。 #静态文件,nginx自己处理 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { expires 30d; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
说明:可以直接粘贴以下内容。
vi /usr/local/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;
启动nginx
/usr/local/nginx/sbin/nginx
注意,启动nginx后,还必须同时启动php-fpm,否则,Nginx不支持php
命令如下:
/usr/local/php/sbin/php-fpm start
修改/usr/local/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确
/usr/local/nginx/sbin/nginx -t
ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
kill -HUP 6302
kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
vi /etc/rc.local
ulimit -SHn 51200 /usr/local/php/sbin/php-fpm start /usr/local/nginx/sbin/nginx
vi /usr/local/nginx/html/phpinfo.php <? phpinfo(); ?>
在浏览器输入http://localhost/phpinfo.php 屏幕显示php相关信息