1、準備工做php
一、開啓80、3306端口,關閉selinuxhtml
[root@justin ~]# vim /etc/sysconfig/iptables # Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT [root@justin ~]# sestatus SELinux status: disabled [root@justin ~]# /etc/init.d/iptables restart iptables: Flushing firewall rules: [ OK ] iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Unloading modules: [ OK ] iptables: Applying firewall rules: [ OK ] [root@justin ~]#
二、下載軟件包
mysql
軟件源代碼包存放位置:/usr/local/src 源碼包編譯安裝位置:/usr/local/軟件名字linux
a、下載apachec++
[root@justin ~]# cd /usr/local/src/ [root@justin src]# wget http://www.apache.org/dist/httpd/httpd-2.4.7.tar.gz
b、下載MySQLsql
http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.5/mysql-5.5.36.tar.gzshell
c、下載php數據庫
http://cn2.php.net/distributions/php-5.4.25.tar.gzapache
d、下載libmcrypt(PHPlibmcrypt模塊)
vim
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
e、下載apr(Apache庫文件)
http://archive.apache.org/dist/apr/apr-1.5.0.tar.gz
f、下載apr-util(Apache庫文件)
http://mirror.bit.edu.cn/apache/apr/apr-util-1.5.3.tar.gz
g、下載Zend Guard(PHP加速軟件)
http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
h、下載cmake(MySQL編譯工具)
http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
[root@justin src]# ls apr-1.5.0.tar.gz libmcrypt-2.5.7.tar.gz ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz cmake-2.8.12.2.tar.gz apr-util-1.5.3.tar.gz mysql-5.5.36.tar.gz httpd-2.4.7.tar.gz php-5.4.25.tar.gz [root@justin src]#
2、安裝
a、安裝編譯工具及庫文件
yum install make apr* autoconf automake gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch -y
b、安裝libmcrypt
[root@justin src]# tar zxvf libmcrypt-2.5.7.tar.gz [root@justin src]# cd libmcrypt-2.5.7 [root@justin libmcrypt-2.5.7]# ./configure [root@justin libmcrypt-2.5.7]# make && make install
c、安裝cmake
[root@justin src]# tar zxvf cmake-2.8.12.2.tar.gz [root@justin src]# cd cmake-2.8.12.2 [root@justin cmake-2.8.12.2]# ./configure [root@justin cmake-2.8.12.2]# make && make install
d、安裝apr
[root@justin src]# tar zxvf apr-1.5.0.tar.gz [root@justin src]# cd apr-1.5.0 [root@justin apr-1.5.0]# ./configure [root@justin apr-1.5.0]# make && make install
e、安裝apr-util
[root@justin src]# tar zxvf apr-util-1.5.3.tar.gz [root@justin src]# cd apr-util-1.5.3 [root@justin apr-util-1.5.3]# mkdir -p /usr/local/apr-util [root@justin apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config [root@justin apr-util-1.5.3]# make && make installl
f、安裝mysql
[root@justin apr-util-1.5.3]# cd .. [root@justin src]# groupadd mysql [root@justin src]# useradd -g mysql mysql -s /sbin/nologin --禁止登錄 [root@justin src]# mkdir -p /data/mysql --mysql數據庫目錄 [root@justin src]# chown -R mysql:mysql /data/mysql/ [root@justin src]# mkdir -p /usr/local/mysql --mysql安裝目錄 [root@justin src]# tar zxvf mysql-5.5.36.tar.gz [root@justin mysql-5.5.36]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:83 (MESSAGE): Curses library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
出錯了,提示RHEL平臺安裝ncurses-devel並刪除CMakeCache.txt
[root@justin mysql-5.5.36]# yum install -y ncurses-devel [root@justin mysql-5.5.36]# rm -f CMakeCache.txt [root@justin mysql-5.5.36]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc [root@justin mysql-5.5.36]# make && make install [root@justin mysql-5.5.36]# cd /usr/local/mysql/ [root@justin mysql]# cp ./support-files/my-huge.cnf /etc/my.cnf cp: overwrite `/etc/my.cnf'? y [root@justin mysql]# vim /etc/my.cnf [mysqld] ---該部分下 port = 3306 socket = /tmp/mysql.sock skip-external-locking datadir = /data/mysql ---添加此行,指定數據庫路徑 [root@justin mysql]# ./scripts/mysql_install_db --user=mysql --生成mysql系統數據庫 [root@justin mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld --把Mysql加入系統啓動 [root@justin mysql]# chmod 755 /etc/init.d/mysqld [root@justin mysql]# chkconfig mysqld on [root@justin mysql]# vim /etc/rc.d/init.d/mysqld 46 basedir=/usr/local/mysql 47 datadir=/data/mysql [root@justin mysql]# /etc/init.d/mysqld start Starting MySQL...... [ OK ] [root@justin mysql]# vim /etc/profile --把mysql服務加入系統環境變量 export PATH=$PATH:/usr/local/mysql/bin --文末添加該行 [root@justin mysql]# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql [root@justin mysql]# ln -s /usr/local/mysql/include/mysql /usr/include/mysql --把myslq的庫文件連接到系統默認的位置,在編譯相似PHP等軟件時能夠不用指定mysql的庫文件地址 [root@justin mysql]# mysql_secure_installation -bash: mysql_secure_installation: command not found --須要先重啓系統 [root@justin mysql]# init 6 [root@justin ~]# mysql_secure_installation [root@justin ~]# service mysqld restart Shutting down MySQL. [ OK ] Starting MySQL... [ OK ] [root@justin ~]#
g、安裝apache
[root@justin src]# cd /usr/local/src/ [root@justin src]# tar zxvf httpd-2.4.7.tar.gz [root@justin src]# cd httpd-2.4.7 [root@justin httpd-2.4.7]# mkdir -p /usr/local/apache [root@justin httpd-2.4.7]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-ssl --enable-ssl --enable-module=so --enable-rewrite --enable-cgid --enable-cgi [root@justin httpd-2.4.7]# make && make install [root@justin httpd-2.4.7]# /usr/local/apache/bin/apachectl -k start [root@justin httpd-2.4.7]# vim /usr/local/apache/conf/httpd.conf 191 ServerName localhost 249 DirectoryIndex index.html index.php 229 Options FollowSymLinks --不顯示目錄結構 236 AllowOverride All ---開啓apache支持僞靜態 349 AllowOverride All 199 AllowOverride All 149 LoadModule rewrite_module modules/mod_rewrite.so --開啓apache支持僞靜態 [root@justin httpd-2.4.7]# vi /etc/profile --添加apache服務系統環境變量 export PATH=$PATH:/usr/local/apache/bin --最後添加下面這一行 [root@justin httpd-2.4.7]# cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd cp: overwrite `/etc/rc.d/init.d/httpd'? y [root@justin httpd-2.4.7]# vim /etc/init.d/httpd #!/bin/sh --添加如下兩行 #chkconfig:2345 10 90 #description:Activates/Deactivates Apache Web Server [root@justin httpd-2.4.7]# chown daemon.daemon -R /usr/local/apache/htdocs [root@justin httpd-2.4.7]# chmod 700 !$ chmod 700 /usr/local/apache/htdocs [root@justin httpd-2.4.7]# chkconfig httpd on [root@justin httpd-2.4.7]# /etc/init.d/httpd start
h、安裝PHP
[root@justin src]# tar zxvf php-5.4.25.tar.gz [root@justin src]# cd php-5.4.25 [root@justin php-5.4.25]# mkdir -p /usr/local/php [root@justin php-5.4.25]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd --with-iconv --with-freetype --with-jpeg --with-png --with-zlib --with-libxml --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic --enable-suhosin --enable-session --with-mcrypt [root@justin php-5.4.25]# make && make install [root@justin php-5.4.25]# cp php.ini-production /usr/local/php/etc/php.ini --複製php配置文件到安裝目錄 [root@justin php-5.4.25]# rm -rf /etc/php.ini --刪除系統自帶的配置文件 [root@justin php-5.4.25]# ln -s /usr/local/php/etc/php.ini /etc/php.ini --建立配置文件軟連接 [root@justin php-5.4.25]# vim /usr/local/php/etc/php.ini 309 open_basedir = .:/tmp/ 315 disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_ status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_sock et_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbypo rt,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,p osix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getp grp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix _getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setp gid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname --列出PHP能夠禁用的函數,若是某些程序須要用到這個函數,能夠刪除,取消禁用 919 date.timezone = PRC 376 expose_php = OFF --禁止顯示php版本的信息 479 display_errors = OFF --關閉錯誤提示
i、安裝Zend Guard
[root@justin php-5.4.25]# cd .. [root@justin src]# mkdir /usr/local/zend [root@justin src]# tar zxvf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz [root@justin src]# cp ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/ZendGuardLoader.so /usr/local/zend/ --拷貝文件到安裝目錄 [root@justin src]#
j、配置PHP支持Zend Guard
[root@justin src]# vim /usr/local/php/etc/php.ini --文末添加如下 [Zend Guard] zend_extension=/usr/local/zend/ZendGuardLoader.so zend_loader.enable=1 zend_loader.disable_licensing=0 zend_loader.obfuscation_level_support=3 zend_loader.license_path=
k、配置Apache支持PHP
[root@justin src]# vim /usr/local/apache/conf/httpd.conf 150 LoadModule php5_module modules/libphp5.so --此行後面添加如下行 151 AddType application/x-httpd-php .php --php .php這個點前面有一個空格 [root@justin src]# service httpd restart [root@justin src]# service mysqld restart
3、測試
[root@justin src]# cd /usr/local/apache/htdocs/ [root@justin htdocs]# vim index.php --添加如下內容 <?php phpinfo(); ?> [root@justin htdocs]# mv index.html index.htmlbak
在瀏覽器裏輸入IP地址就能夠訪問到相關配置信息
網站程序上傳到/usr/local/apache/htdocs/目錄中,遇到安裝問題,檢查權限
[root@justin htdocs]# chown daemon.daemon -R /usr/local/apache/htdocs/ [root@justin htdocs]# chmod 700 -R /usr/local/apache/htdocs/
至此RHEL+Apache+MySQL+PHP+ZendOptimize配置完成
###########################################################
關注微信平臺,瞭解更多分享