CentOS 7.0(64位)安裝配置LAMP服務器(Apache+PHP+MariaDB)
一、配置防火墻,開啟80端口、3306端口
CentOS 7.0默認使用的是firewall作為防火墻。
1、開啟firewall:
systemctl start firewalld.service #開啟firewall
systemctl enable firewalld.service #設置firewall開機啟動
2、配置firewalld防火墻
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --permanent --add-service=mysql
firewall-cmd --reload
二、關閉SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #注釋掉
#SELINUXTYPE=targeted #注釋掉
SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效
### 安裝篇:
一、安裝Apache
`yum install httpd` #根據提示,輸入Y安裝即可成功安裝
`systemctl start httpd.service` #啟動apache
`systemctl stop httpd.service` #停止apache
`systemctl restart httpd.service` #重啟apache
`systemctl enable httpd.service` #設置apache開機啟動
二、安裝MariaDB
CentOS 7.0中,已經使用MariaDB替代了MySQL數據庫
1、安裝MariaDB
`yum install mariadb mariadb-server` #詢問是否要安裝,輸入Y即可自動安裝,直到安裝完成
`systemctl start mariadb.service` #啟動MariaDB
`systemctl stop mariadb.service` #停止MariaDB
`systemctl restart mariadb.service` #重啟MariaDB
`systemctl enable mariadb.service` #設置開機啟動
`cp /usr/share/mysql/my-huge.cnf /etc/my.cnf` #拷貝配置文件(注意:如果/etc目錄下面默認有一個my.cnf,直接覆蓋即可)
2、為root賬戶設置密碼
`mysql_secure_installation
`
回車,根據提示輸入Y
輸入2次密碼,回車
根據提示一路輸入Y
最后出現:`Thanks for using MySQL!
`
MariaDB密碼設置完成,重新啟動 MariaDB:
`systemctl restart mariadb.service` #重啟MariaDB
三、安裝PHP
安裝PHP7.1組件,使PHP支持 MariaDB
yum install epel-release -y
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php71w php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath libjpeg php71w-ldap php71w-odbc php71w-pear php71w-xmlrpc
php71w-mcrypt -y
安裝解壓縮軟件和上傳插件(可選)
yum install unzip lrzsz -y
systemctl restart mariadb.service #重啟MariaDB
systemctl restart httpd.service #重啟apache
四、安裝ioncube_loader
1.下載:ioncube_loader(64位操作系統)
http://www.yuanfengtest.com/php7.1/ioncube7.1.zip
2.安裝 ioncube_loader
解壓后將 ioncube_loader_lin_7.1.so 拷貝到服務器 /usr/lib64/php/modules 目錄
將00-ioncube.ini 拷貝到服務器 /etc/php.d/ 目錄下
完成后重啟apache:systemctl restart httpd.service
配置篇
一、Apache配置
vi /etc/httpd/conf/httpd.conf
#編輯文件
`ServerSignature On` #添加,在錯誤頁中顯示Apache的版本,Off為不顯示
`Options Indexes FollowSymLinks` #修改為:`Options Includes ExecCGI FollowSymLinks`(允許服務器執行CGI及SSI,禁止列出目錄)
`AllowOverride None` #修改為:`AllowOverride All` (允許.htaccess)
`#Options Indexes FollowSymLinks #`修改為 `Options FollowSymLinks`(不在瀏覽器上顯示樹狀目錄結構)
`DirectoryIndex index.html` #修改為:`DirectoryIndex index.html index.php`(設置默認首頁文件,增加index.php)
`:wq!` #保存退出
`systemctl restart httpd.service` #重啟apache
`rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html `#刪除默認測試頁
二、php配置
`vi /etc/php.ini`#編輯
`expose_php = Off` #禁止顯示php版本的信息
`short_open_tag = ON` #支持php短標簽
`:wq!` #保存退出
`systemctl restart mariadb.service` #重啟MariaDB
`systemctl restart httpd.service` #重啟apache
測試篇
`cd /var/www/html
`
`vi index.php` #輸入下面內容
`:wq!` #保存退出
在客戶端瀏覽器輸入服務器IP地址,可以看到相關的配置信息!
注意:apache默認的程序目錄是`/var/www/html
`
權限設置:`chown apache.apache -R /var/www/html
`
至此,CentOS 7.0安裝配置LAMP服務器(Apache+PHP+MariaDB)教程完成!