安裝次序
httpd, MariaDB, php
安裝apache2.4
[root@root ~]# yum groupinstall "Development Tools" "Server Platform Develoment " –y #安裝開發環境 [root@root ~]# yum install pcre-devel –y #安裝pcre [root@root ~]# wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.2.tar.gz #下載apr [root@root ~]# wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.4.tar.gz #下載apr-util [root@root ~]# ls anaconda-ks.cfg apr-util-1.5.4.tar.gz install.log.syslog apr-1.5.2.tar.gz install.log [root@root ~]# tar -xf apr-1.5.2.tar.gz #安裝apr [root@root ~]# cd apr-1.5.2 [root@root apr-1.5.2]# ./configure --prefix=/usr/local/apr #為避免覆蓋1.3.9版本的apr,我們選擇新的路徑進行安裝 [root@root ~]# tar -xf apr-util-1.5.4.tar.gz #安裝apr-util [root@root ~]# cd apr-util-1.5.4 [root@root apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr =/usr/local/apr #針對于apr做編譯 [root@root apr-util-1.5.4]# make && make install [root@root ~]# groupadd -r apache [root@root ~]# useradd -r -g apache apache #添加系統用戶和系統組apache [root@root ~]# yum install pcre-devel–y #在編譯httpd2.4前需要安裝pcre [root@root ~]# wget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.20.tar.g z #下載httpd2.4 [root@root ~]# tar -xvf httpd-2.4.20.tar.gz [root@root ~]# cd httpd-2.4.20 [root@root httpd-2.4.20]# ./configure --prefix=/usr/local/apache --sysconf=/etc /httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --w ith-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enabl e-modules=most --enable-mpms-shared=all --with-mpm=prefork
涉及到以下參數
--prefix=/usr/local/apache2.4.9 #應用程序安裝路徑 --sysconfdir=/etc/httpd #配置文件的安裝路徑 --enable-so #支持DSO動態裝載模塊 --enable-ssl #要編譯啟用ssl模塊(前提是需要安裝openssl-devel) --enable-cgi #啟用CGI模塊(默認就啟用) --enable-rewrite #URL重寫(把用戶訪問的URL由服務器自動的改成另外一個URL, #這是一個非常有用的機制) --with-zlib #這是一個壓縮庫(專用于網絡傳輸) --with-pcre #使用增強的perl正則表達式分析工具(使用這項需要安 #裝pcre-devel,pcre:正則表達式分析器) --with-apr=/usr/local/apr #指明apr的目錄(若apr在特殊路徑下) --with-apr-util=/usr/local/apr-util/ #指明apr-util路徑(若apr-util在特殊路徑下 ) --enable-mpms-shared=all #把所有的mpm模塊都編譯進來而且是共享模塊 --with-mpm=prefork #默認使用的mpm模塊 --enable-modules=most(all) #還有很多其他模塊,其他的動態可裝載模塊需要 #編譯哪些 #(all:所有都編譯,most:編譯一些常用的模塊) [root@root httpd-2.4.20]#make && make install [root@root ~]# /usr/local/apache/bin/apachectl -t #檢查apache主配置文件語法是否有錯誤 Syntax OK
查看httpd-2.4.20安裝目錄的內容
[root@Centos ~]# tree -d /usr/local/apache/ /usr/local/apache/ ├── bin #存放啟動或關閉httpd的腳本文件 ├── build ├── cgi-bin #cgi程序文件的存放目錄 ├── error #發生服務器端錯誤時返回給客戶端的錯誤頁面 │ └── include ├── htdocs #Web頁面所在的目錄 ├── icons #存放httpd的圖標文件 │ └── small ├── include #存放頭文件 ├── logs #httpd的日志文件 ├── man #幫助手冊 │ ├── man1 │ └── man8 ├── manual #httpd的配置手冊 │ ├── developer │ ├── faq │ ├── howto │ ├── images │ ├── misc │ ├── mod │ ├── platform │ ├── programs │ ├── rewrite │ ├── ssl │ ├── style │ │ ├── css │ │ ├── lang │ │ ├── latex │ │ ├── scripts │ │ └── xsl │ │ └── util │ └── vhosts └── modules #存放httpd的模塊
編譯安裝后的基本配置:
1.修改httpd的主配置文件,設置其Pid文件的路徑:
vim /etc/httpd24/httpd.conf ServerRoot "/usr/local/apache" PidFile "/var/run/httpd.pid" 修改PAT H環境變量,讓/usr/local/apache/bin目錄下的命令都可以執行: [root@root ~]# vim /etc/profile.d/httpd.sh #必須要以.sh結尾,并且放在這里可以單獨管理,不要的時候可以直接刪除,添加如下內容 export PATH=/usr/local/apache/bin:$PATH [root@root ~]# . /etc/profile.d/httpd.sh #source一下 [root@root ~]# httpd -t #檢查是相關命令是否可用了 Syntax OK
2.導出頭文件:
[root@root ~]# ln -sv /usr/local/apache/include/ /usr/local/include/httpd `/usr/local/include/httpd' -> `/usr/local/apache/include/'
3.導出man手冊(用vim編輯/etc/man.config):
MANPATH /usr/man MANPATH /usr/share/man MANPATH /usr/local/man MANPATH /usr/local/share/man MANPATH /usr/X11R6/man 加上下面這一行 MANPATH /usr/local/apache/man
4.編寫服務腳本(因是編譯安裝,不會自動生成服務腳本)并給其添加執行權限:(vim
/etc/rc.d/init.d/httpd) #!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: Apache is a World Wide Web server. It is used to serve \ # HTML files and CGI. # processname: httpd # config: /etc/httpd/conf/httpd.conf # config: /etc/sysconfig/httpd # pidfile: /var/run/httpd.pid # Source function library. . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi # Start httpd in the C locale by default. HTTPD_LANG=${HTTPD_LANG-"C"} # This will prevent initlog from swallowing up a pass-phrase prompt if # mod_ssl needs a pass-phrase from the user. INITLOG_ARGS="" # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server # with the thread-based "worker" MPM; BE WARNED that some modules may not # work correctly with a thread-based MPM; notably PHP will refuse to start. # Path to the apachectl script, server binary, and short-form for messages. apachectl=/usr/local/apache/bin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS "/etc/rc.d/init.d/httpd" 86L, 2314C 31,1 Top #!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: Apache is a World Wide Web server. It is used to serve \ # HTML files and CGI. # processname: httpd # config: /etc/httpd/conf/httpd.conf # config: /etc/sysconfig/httpd # pidfile: /var/run/httpd.pid # Source function library. . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi # Start httpd in the C locale by default. HTTPD_LANG=${HTTPD_LANG-"C"} # This will prevent initlog from swallowing up a pass-phrase prompt if # mod_ssl needs a pass-phrase from the user. INITLOG_ARGS="" # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server # with the thread-based "worker" MPM; BE WARNED that some modules may not # work correctly with a thread-based MPM; notably PHP will refuse to start. # Path to the apachectl script, server binary, and short-form for messages. apachectl=/usr/local/apache/bin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS "/etc/rc.d/init.d/httpd" 86L, 2314C 31,1 Top echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p ${pidfile} -d 10 $httpd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: " if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then RETVAL=$? echo $"not reloading due to configuration syntax error" failure $"not reloading $httpd due to configuration syntax error" else killproc -p ${pidfile} $httpd -HUP RETVAL=$? fi echo } # See how we were called. case "$1" in start) start;; stop) stop;; status) status -p ${pidfile} $httpd 33,5 61% status) status -p ${pidfile} $httpd RETVAL=$?;; restart) stop start;; condrestart) if [ -f ${pidfile} ] ; then stop start fi;; reload) reload;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$?;; *) echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatu s |graceful|help|configtest}" exit 1 esac exit $RETVAL apachectl=/usr/local/apache/bin/apachectl #需要注意這些路徑 httpd=${HTTPD-/usr/local/apache/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd}
5.啟動服務并測試:
[root@root ~]#vi /etc/sysconfig/iptables #iptables添加80端口 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80-j ACCEPT [root@root ~]# service httpd start
測試
6.設置開機啟動:
[root@root ~]# chkconfig httpd on [root@root ~]# chkconfig –list | grep httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
安裝mariadb
[root@root ~]# groupadd -r mysql [root@root ~]# useradd -r mysql -g mysql [root@root ~]# id mysql uid=496(mysql) gid=494(mysql) groups=494(mysql) [root@root~]#wget https://downloads.mariadb.org/interstitial/mariadb-5.5.36/kvm -bintar-centos5-amd64/mariadb-5.5.36-linux-x86_64.tar.gz/from/http%3A//archive. mariadb.org/ [root@root]# tar -zxvf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local [root@root ~]# cd /usr/local [root@root local]# ls bin games include lib64 mariadb-5.5.36-linux-x86_64 share etc gnupg lib libexec sbin src [root@root local]# ln -sv mariadb-5.5.36-linux-x86_64 mysql [root@root local]# ll drwxr-xr-x. 13 root root 4096 May 13 06:53 mariadb-5.5.36-linux-x86_64 [root@root local]# cd mysql/ [root@root mysql]# chown -R root:mysql ./* [root@root mysql]# ls scripts/ mysql_install_db [root@root ~]# scripts/mysql_install_db --help --basedir=path #mysql安裝目錄 --datadir=path #數據存放位置 --user=user_name #以哪個用戶的身份安裝 [root@root mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/mysq l-data/
初始化mysql
[root@root mysql]# ls support-files/ #查看服務腳本mysql.serve binary-configure magic my-medium.cnf mysql.server config.huge.ini my-huge.cnf my-small.cnf ndb-config-2-no de.ini config.medium.ini my-innodb-heavy-4G.cnf mysqld_multi.server SELinux config.small.ini my-large.cnf mysql-log-rotate solaris [root@root mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld root@root mysql]# chkconfig --add mysqld [root@root mysql]# chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off root@root mysql]# mkdir /etc/mysql [root@root mysql]# pwd /usr/local/mysql [root@root mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf [root@root mysql]# vim /etc/mysql/my.cnf
thread_concurrency = 8 #并行線程數,cpu*2 datadir=/mydata/mysql-data/ #修改data路徑 innodb_file_per_table #暫不解釋 skip_name_resolve = on #跳過名稱反解,直接識別ip
[root@root mysql]# service mysqld start Starting MySQL.. SUCCESS! [root@root mysql]# ss -tnl 0 50 *:3306 *:* #3306端口處于監聽狀態
安裝php
[root@root ~]# wget http://cn2.php.net/distributions/php-5.6.23.tar.gz [root@root ~]# tar -zxvf php-5.6.23.tar.gz -C /usr/local/ wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo #配置epel源 [root@root ~]# yum install bzip2-devel libmcrypt-devel libxml2-devel –y [root@root ~]# cd /usr/local/php-5.6.23/
[root@root ~]#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openss l --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-free type-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --en able-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcryp t --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-b z2 --enable-maintainer-zts
--enable-mbstring #多字節字符串支持 --with-freetype-dir #支持freetype字體格式 --with-jpeg-dir #支持jpeg圖片格式 --with-png-dir #支持png圖片格式 --enable-sockets #支持與sockets通信 --with-apxs2=/usr/local/apache/bin/apxs #把php編譯成apache的模塊 --with-mcrypt #支持加密解密庫 --enable-maintainer-zts #編譯成zts模塊,event,worker模式使用
[root@root php-5.6.23]#make -j 4 && make install [root@root php-5.6.23]# cp php.ini-production /etc/php.ini #為php提供配置文件 [root@root php-5.6.23]# cd /etc/httpd24/ [root@root httpd24]# cp httpd.conf {,.bak} [root@root httpd24]# vim httpd.conf #編輯apache配置文件httpd.conf,使apache支持p hp AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType application/x-httpd-php .php #添加 AddType application/x-httpd-php-source .phps #添加 DirectoryIndex index.php index.html #定位至DirectoryIndex index.html修改 [root@root httpd24]# service httpd restart [root@root httpd24]# cd /usr/local/apache/ [root@root apache]# ls bin build cgi-bin error htdocs icons include logs man manual modules [root@root apache]# cd htdocs/ [root@root htdocs]# mv index.html index.php [root@root htdocs]# vim index.php
測試
[root@root htdocs]# service mysqld stop
原創文章,作者:Net17_得得,如若轉載,請注明出處:http://www.www58058.com/20830