CentOS 6搭建LAMP和phpRedisAdmin遇到的問題及解決方案分享

來源:互聯網
上載者:User
文章目錄
  • 1.yum安裝apache
  • 2.yum安裝mysql
  • 3.yum安裝apache
  • 4.源碼安裝phpredis

最近在項目中用到Reids,為了簡化測試人員的工作,所以準備搭建phpRedisAdmin,環境是64的CentOS6.0。雖然我對linux瞭解的很少,但是本想搭建個LAMP環境跟裝個php網站應該so easy。但結果卻是花了我好幾天的時間,這中間的折騰就不說,好歹結果還是搞定了。跟大家分享一下中間遇到的一寫問題以及解決方案:剛開始是用源碼安裝的,遇到了一大堆問題最後還是沒搞定。最後LAMP是用yum安裝的,同樣遇到了一大堆問題。下面都是我邊弄邊寫所以寫的有點亂,也懶得整理了,直接貼出來了。

1.yum安裝apache

在centos6.0 上安裝apache因為種種原因先是通過yum安裝然後又通過源碼安裝,後來又因為種種原因又要卸載apache。這時候出問題了。源碼安裝的我是直接刪除安裝目錄 /usr/local/apache2。然後通過yum remove httpd來刪除yum安裝的。提示刪除成功,但是我再用yum install httpd想驗證下我有沒有真的刪除掉的時候,系統又總是提示我已經安裝過apache。因為yum安裝不足就是我不知道到底安裝量哪些檔案,安裝的檔案在哪個目錄,所以一個個刪除檔案不顯示。
最後網上查到可以用rpm -qa|grep httpd查看安裝了哪些apache依賴的rpm包輸入如下:
httpd-tools-2.2.15-15.el6.centos.1.x86_64
httpd-2.2.15-15.el6.centos.1.x86_64
然後用rpm -e來刪除這些依賴項,但這時候又出現問題了,系統出錯提示如下:
error reading information on service httpd: No such file or directory
error: %preun(httpd-2.2.15-15.el6.centos.1.x86_64) scriptlet failed, exit status 1
最後沒辦法又的求助於穀哥哥,度娘娘,終於又查得一個rpm的一個參數 --noscripts:
最後終於通過rpm -e --noscripts刪除掉了上面的兩個包。
再次yum install httpd驗證,ok,搞定了。
哎,對linux瞭解甚少,剛開始圖容易,通過yum安裝,以後還是手動源碼自己編譯安裝,雖然複雜了點,但是定製性強。

2.yum安裝mysql

首先來進行 MySQL 的安裝。開啟超級終端,輸入:

[root@localhost ~]# yum install mysql mysql-server
安裝完畢,讓 MySQL 能夠隨系統自動啟動:
[root@localhost ~]# chkconfig --levels 235 mysqld on
[root@localhost ~]# /etc/init.d/mysqld start
設定 MySQL 資料 root 賬戶的密碼:
[root@localhost ~]# mysql_secure_installation
但是這時候卻出現了Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)的錯誤
最後發現原來我的/tmp下有mysql.sock但是啟動尋找的目錄是/var/lib/mysql,這個目錄下並沒有mysql.sock,於是做了一個連結ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock解決了問題。但是還是疑惑為什麼yum安裝mysql啟動時候到/var/lib/mysql下尋找mysql.sock但是設定檔my.cnf裡配的路徑卻是/tmp/mysql.sock

3.yum安裝apache

[root@localhost ~]# yum install httpd
同樣配置系統讓 Apache 隨系統啟動:
[root@localhost ~]# chkconfig --levels 235 httpd on
配置完畢,啟動 Apache:
[root@localhost ~]# /etc/init.d/httpd start
這時候又遇到問題了:
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.33.225 for ServerName
(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
重啟系統,如果重啟不行的話
可以用netstat -lnp|grep 80看哪些進程佔用了80連接埠
可以利用ps pid的方法查看具體某個進程。
然後用他kill -9 pid將佔用80連接埠的進程殺掉

4.源碼安裝phpredis

因為要安裝phpRedisAdmin所以要裝php的Redis擴充phpredis,但是通過yum安裝phphou就是找不到phpize,phpzie是用來安裝php擴充的,找不到它自然無法安裝phpRedis.最後發現原來phpize是屬於php-devel的。yum install php-devel後發現phpize出現在/usr/bin目錄下了。

在裝好phpize後,開始裝phpredis:

下載好phpredis的tar包解壓,開始安裝:
[root@junlings /]# cd /usr/local/src
[root@junlings src]# cd phpredis/
[root@junlings phpredis]# cd owlient-phpredis-90ecd17/
[root@junlings owlient-phpredis-90ecd17]# /usr/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
[root@junlings owlient-phpredis-90ecd17]# ./configure -with-php-config=/etc
這時候又出現問題了,說:configure: error: Cannot find php-config. Please use --with-php-config=PATH
但是我從phpinfo()打出來的資訊可以看到php的設定檔就在/etc目錄下。但是cd到/etc目錄下卻沒有發現php.ini這個檔案。通過find也沒找到系統中有php.ini這個檔案。

於是嘗試直接./configure然後直接make & make install然後提示redis.so被安裝到了/usr/lib64/php/modules/。但是這樣重新整理重啟apache後再phpinfo頁面還是沒看到支援redis的資訊。/etc下不是沒有php.ini,於是手動建了一個添上一行 extension="redis.so",在重啟apache,重新整理頁面,OK終於看到了redis……寫一個redis的測試頁面:
<?php
$redis=new Redis();
$redis->connect('192.168.32.13',6379);
$redis->set('test','Hello Redis Word!');
echo $redis->get('test');
?>
瀏覽看到“Hello Redis Word!”說明redis擴充安裝成功。

之後就是安裝phpRedisAdmin,那就很簡單了。回頭一想,雖然很不順利,但是經過這麼一折騰linux的基本命令都弄的差不對了,感謝不順啊~

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.