LNMP环境重新搭建就记录下过程。
一、安装php的依赖
1、libiconv 字符编码转换
下载地址:http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz
tar -zxvf libiconv-1.14.tar.gz cd libiconv-1.14/ ./configure --prefix=/usr/local/ make make install
如果没有C编译环境
onfigure: error: in `/usr/local/src/libiconv-1.14':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
解决办法: apt-get install build-essential
2、libmcrypt 加密算法的扩展
下载地址:ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt-2.5.7.tar.gz cd libmcrypt-2.5.7/ ./configure make&&make install
3、mhash 不可逆向的php加密方式扩展库
下载地址:http://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
tar -zxvf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9/ ./configure make&&make install 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
4、libpng图片相关
下载地址:http://downloads.sourceforge.net/project/libpng/libpng16/1.6.17/libpng-1.6.17.tar.gz
如果configure出错
错误:configure: error: zlib not installed 则应先安装zlib
下载地址:http://downloads.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz ./configure make make install ./configure --prefix=/usr/local/libpng --enable-shared --enable-static make make install
5、jpegsrc图片相关
下载地址:http://www.ijg.org/files/jpegsrc.v9a.tar.gz
tar -zxvf jpegsrc.v9a.tar.gz cd jpeg-9a/ ./configure --prefix=/usr/local/jpeg --enable-shared --enable-static make make install
6、freetype 字体相关
下载地址:http://download.savannah.gnu.org/releases/freetype/freetype-2.4.9.tar.gz
tar -xzvf freetype-2.4.9.tar.gz cd freetype-2.4.9 ./configure --prefix=/usr/local/freetype --enable-shared --enable-static make make install
7、libxml2
下载地址:ftp://xmlsoft.org/libxml2/libxml2-2.7.8.tar.gz
tar -zxvf libxml2-2.7.8.tar.gz cd libxml2-2.7.8/ ./configure make make install
8、fontconfig
下载地址:http://www.freedesktop.org/software/fontconfig/release/fontconfig-2.9.0.tar.gz
如果编译时出现如下错误:configure: error: Package requirements (freetype2) were not met:
则应安装libfreetype6-dev
apt-get install libfreetype6-dev ./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config --enable-static --enable-shared --enable-libxml2 make make install
9、GD库
tar -zxvf gd-2.0.35.tar.gz cd gd-2.0.35 ./configure --prefix=/usr/local/gd --with-png=/usr/local/libpng/ --with-freetype=/usr/local/freetype/ --with-fontconfig=/usr/local/fontconfig/ --with-jpeg=/usr/local/jpeg/ 修改gd_png.c文件,否则报错 sed -i -e '16s/png.h/\/usr\/local\/libpng\/include\/png.h/g' gd_png.c make make install
10、安装mysql的支持
安装mysql的依赖ncurses
tar -zxvf ncurses-5.8.tar.gz cd ncurses-5.8 ./configure &&make && make install
mysql下载地址:http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.25.tar.gz
tar -zxvf mysql-5.6.25.tar.gz cd mysql-5.6.25.tar.gz cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci make make install
因php只是读了mysql得一些库文件,所以不用实际安装初始化mysql,当做mysql数据库使用见mysql的安装
二、php的安装
php下载地址:http://museum.php.net/php5/php-5.3.21.tar.gz
tar -zxvf php-5.3.21.tar.gz cd php-5.3.21 ./configure --prefix=/usr/local/php5.3.21 --with-config-file-path=/usr/local/php5.3.21/etc --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir=/usr/local/freetype/ --with-jpeg-dir=/usr/local/jpeg/ --with-png-dir=/usr/local/libpng/ --with-zlib --with-libxml-dir=/usr --enable-calendar --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-ftp --with-mhash --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --enable-magic-quotes --with-gettext --with-mime-magic make make test make install
三、添加php的扩展
【PDO_mysql】
cd PDO_MYSQL-1.0.2/ /usr/local/php5.3.21/bin/phpize ./configure --with-php-config=/usr/local/php5.3.21/bin/php-config --with-pdo-mysql=/usr/local/mysql make make install
【mongo】
cd mongo-1.5.8/ /usr/local/php5.3.21/bin/phpize ./configure --with-php-config=/usr/local/php5.3.21/bin/php-config make make install
【memcache】
cd memcache-2.2.5/ /usr/local/php5.3.21/bin/phpize ./configure --with-php-config=/usr/local/php5.3.21/bin/php-config make make install
【fastdfs-client】version:V3.05
cd FastDFS/ ./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib ./make.sh install cd client make make install cd ../php_client /usr/local/php5.3.21/bin/phpize ./configure --with-php-config=/usr/local/php5.3.21/bin/php-config make make install
修改配置文件:
vim /etc/fdfs/client.conf
更改:
base_path=/data/fastdfs tracker_server=192.168.10.210:22122
如果make.sh的时候报如下错误:
collect2: ld returned 1 exit status make: *** [fdfs_monitor] Error 1
解决:
到系统中查找libpthread.so文件位置,直接find就可以找到了; find / -name 'libpthread.a' /usr/lib/x86_64-linux-gnu/libpthread.a find / -name 'libpthread.so' /usr/lib/x86_64-linux-gnu/libpthread.so 接着直接在make.sh中找到这句话然后替换掉就可以了,改成如下样子: if [ -f /usr/lib/x86_64-linux-gnu/ibpthread.so ] || [ -f /usr/local/lib/libpthread.so ] || [ -f /lib64/libpthread.so ] || [ -f /usr/lib64/libpthread.so ] || [ -f /usr/lib/x86_64-linux-gnu/libpthread.a ] || [ -f /usr/local/lib/libpthread.a ] || [ -f /lib64/libpthread.a ] || [ -f /usr/lib64/libpthread.a ]; then LIBS="$LIBS -lpthread"
php.ini (/usr/local/php5.3.21/etc/php.ini)
文件内容如下:
[PHP] engine = On short_open_tag = Off asp_tags = Off precision = 14 output_buffering = 4096 zlib.output_compression = Off implicit_flush = Off unserialize_callback_func = serialize_precision = 17 disable_functions = disable_classes = zend.enable_gc = On expose_php = On max_execution_time = 30 max_input_time = 60 memory_limit = 128M error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT display_errors = On display_startup_errors = Off log_errors = On log_errors_max_len = 1024 ignore_repeated_errors = Off ignore_repeated_source = Off report_memleaks = On track_errors = Off html_errors = On variables_order = "GPCS" request_order = "GP" register_argc_argv = Off auto_globals_jit = On post_max_size = 50M auto_prepend_file = auto_append_file = default_mimetype = "text/html" default_charset = "UTF-8" doc_root = user_dir = extension_dir = "/usr/local/php5.3.21/lib/php/extensions/no-debug-non-zts-20090626" extension = "memcache.so" extension = "pdo_mysql.so" extension = "mongo.so" enable_dl = Off cgi.fix_pathinfo=0 file_uploads = On upload_max_filesize = 50M max_file_uploads = 20 allow_url_fopen = On allow_url_include = Off default_socket_timeout = 60 [CLI Server] cli_server.color = On [Date] date.timezone =Asia/Shanghai [filter] [iconv] [intl] [sqlite] [sqlite3] [Pcre] [Pdo] [Pdo_mysql] pdo_mysql.cache_size = 2000 pdo_mysql.default_socket= [Phar] [mail function] SMTP = localhost smtp_port = 25 mail.add_x_header = On [SQL] sql.safe_mode = On [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.allow_persistent = On 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 = Off [OCI8] [PostgreSQL] 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_strict_mode = 0 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.referer_check = 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.compatibility_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] [opcache] opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable_cli=1 [curl] [openssl] [FASTDFS] extension = fastdfs_client.so fastdfs_client.tracker_group_count = 1 fastdfs_client.tracker_group0 = /etc/fdfs/client.conf fastdfs_client.base_path = /data/fastdfs
php-fpm.conf (和php.in在同目录下)
[global] [www] user = www-data group = www-data listen = 127.0.0.1:9001 pm = dynamic #使用方式:static 静态 dynamic 动态 pm.max_children = 5 # 静态方式下开启的php-fpm进程数量 pm.start_servers = 2 #动态方式下起始php-fpm进程数量 pm.min_spare_servers = 1#保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程 pm.max_spare_servers = 3 #保证空闲进程数最大值,如果空闲进程大于此值,此进行清理
php-fpm启动:
/usr/local/php5.3.21/sbin/php-fpm
检查是否启动成功:
1、ps -ef|grep php-fpm 2、netstat -ntpl|grep 9001
三、nginx的安装
1、安装nginx的正则表达式依赖包
tar -zxvf pcre-8.30.tar.gz cd pcre-8.30 ./configure --prefix=/usr/local/ make&&make install
2、安装nginx
nginx的下载地址:http://nginx.org/download/nginx-1.8.0.tar.gz
groupadd www-data useradd www-data -g www-data tar -zxvf nginx-1.8.0.tar.gz cd nginx-1.8.0 ./configure --user=www-data --group=www-data --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module make make install
nginx.conf(/usr/local/nginx/conf/nginx.conf)
user www-data www-data; worker_processes 4; worker_cpu_affinity 000000000010 000000000100 000000001000 000000010000; error_log logs/error.log debug; worker_rlimit_nofile 512000; pid logs/nginx.pid; events { use epoll; worker_connections 512000; multi_accept on; accept_mutex_delay 50ms; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user $request_time [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent"'; server_names_hash_bucket_size 128; client_header_buffer_size 4k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; expires 365d; tcp_nodelay on; server_tokens off; #去版本信息 # set_real_ip_from 192.168.1.0/24; # real_ip_header X-Forwarded-For; 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 256k; client_body_buffer_size 256k; proxy_ignore_client_abort on; proxy_buffering on; proxy_buffer_size 4096k; proxy_buffers 256 4096k; request_pool_size 16k; output_buffers 4 512k; postpone_output 1460; client_header_timeout 30; client_body_timeout 30; send_timeout 30; gzip off; 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 off; include /usr/local/nginx/conf/sites-enabled/*; }
phpinfo.conf(/usr/local/nginx/conf/sites-enabled/phpinfo.conf)
server { listen 80; server_name phpinfo.test.com; index index.html index.htm index.php; root /data/www/phpinfo/; #limit_conn crawler 20; location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; include fcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } access_log /usr/local/nginx/logs/fuck.access.log main; }
四、测试
在/data/www/phpinfo/目录下新建phpinfo.php文件
内容如下
<?php phpinfo(); ?>
写hosts
ip地址 phpinfo.test.com
通过浏览器访问
phpinfo.test.com/phpinfo.php