想搭建一個Lamp環境,因為編譯安裝太麻煩,對於我這樣的新手來說,太過於復雜。而CentOS自帶的Apache、MySql和PHP的版本都太低,不想用。上百度搜了一輪,原來可以通過添加Epel和Remi源來解決。對於Epel源和Remi源,網友是這樣介紹的:
EPEL源
EPEL,即Extra Packages for Enterprise Linux,是由 Fedora 社區創建維護,為 RHEL 及衍生發行版如 CentOS、Scientific Linux 等提供高質量軟件包的項目。EPEL中含有大量的軟件,對官方標准源是一個很好的補充。
“EPEL (Extra Packages for Enterprise Linux ) is a Fedora Special Interest Group that creates, maintains, and manages a high quality set of additional packages for Enterprise Linux, including, but not limited to, Red Hat Enterprise Linux (RHEL), CentOS and Scientific Linux (SL).”
wiki:http://fedoraproject.org/wiki/EPEL
Fedora EPEL 下載:http://mirrors.fedoraproject.org/publiclist/EPEL/
EPEL 下載地址:http://download.fedora.redhat.com/pub/epel/
請針對不同的版本下載相應的包。
Remi源
Remi源大家或許很少聽說,不過Remi源GoFace強烈推薦,尤其對於不想編譯最新版的linux使用者,因為Remi源中的軟件幾乎都是最新穩定版。或許您會懷疑穩定不?放心吧,這些都是Linux骨灰級的玩家編譯好放進源里的,他們對於系統環境和軟件編譯參數的熟悉程度毋庸置疑。
Remi下載地址:http://rpms.famillecollet.com/
您也需要針對不同的版本號下載。(以上介紹為轉載)
yum remove epel-release-6-8.noarch
以下是安裝的過程和命令:
安裝Epel源:
我本地的CentOS是6.5,所以安裝的是對應的版本epel 6
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
然后導入KEY
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
別忘了,還有一步
yum install yum-priorities
安裝Remi源:
版本也是對應CentOS6.x的
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
同樣也需要執行以下命令
yum install yum-priorities
OK,Epel和Remi源就已經添加了,在/etc/yum.repos.d/中可以看到,已經多了幾個文件:
epel.repo epel-testing.repo remi.php70.repo remi.repo
安裝Lamp環境:
安裝Apache
yum --enablerepo=remi install httpd
修改防火牆配置
打開/etc/sysconfig/iptables
vi /etc/sysconfig/iptables
在文件中添加:
-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
關閉SELINUX
打開文件
vi /etc/selinux/config
將以下兩行注釋掉並增加SELINUX=disabled:
#SELINUX=enforcing #注釋掉 #SELINUXTYPE=targeted #注釋掉 SELINUX=disabled #增加
配置apache2
編輯apache 配置文件
sudo vi /etc/httpd/conf/httpd.conf
找到 #ServerName www.example.com:80
修改為 ServerName 這里設置為你自己的域名,如果沒有域名,可以設置為localhost:80
配置開機自動啟動apache2
chkconfig httpd on
重啟CentOS,在瀏覽器輸入localhost應該就能看到'Apache 2 Test Page'頁面了。
安裝MySQL
yum --enablerepo=remi install mysql mysql-server
安裝完畢后,設置開機自動啟動,並拷貝配置文件
chkconfig mysqld on cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
啟動MySql,會根據配置文件生成一個/var/lib/mysql/mysql.sock文件。如果沒有這個文件,是不能登錄MySql的。
為root賬戶設置密碼
mysql_secure_installation
然后跟着提示輸入就可以了。
安裝PHP5
yum --enablerepo=remi install php
再安裝如下php組件:
yum --enablerepo=remi install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt
修改Apache配置:
vi /etc/httpd/conf/httpd.conf
找到DirectoryIndex index.html index.html.var
修改為:
DirectoryIndex index.php index.html index.htm Default.html Default.htm
重啟Apache,創建一個php文件測試。
結束。