系統:CentOS 6.5 64位php
rpm -qa | grep mysql #查詢是否已經安裝MySQL,若有執行下面的操做將其所有刪除 rpm -e mysql --nodeps #--nodeps選項強制刪除,刪除全部以MySQL開頭的軟件 rpm -e mysql-devel rpm -e mysql-libs --nodeps rpm -qa | grep httpd #查詢、卸載安裝的Apache rpm -e httpd --nodeps rpm -e httpd-tools --nodeps rpm -qa|grep php #查詢是否安裝php,如有將其卸載
二、更新系統,並安裝基本編譯器html
yum -y update yum -y install wget make zlib-devel openssl openssl-devel pcre-devel kernel keyutils patch perl yum -y install gcc gcc-c++ #基本編譯器 yum -y install libXpm-devel #編譯php須要 yum -y install openssl-devel
cd /usr/local/src/ mkdir /usr/local/src/dbtools/ #這個目錄下的軟件主要是安裝MySQL使用的 cd /usr/local/src/dbtools/ wget http://ftp.gnu.org/gnu/make/make-4.1.tar.gz wget http://alpha.gnu.org/gnu/bison/bison-2.7.91.tar.gz wget http://www.cmake.org/files/v3.2/cmake-3.2.2.tar.gz wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.24.tar.gz wget -O m4-1.4.9.tar.gz http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz ls *.tar.gz | xargs -n1 tar xzvf #批量解壓 cd .. mkdir -p /usr/local/src/libtools #這個目錄下安裝gd及其依賴庫以支持php對圖片的處理 cd /usr/local/src/libtools wget http://xmlsoft.org/sources/libxml2-sources-2.9.2.tar.gz wget http://mirrors.linuxeye.com/lnmp/src/libmcrypt-2.5.8.tar.gz wget http://zlib.net/zlib-1.2.8.tar.xz wget http://ncu.dl.sourceforge.net/project/libpng/libpng16/1.6.17/libpng-1.6.17.tar.gz wget http://www.ijg.org/files/jpegsrc.v9.tar.gz wget http://jaist.dl.sourceforge.net/project/freetype/freetype2/2.5.5/freetype-2.5.5.tar.gz wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz wget https://codeload.github.com/libgd/libgd/tar.gz/gd-2.1.0 mv gd-2.1.0 gd-2.1.0.tar.gz #這裏下載後的文件後綴不對,改一下名稱後綴 ls *.tar.gz | xargs -n1 tar xzvf cd .. mkdir -p /usr/local/src/apache_tools cd /usr/local/src/apache_tools wget http://mirrors.linuxeye.com/lnmp/src/apr-util-1.5.4.tar.gz wget http://mirrors.linuxeye.com/lnmp/src/apr-1.5.1.tar.gz wget http://mirrors.linuxeye.com/lnmp/src/pcre-8.37.tar.gz wget http://www.apache.org/dist/httpd/httpd-2.4.12.tar.gz cd .. mkdir -p /usr/local/src/php_pack cd /usr/local/src/php_pack wget http://mirrors.linuxeye.com/lnmp/src/phpMyAdmin-4.4.7-all-languages.tar.gz wget http://mirrors.sohu.com/php/php-5.5.15.tar.gz #wget http://cn2.php.net/distributions/php-5.4.41.tar.gz #wget https://codeload.github.com/eaccelerator/eaccelerator/legacy.tar.gz/master #php5.5之後的版本不能用這些外在的加速插件了 #mv master eaccelerator-eaccelerator.tar ls *.tar.gz | xargs -n1 tar xzvf
cd libxml2-2.9.2/ ./configure --prefix=/usr/local/libxml2 && make && make install cd .. cd libmcrypt-2.5.8 ./configure --prefix=/usr/local/libmcrypt && make && make install cd .. cd zlib-1.2.8 ./configure --prefix=/usr/local/zlib && make && make install cd.. cd libpng-1.6.17 ./configure --prefix=/usr/local/libpng && make && make install cd .. mkdir /usr/local/jpeg9 #創建軟件安裝目錄 mkdir /usr/local/jpeg9/bin #創建存放命令的目錄 mkdir /usr/local/jpeg9/lib #創建jpeg庫文件所在目錄 mkdir /usr/local/jpeg9/include #創建存放頭文件目錄 mkdir -p /usr/local/jpeg9/man/man1 #創建存放手冊目錄 cd jpeg-9 ./configure --prefix=/usr/local/jpeg9/ --enable-shared --enable-static make && make install cd .. cd freetype-2.4.10 ./configure --prefix=/usr/local/freetype && make && make install cd .. cd autoconf-2.69 ./configure && make && make install cd .. libgd-gd-2.1.0 ./bootstrap.sh ./configure --prefix=/usr/local/gd2 --with-zlib=/usr/local/zlib/ --with-jpeg=/usr/local/jpeg9/ --with-png=/usr/local/libpng/ --with-freetype=/usr/local/freetype make && make install
#拷貝兩個文件到httpd目錄下(注意:低一些的版本可能不須要此操做),並同時重命名 cp -a apr-1.5.1 httpd-2.4.12/srclib/apr cp -a apr-util-1.5.4 httpd-2.4.12/srclib/apr-util #安裝pcre cd pcre-8.37 ./configure && make && make install cd .. #安裝Apache ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd/ --with-z=/usr/local/zlib/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support make && make install #修改配置文件 # vim /etc/httpd/httpd.conf 將ServerName localhost:80 DirectoryIndex index.html index.htm index.php #測試成功後,爲Apache添加自啓動功能,用以下命令編輯/etc/rc.d/rc.local 文件: echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.local /usr/local/apache2/bin/apachectl start 啓動服務器 打開網頁輸入Localhost,應該看到it works字樣
二、安裝mysqlnode
2-一、#安裝基本依賴包,這裏採用源碼安裝的方式,也可使用yum命令安裝
cd make-4.1 ./configure && make && make install cd m4-1.4.9 ./configure && make && make install cd bison-2.7.91 ./configure && make && make install cd cmake-3.2.2 ./bootstrap && gmake && gmake install make && make install cd ncurses-5.9 ./configure && make && make install
#安裝mysql 2-二、#首先,建立mysql用戶、組
groupadd mysql useradd -r -g mysql mysql mkdir -p /usr/local/mysql #軟件安裝目錄 mkdir -p /usr/local/mysql/data #數據倉庫目錄
進入安裝目錄並安裝:mysql
cd mysql-5.6.24linux
cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql\ -DMYSQL_DATADIR=/data/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/mysql/mysql.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
解讀:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #軟件安裝目錄 -DMYSQL_DATADIR=/usr/local/mysql/data \ #數據倉庫目錄 -DSYSCONFDIR=/etc \ #my.cnf路徑 -DWITH_MYISAM_STORAGE_ENGINE=1 \ #支持MyIASM引擎 -DWITH_INNOBASE_STORAGE_ENGINE=1 \ #支持InnoDB引擎 -DWITH_MEMORY_STORAGE_ENGINE=1 \ #支持Memory引擎 -DWITH_READLINE=1 \ #快捷鍵功能(我沒用過) -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \ #鏈接數據庫socket路徑 -DMYSQL_TCP_PORT=3306 \ #端口 -DENABLED_LOCAL_INFILE=1 \ #容許從本地導入數據 -DWITH_PARTITION_STORAGE_ENGINE=1 \ #安裝支持數據庫分區 -DEXTRA_CHARSETS=all \ #安裝全部的字符集 -DDEFAULT_CHARSET=utf8 \ #默認字符 -DDEFAULT_COLLATION=utf8_general_ci
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
(2)、#copy配置文件,針對不一樣版本,5.6用下面一行
# cp support-files/my-medium.cnf /usr/local/mysql/my.cnf cp /usr/local/mysql/support-files/my-default.cnf /usr/local/mysql/my.cnf
(3)、 #更改權限
chown -R mysql:mysql /usr/local/mysql
(4)、vim /usr/local/mysql/my.cnf #修改文件,添加如下內容:
[mysqld] basedir = /usr/local/mysql datadir = /usr/local/mysql/data log-error = /usr/local/mysql/mysql_error.log pid-file = /usr/local/mysql/mysql.pid user = mysql tmpdir = /tmp
(5)、添加到引導程序中:
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
而後便可手工啓動
/etc/init.d/mysqld start ##或者 service mysqld start
注意:設置開機啓動:
chkconfig --add mysql ##有的系統須要下面的 chkconfig --level 345 mysql on
(6)、簡化調用過程,設置密碼,爲方便調用,添加一個軟鏈接:
ln -s /usr/local/mysql/bin/mysql /usr/bin/
設定一個密碼
#mysql #默認是空密碼,用這個命令就能夠啓動數據庫 mysql> SET PASSWORD = PASSWORD('123456');
# mysql -u root -p
# ./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-png-dir=/usr/local/libpng/ \ --with-jpeg-dir=/usr/local/jpeg9/ \ --with-freetype-dir=/usr/local/freetype/ \ --with-gd=/usr/local/gd2/ \ --with-zlib-dir=/usr/local/zlib/ \ --with-mcrypt=/usr/local/libmcrypt/ \ --with-mysqli=/usr/local/mysql/bin/mysql_config \ --enable-soap \ --enable-mbstring=all \ --enable-sockets # make && make install
cp php.ini-production /usr/local/php/etc/php.ini
149 LoadModule php5_module modules/libphp5.so #查看是否有這一行,若是PHP安裝成功會有此行,不然從新安裝PHP 378 AddType application/x-httpd-php .php .php4 .php5 #添加這兩行意思是以.php .php4 .php5這些擴展名結尾的文件在Apache中用php解析器解析。 379 AddType application/x-httpd-php .php .phtml
[root@vn~]# /usr/local/apache2/bin/apachectl stop [root@vn ~]# /usr/local/apache2/bin/apachectl start [root@vn ~]# vim /usr/local/apache2/htdocs/test.php #輸入如下內容並保存 <?php phpinfo(); ?>
目前PHP的緩存插件通常有三個: APC、 eAccelerator、 XCache,但將來它們可能都會消失,由於PHP 5.5已經集成 Zend Opcache,功能和前三者類似但又有少量不一樣,c++
緩存速度聽說比它們更快(注意:只是聽說,我沒測試過)。git
php5.5之後版本編譯eAccelerator報錯以下:github
eaccelerator.c:66:23: error: php_logos.h: No such file or directorysql
究其緣由是PHP5.5如下版本有php_logos.c,php_logos.h等文件。數據庫
若是想在新版本繼續用加速,目前知道是的php自帶擴展 opcache。
操做以下:
cd /usr/local/src/php_pack/php-5.5.15 /ext/opcache /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make && make install
修改配置文件# vim /usr/local/php/etc/php.ini 在最後加入
zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20121212/opcache.so 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
[root@kn curl]# pwd /usr/local/src/php_pack/php-5.5.15/ext/curl [root@kn curl]# ls config.m4 config.w32 CREDITS curl.dsp curl_file.c interface.c multi.c package.xml php_curl.h share.c tests [root@kn curl]# /usr/local/php/bin/phpize 便可 OK
852 ; ... or with a path: 853 ; 854 ; extension=/path/to/extension/msql.so 855 ; 856 extension=curl.so
[PHP Modules]
Core
ctype
curl
date
dom
ereg
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysql
mysqli
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
# /usr/local/apache2/bin/apachectl stop
# /usr/local/apache2/bin/apachectl start
<?php
echo phpinfo();
?>
cd phpMyAdmin-4.4.9-all-languages cp config.sample.inc.php config.inc.php #配置文件 cp -a phpMyAdmin-4.4.9-all-languages /usr/local/apache2/htdocs/myadmin #複製到指定目錄,並改名
wget https://download.suhosin.org/suhosin-0.9.38.tar.gz tar zxvf suhosin-0.9.38.tar.gz cd suhosin-0.9.38 /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make && make install
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20121212/ " extension="suhosin.so"