[root@Alicia named]# vi /etc/httpd/conf/httpd.conf 33 ### Section 1: Global Environment 44 ServerTokens OS 57 ServerRoot "/etc/httpd" 63 PidFile run/httpd.pid 68 Timeout 120 74 KeepAlive Off 81 MaxKeepAliveRequests 100 87 KeepAliveTimeout 15 100 <IfModule prefork.c> 101 StartServers 8 启动8个进程 102 MinSpareServers 5 至少保持5个空闲的进程 103 MaxSpareServers 20 最多保持20个空闲的进程 104 ServerLimit 256 服务器限制 105 MaxClients 256 进程最多响应256个 106 MaxRequestsPerChild 4000 一个客户端要开好几个页面,是子进程 107 </IfModule> 134 Listen 80 210 Include conf.d/*.conf 231 User apache 232 Group apache 234 ### Section 2: 'Main' server configuration 251 ServerAdmin root@localhost 265 #ServerName www.example.com:80 274 UseCanonicalName Off 281 DocumentRoot "/var/www/html" 291 <Directory /> 292 Options FollowSymLinks 293 AllowOverride None 294 </Directory> 306 <Directory "/var/www/html"> 320 Options Indexes FollowSymLinks 327 AllowOverride None 332 Order allow,deny 333 Allow from all 334 335 </Directory> 349 <IfModule mod_userdir.c> 355 UserDir disable 362 #UserDir public_html 363 364 </IfModule> 472 ErrorLog logs/error_log 524 ServerSignature On 570 <Directory "/var/www/cgi-bin"> 571 AllowOverride None 572 Options None 573 Order allow,deny 574 Allow from all 575 </Directory> 985 #<VirtualHost *:80> 986 # ServerAdmin [email protected] 987 # DocumentRoot /www/docs/dummy-host.example.com 988 # ServerName dummy-host.example.com 989 # ErrorLog logs/dummy-host.example.com-error_log 990 # CustomLog logs/dummy-host.example.com-access_log common 991 #</VirtualHost>
增加一个主页启动apache:
[root@Alicia named]# vi /var/www/html/index.html 1 <html> 2 Welcome to alicia web page!! 3 </html> [root@Alicia named]# service httpd restart Stopping httpd: [FAILED] Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName [ OK ]
[root@Alicia named]# vi /etc/httpd/conf/httpd.conf 265 ServerName www.alicia.net:80 [root@Alicia named]# !ser service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
基于个人用户
[root@Alicia named]# vi /etc/httpd/conf/httpd.conf 349 <IfModule mod_userdir.c> 350 # 351 # UserDir is disabled by default since it can confirm the presence 352 # of a username on the system (depending on home directory 353 # permissions). 354 # 355 #UserDir disable 注释掉 356 357 # 358 # To enable requests to /~user/ to serve the user's public_html 359 # directory, remove the "UserDir disable" line above, and uncomment 360 # the following line instead: 361 # 362 UserDir public_html 启用公有目录 363 364 </IfModule>
test: mkdir /home/dh/public_html vi /home/dh/public_html/index.html hi, i am dh chmod 755 -R /home/dh/public_html http://192.168.0.111/~dh hi, i am dh 避免用户出现在url中 [root@Alicia html]# cd /var/www/html [root@Alicia html]# ln -s /home/dh/public_html/ linux http://192.168.0.111/linux hi, i am dh
基于域名的虚拟主机
首先配置DNS,使得本机能解析两个域名为同一个本机地址,加个区数据文件,或者一个A记录就好[root@Alicia dh]# nslookup www.hding Server: 192.168.0.111 Address: 192.168.0.111#53 Name: www.hding Address: 192.168.0.111 [root@Alicia dh]# nslookup www.alicia.net Server: 192.168.0.111 Address: 192.168.0.111#53 Name: www.alicia.net Address: 192.168.0.111
这样访问http://www.hding, http://www.alicia.net实际上就是http://192.168.0.111:80
据不同域名访问不同内容[root@Alicia html]# vi /etc/httpd/conf/httpd.conf 973 NameVirtualHost *:80 993 <VirtualHost *:80> 994 ServerAdmin [email protected] 995 DocumentRoot /var/www/html/alicia 996 ServerName www.alcia.net 997 ErrorLog logs/dummy-host.alicia.com-error_log 998 CustomLog logs/dummy-host.alicia.com-access_log common 999 </VirtualHost> 1000 1001 <VirtualHost *:80> 1002 ServerAdmin [email protected] 1003 DocumentRoot /var/www/html/hding 1004 ServerName www.hding 1005 ErrorLog logs/dummy-host.hding.com-error_log 1006 CustomLog logs/dummy-host.hding.com-access_log common 1007 </VirtualHost> 建立相应目录和文件 [root@Alicia dh]# cd /var/www/html/ [root@Alicia html]# mkdir hding alicia [root@Alicia html]# vi hding/index.html 1 hi, i am alicia here ~ "hding/index.html" [New] 1L, 21C written [root@Alicia html]# vi alicia/index.html 1 hi, i am alicia here
客户端测试
http://www.hding hi, i am hding here http://www.alicia.net hi, i am alicia here
相同IP不同端口,相同端口不同IP的主机实现
[root@Alicia html]# ifconfig eth0:0 192.168.0.119 [root@Alicia html]# vi /etc/httpd/conf/httpd.conf 134 Listen 80 135 Listen 81 136 Listen 82 1011 <VirtualHost 192.168.0.111:81> 1012 DocumentRoot /var/www/html/html1 1013 Servername www.alicia.net 1014 </VirtualHost> 1015 1016 <VirtualHost 192.168.0.119:81> 1017 DocumentRoot /var/www/html/html2 1018 Servername www.alicia.net 1019 </VirtualHost> 1020 1021 <VirtualHost 192.168.0.119:82> 1022 DocumentRoot /var/www/html/html3 1023 Servername www.alicia.net 1024 </VirtualHost>
源代码编译安装:
cd ../apr-1.4.6 ./configure --prefix=/usr/local/apr/ make&&make install 安装apr-util cd ../apr-util-1.5.1 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ make&&make install 安装pcre unzip -o pcre-8.32.zip cd ../pcre-8.32 ./configure --prefix=/usr/local/pcre make&&make install [root@Alicia httpd-2.4.3]# ./configure --prefix=/usr/local/apache2 --with-apr=/ usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/ --with-include-apr --enable-so --enable-rewrite [root@Alicia httpd-2.4.3]#make [root@Alicia httpd-2.4.3]#make install [root@Alicia httpd-2.4.3]# ll /usr/local/apache2/ total 56 drwxr-xr-x 2 root root 4096 Jan 15 03:00 bin drwxr-xr-x 2 root root 4096 Jan 15 03:00 build drwxr-xr-x 2 root root 4096 Jan 15 03:00 cgi-bin drwxr-xr-x 4 root root 4096 Jan 15 03:00 conf drwxr-xr-x 3 root root 4096 Jan 15 03:00 error drwxr-xr-x 2 root root 4096 Jan 15 00:22 htdocs drwxr-xr-x 3 root root 4096 Jan 15 03:00 icons drwxr-xr-x 2 root root 4096 Jan 15 03:00 include drwxr-xr-x 2 root root 4096 Jan 15 03:00 logs drwxr-xr-x 4 root root 4096 Jan 15 03:00 man drwxr-xr-x 14 root root 12288 Aug 17 2012 manual drwxr-xr-x 2 root root 4096 Jan 15 03:00 modules [root@Alicia]# /usr/local/bin/apachectl start AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80 (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down AH00015: Unable to open logs [root@Alicia apache2]# vi /usr/local/apache2conf/httpd.conf 53 Listen 8080 144 LoadModule userdir_module modules/mod_userdir.so 455 # User home directories 456 Include conf/extra/httpd-userdir.conf [root@Alicia apache2]# vi /home/dh/public_html/index.html 1 hi, i am dh, I am using apache2 for test! [root@Alicia apache2]# /usr/local/apache2/bin/apachectl restart
客户端测试:
http://www.alicia.net:8080 It Works http://www.alicia.net:8080/~dh hi, i am dh, i am using apache2 for test 创建一个软链接,来避免用户出现在URL中 [root@Alicia apache2]# cd /var/www/html/ [root@Alicia html]# ln -s /home/dh/public_html/ linux lrwxrwxrwx 1 root root 21 Jan 15 03:42 linux -> /home/dh/public_html/
LAMP
mysql安装
groupadd mysql useradd -g mysql mysql cd mysql-5.0.18 ./configure --prefix=/usr/local/mysql --without-debug --enable-thread-safe-client --with-pthread --enable-assembler --enable-profilling --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=all --with-plugins=all --with-mysqld-user=mysql --without-embedded-server --with-server-suffix=-community --with-unix-socket-path=/tmp/mysql.sock make&&make install cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf vi /etc/my.cnf 18 [client] 19 #password = your_password 20 port = 3306 21 socket = /tmp/mysql.sock 22 23 default-character-set=utf8 27 [mysqld] 28 port = 3306 29 socket = /tmp/mysql.sock 30 skip-locking 31 key_buffer = 16M 32 max_allowed_packet = 1M 33 table_cache = 64 34 sort_buffer_size = 512K 35 net_buffer_length = 8K 36 read_buffer_size = 256K 37 read_rnd_buffer_size = 512K 38 myisam_sort_buffer_size = 8M 39 character-set-server=utf8 40 collation-server=utf8_general_ci 41 default-storage-engine=innodb 123 innodb_data_home_dir = /usr/local/mysql/var/ 124 innodb_data_file_path = ibdata1:10M:autoextend 125 innodb_log_group_home_dir = /usr/local/mysql/var/ 126 #innodb_log_arch_dir = /usr/local/mysql/var/ 127 # You can set .._buffer_pool_size up to 50 - 80 % 128 # of RAM but beware of setting memory usage too high 129 innodb_buffer_pool_size = 16M 130 innodb_additional_mem_pool_size = 2M 131 # Set .._log_file_size to 25 % of buffer pool size 132 innodb_log_file_size = 5M 133 innodb_log_buffer_size = 8M 134 innodb_flush_log_at_trx_commit = 1 135 innodb_lock_wait_timeout = 50 /usr/local/mysql/bin/mysql_install_db --user=mysql cd /usr/local/mysql/shard/mysql cp mysql.server /etc/init.d/mysqld service mysqld restart /usr/local/mysql/bin/mysqladmin -uroot password password [root@Alicia mysql]# bin/mysql -u root -ppassword Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 to server version: 5.0.18-community-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.06 sec) mysql>PHP
安装 libxml2 cd /lamp/libxml2-2-2.9.0 ./configure --prefix=/usr/local/libxml2/ make&&make instally 安装libmcrypt cd ../libmcrypt-2.5.8 ./configure --prefix=/usr/local/libmcrypt/ make&&make install 安装libltdl cd ../libmcrypt-2.5.8/libltdl/ ./configure --enable-ltdl-install make&&make install 安装zlib cd ../zlib-1.2.7 ./configure make&&make install 安装libpng cd ../libpng-1.5.14 ./configure --prefix=/usr/local/libpng/ make&&make install 安装jpeg cd ../jpeg-8b/ mkdir /usr/local/jpeg8 mkdir /usr/local/jpeg8/bin mkdir /usr/local/jpeg8/lib mkdir /usr/local/jpeg8/include mkdir /usr/local/jpeg8/man/man1 ./configure --prefix=/usr/local/jpeg8/ --enable-shared --enable-static make&&make install 安装freetype cd ../freetype-2.4.10 ./configure --prefix=/usr/local/freetype/ make&&make install 安装autoconf cd ../autoconf-2.69 ./configure make&&make install 安装gd mkdir /usr/local/gd2 cd ../gd2.0.35 ./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg8/ --with-freetype=/usr/local/freetype/ make&&make install cd ../php-5.4.11 ./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg8/ --with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets make make install
PHP与apache连接
[root@Alicia php-5.4.11]# vi /usr/local/apache2/conf/httpd.conf 376 AddType application/x-httpd-php .php .phtml .phs [root@Alicia php-5.4.11]# vi /usr/local/apache2/htdocs/test.php 1 <? 2 phpinfo(); 3 ?> [root@Alicia php-5.4.11]# /usr/local/apache2/bin/apachectl restart httpd not running, trying to starthttps server:
准备CA服务器:
[root@Alicia certs]# vi /etc/pki/tls/openssl.cnf 45 dir = /etc/pki/CA # Where everything is kept 87 [ policy_match ] 88 countryName = optional 89 stateOrProvinceName = optional 90 organizationName = optional 134 [ req_distinguished_name ] 135 countryName = Country Name (2 letter code) 136 countryName_default = CN 137 countryName_min = 2 138 countryName_max = 2 139 140 stateOrProvinceName = State or Province Name (full name) 141 stateOrProvinceName_default = Shanghai 142 143 localityName = Locality Name (eg, city) 144 localityName_default = Shanghai [root@Alicia certs]# cd /etc/pki/CA [root@Alicia CA]# mkdir crl [root@Alicia CA]# mkdir certs [root@Alicia CA]# mkdir newcerts [root@Alicia CA]# touch serial [root@Alicia CA]# echo "01" > serial [root@Alicia CA]# touch index.txt [root@Alicia CA]# openssl genrsa 1024 > private/cakey.pem Generating RSA private key, 1024 bit long modulus ...++++++ ...++++++ e is 65537 (0x10001) [root@Alicia CA]# chmod 600 private/cakey.pem [root@Alicia CA]# openssl req -new -key private/cakey.pem -x509 -ou t cacert.pem -days 3650 You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [CN]: State or Province Name (full name) [Shanghai]: Locality Name (eg, city) [Shanghai]: Organization Name (eg, company) [My Company Ltd]: Organizational Unit Name (eg, section) []:qa Common Name (eg, your name or your server's hostname) []: Email Address []:web https server所需要的证书
web server ca: [root@Alicia apache2]# mkdir certs [root@Alicia apache2]# cd certs/ [root@Alicia certs]# openssl genrsa 1024 > httpd.key 使用长度为1024的非对称加密算法rsa,重定向到存放私钥的文件httpd.key中 Generating RSA private key, 1024 bit long modulus .................++++++ .................................++++++ e is 65537 (0x10001) [root@Alicia certs]# openssl req -new -key httpd.key -out httpd.csr 利用存放私钥的文件httpd.key请求得到一个证书请求,请求产生的文件叫httpd.csr You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [GB]:cn State or Province Name (full name) [Berkshire]:sh Locality Name (eg, city) [Newbury]: Organization Name (eg, company) [My Company Ltd]: Organizational Unit Name (eg, section) []:qa Common Name (eg, your name or your server's hostname) []:alicia.net Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: [root@Alicia certs]# openssl ca -in httpd.csr -out httpd.cert 利用ca产生一个证书,请求文件是当前目录下的httpd.csr,申请一个证书httpd.cert [root@Alicia certs]# ll total 12 -rw-r--r-- 1 root root 3046 Jan 16 01:09 httd.cert -rw-r--r-- 1 root root 651 Jan 16 00:52 httpd.csr -rw-r--r-- 1 root root 887 Jan 16 00:51 httpd.key
编译apache,加入ssl配置
[root@Alicia httpd-2.4.3]# ./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl --enable-rewrite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/ [root@Alicia apache2]# vi /usr/local/apache2/conf/httpd.conf 88 LoadModule socache_shmcb_module modules/mod_socache_shmcb.so 127 LoadModule ssl_module modules/mod_ssl.so 480 # Secure (SSL/TLS) connections 481 Include conf/extra/httpd-ssl.conf [root@Alicia apache2]# vi conf/extra/httpd-ssl.conf 106 SSLCertificateFile "/usr/local/apache2/certs/httpd.crt" 116 SSLCertificateKeyFile "/usr/local/apache2/certs/httpd.key" [root@Alicia apache2]# /usr/local/apache2/bin/apachectl restart
至此 https://www.alicia.net成功获取证书,访问网页
出现的问题:
httpd源码编译时需要apr, apr-util, pcre的依赖关系,否则编译不过
编译libxml2失败,是因为装了两个版本的zlib,解决方法: ./configure --prefix=/usr/local/libxml2/ --without-zlib
php make不过需要修改gd_io.h make: *** [ext/gd/gd.lo] Error 1 [root@centos php-5.4.11]# vi /usr/local/gd2/include/gd_io.h 1 #ifdef __cplusplus 2 extern "C" { 3 #endif 4 5 #ifndef GD_IO_H 6 #define GD_IO_H 1 7 8 #include <stdio.h> 9 10 #ifdef VMS 11 #define Putchar gdPutchar 12 #endif 13 14 typedef struct gdIOCtx 15 { 16 int (*getC) (struct gdIOCtx *); 17 int (*getBuf) (struct gdIOCtx *, void *, int); 18 19 void (*putC) (struct gdIOCtx *, int); 20 int (*putBuf) (struct gdIOCtx *, const void *, int); 21 22 /* seek must return 1 on SUCCESS, 0 on FAILURE. Unlike f seek! */ 23 int (*seek) (struct gdIOCtx *, const int); 24 25 long (*tell) (struct gdIOCtx *); 26 27 void (*gd_free) (struct gdIOCtx *); 28 29 void (*data); 30 }
php make 不过需要修改gd_compat.c make: *** [ext/gd/libgd/gd_compat.lo] Error 1 [root@centos php-5.4.11]# vi ext/gd/libgd/gd_compat.c 1 #include "php_config.h" 2 #ifdef HAVE_GD_PNG 3 /* needs to be first */ 4 # include </usr/local/libpng/include/png.h> 5 #endif 6 7 #ifdef HAVE_GD_JPG 8 #include <stdio.h> 9 # include <jpeglib.h> 10 #endif 11 12 #ifdef HAVE_GD_JPG