CentOS編譯安裝lamp

來源:互聯網
上載者:User

標籤:

LAMP環境搭建(編譯安裝CentOS+httpd2.2+mysql5.5+php5.4)首先準備以下壓縮包


<ignore_js_op> 

(1)編譯安裝apache

1、配置防火牆,開啟80連接埠、3306連接埠
執行以下命令:
#vi /etc/sysconfig/iptables
添加以下兩條規則到22連接埠這條規則的下面
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #允許80連接埠通過防火牆
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #允許3306連接埠通過防火牆

2、確定IP[[email protected] ~]# ifconfig eth03、確定主機名稱[[email protected] ~]#hostnamewww.htu.com

 

4  卸載httpd,並且將源碼包解壓rpm -e httpd httpd-manual webalizersubversion mod_python mod_ssl mod_perl php php-common mysql dovecot –nodepstar xzf httpd-2.2.17.tar.gz-C /usr/src/            //將源碼包解壓到了/usr/src




5、編譯安裝apache[[email protected]]# ./configure --prefix=/usr/local/httpd--enable-so --enable-rewrite --enable-charset-lite && make &&make install 6、查看安裝的結果 [[email protected] ~]# ls /usr/local/httpd/bin  build cgi-bin  conf  error htdocs  icons  include lib  logs  man manual  modules 那麼httpd的執行目錄就在/usr/local/httpd/bin/這個目錄下,但是這樣我會覺得很冗餘,所以用以前講過的ln來串連[[email protected] httpd]#ln -s /usr/local/httpd/bin/* /usr/local/bin/[[email protected] ~]#httpd -v  7、添加服務,添加服務識別配置[[email protected] ~]# cp/usr/local/httpd/bin/apachectl /etc/init.d/httpdVi  /et       c/init.d/httpd#chkconfig: 35 8515#description:httpd start server [[email protected] ~]#chkconfig--add httpd[[email protected] ~]# chkconfig --list httpdhttpd                0:關閉  1:關閉  2:關閉  3:啟用  4:關閉  5:啟用  6:關閉[[email protected] ~]# chkconfig--level 35 httpd on8 編輯httpd的主設定檔添加網域名稱 Vi /usr/local/httpd/conf/httpd.confServerName www.htu.com:80 檢查httpd的語法錯誤[[email protected] ~]# /usr/local/httpd/bin/apachectl -tSyntax OK 9       啟動httpd服務/etc/init.d/httpdstart驗證是否開啟服務[[email protected] ~]# netstat -natp | grep httpdtcp        0     0 :::80                      :::*                        LISTEN      29040/httpd          10    測試時候成功<ignore_js_op> 

 

(2)編譯安裝mysql1  準備工作: 卸載rpm的mysql-server
[[email protected]/]# rpm-e mysql-server –nodeps
[[email protected] /]#useradd -M -u 49 -s /sbin/nologin mysql    //建立mysql運行使用者MySQL 
從5.5開始改用cmake來編譯源碼代替./configure,
在編譯安裝 MySQL5.5.x 之前,需要最少安裝的包有:
gcc4.4.6、gcc-c++、cmake、ncurses-devel、bison
這時只需你的Linux系統安裝cmake、ncurses-devel、bison,
[[email protected] ~]# yum install gcc gcc-c++  
[[email protected] ~]#yum install ncurses-devel
  首先要先去網上下載一個cmake軟體一、安裝 cmake --前提軟體。
[[email protected]~]# tar zxvf cmake-2.8.5.tar.gz  -C /usr/src   (解壓)
[[email protected] ~]# cd cmake-2.8.5                 (進入目錄)
[[email protected] cmake-2.8.5  ]#./configure –prefix=/usr/local/cmaked(編譯前配置—prefix=制定路徑為/usr/local/cmaked/)
[[email protected] cmake-2.8.5 ]# gmake && gmake install          (編譯安裝)
cmake安裝完成cmake -D<變數>=<值>
2.安裝mysql5.5.20

[[email protected] ~]# tar zxvf mysql-5.5.20.tar.gz  -C /usr/src     (解壓)
[[email protected] ~]# cd mysql-5.5.20       (進入目錄)
[[email protected] mysql-5.5.20]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysqld-DMYSQL_UNIX_ADDR=/tmp/mysql.sock 
-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci  -DWITH_EXTRA_CHARSETS=all-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1-DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1
-DWITH_SSL=yes  -DENABLED_LOCAL_INFILE=1      (編譯前配置) 
[[email protected] mysql-5.5.20]#make  && make install(編譯安裝)

注意:如果提示編譯時間錯誤cmake:command not found輸入一下命令export PATH=/usr/local/cmake/binPATH   #PATH=你的camke編譯指定路徑
#這裡編譯cmake的時候沒有指定路徑  如果有路徑就執行上面的命令
3 安裝後調試 建立設定檔,這裡我們複製已有模板
[[email protected] mysql-5.5.20]#cp support-files/my-medium.cnf /etc/my.cnf
用mysql使用者初始化資料庫(/usr/local/mysqld/scripts)




4.初始化資料庫
[[email protected] ~]# /usr/local/mysqld/scripts mysql_install_db --user=mysql 
FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run ‘make install‘ to 
copy the software into the correct location ready for operation. 
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option 
pointing to that location. 
#初始化碰到這個錯誤是因為沒有指定安裝目錄以及存放資料的目錄,
[[email protected] ~]#./mysql_install_db --user=mysql --basedir=/usr/local/mysqld/--datadir=/usr/local/mysqld/data/5.修改資料庫檔案的屬主 
[[email protected] /]# chown -R root:mysql/usr/local/mysqld/
[[email protected]/]# chown -R mysql /usr/local/mysqld/data/
6.最佳化mysql程式目錄的路徑
[[email protected]]# ln -s /usr/local/mysqld/bin/* /usr/local/bin/
[[email protected] bin]# ln -s /usr/local/mysql/lib/* /usr/lib
[[email protected] bin]# ln-s /usr/local/mysql/include/mysql/* /usr/include/
然後要做的是添加系統服務,這樣就很方便我們開啟和關閉了
[[email protected] bin]# cp/usr/src/mysql-5.5.20/support-files/mysql.server /etc/rc.d/init.d/    //將源碼包中的服務啟動指令碼複製到自動啟動的路徑下
[[email protected] bin]#chmod a+x/etc/rc.d/init.d/mysql.server  (給執行服務運行許可權)
[[email protected] bin]#chkconfig –add mysql.server            (加服務)
現在可以很方便的開啟和關閉,也能看到mysqld的連接埠號碼3306 那麼在預設情況下我們可以用root登入,沒有密碼
[[email protected]/]#  PATH=$PATH:/usr/bin/   指定命令搜尋的路徑,這樣就能找到mysqladmin的命令了
[[email protected]/]#mysqladmin –u –p “htuidc”  

<ignore_js_op> (3)編譯安裝php準備工作和安裝1 首先要卸載php相關的rpm包以免後期衝突     (沒有的話就不用卸載了-)
rpm -e php php-cliphp-ldap php-common php-mysql –nodeps
安裝 libmcrypt
[[email protected] /usr/src]# cd /usr/src/libmcrypt-2.5.8/
[[email protected] libmcrypt-2.5.8]#./configure
[[email protected] libmcrypt-2.5.8]#make && make install
[[email protected] libmcrypt-2.5.8]#ln -s /usr/local/lib/libmcrypt.* /usr/lib  
安裝mhash
[[email protected]  /usr/src]# tar xzf mhash-0.9.9.9.tar.gz-C /usr/src/
[[email protected] /usr/src]# cd /usr/src/mhash-0.9.9.9/
[[email protected] mhash-0.9.9.9]#./configure
[[email protected] mhash-0.9.9.9]#make && make install
[[email protected] mhash-0.9.9.9]ln-s /usr/local/lib/libmhash* /usr/lib 
安裝mcrypt   
(通過rpm或者是yum來裝一個libxml2-devel)
Yum –y install libxml2-delvel
rpm –ivh libxml2-delvel
[[email protected] /usr/src]# tar xzf mcrypt-2.6.8.tar.gz-C /usr/src/
[[email protected] /usr/src]# cd /usr/src/mcrypt-2.6.8/
[[email protected] mcrypt-2.6.8]#./configure
[[email protected] mcrypt-2.6.8]#make && make install 
安裝php
[[email protected] /usr/src]# tar xzf php-5.3.6.tar.gz-C /usr/src/
[[email protected] /usr/src # cd /usr/src/php-5.3.6/
[[email protected]]#./configure --prefix=/usr/local/php5 --with-mcrypt --with-apxs2=/usr/local/httpd/bin/apxs 
--with-mysql=/usr/local/mysqld/ --with-config-file-path=/usr/local/php5 --enable-mbstring --prefix:設定php程式的安裝路徑-
-enable-mbstring:設定php支援多位元組字串--with-apxs2:設定apache伺服器提供的apxs模組支援程式的檔案路徑位置
--with-configure-file-path:設定php程式的設定檔所在位置 
[[email protected] php-5.3.6]#make && make install2、複製php.ini設定檔
[[email protected] /]# cp/usr/src/php-5.3.6/php.ini-development  /usr/local/php5/php.ini 
3 最佳化zendguardloader
[[email protected] 1234]#tar xzf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz -C /usr/src/ 
[[email protected] /]# cd/usr/src/ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/
[[email protected]]# cp ZendGuardLoader.so /usr/local/php5/lib/php
拷貝最佳化模組到php模組檔案夾然後修改php.ini
Vi/usr/local/php5/php.ini
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1
[[email protected]]# vi /usr/local/httpd/conf/httpd.conf
AddTypeapplication/x-httpd-php .php       //這個是要手動添加的php功能
<IfModuledir_module>    
DirectoryIndex index.html index.php    //添加網頁支援php
</IfModule>
修改之後注意重啟使之生效
setenforce0  關閉Selinux
[[email protected]]# /etc/init.d/httpd restart

3 、測試php運行環境編譯php網頁測試檔案
[[email protected] htdocs]#vi test1.php 
<?php
phpinfo();
?>
<ignore_js_op> 
(2個測試頁最好手動輸入 )

[[email protected] htdocs]#vi test2.php 
<?php
$link=mysql_connect(‘localhost‘,‘root‘,‘htuidc‘);
if($link)
  echo "success";
?>
<ignore_js_op> 

<ignore_js_op>

CentOS編譯安裝lamp

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.