1.安裝apache:
yum install httpd httpd-devel
啟動apache:
/bin/systemctl start httpd.service
此時在瀏覽器地址欄輸入服務(wù)器的IP地址,應(yīng)該看到apache的服務(wù)頁面,端口不用輸,apache默認就是使用80端口,如果端口改變了就要輸。
有可能訪問不了 你需要將Centos 7 中的
防火墻關(guān)閉:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啟動
firewall-cmd --state #查看默認防火墻狀態(tài)(關(guān)閉后顯示notrunning,開啟后顯示running)
2.安裝mysql:
yum install mysql mysql-server
啟動mysql:
systemctl start mysql.service
要啟動MySQL數(shù)據(jù)庫是卻是這樣的提示
Failed to start mysqld.service: Unit not found
解決方法如下:
首先需要安裝mariadb-server
yum install -y mariadb-server
啟動服務(wù)
systemctl start mariadb.service
添加到開機啟動
systemctl enable mariadb.service
至此完成!
可以測試一下
mysql -u root -p
3.安裝php
yum install php php-devel
重啟apache使php生效
/bin/systemctl start httpd.service
此時可以在目錄:/var/www/html/下建立一個PHP文件index.php,加入代碼:
<?php phpinfo(); ?>
然后在瀏覽器訪問這個文件,就能看到PHP的一些信息,php.ini配置文件的路徑可以在這個頁面上看到
如若安裝PHP7版本請看下面的操作
在centos7通過yum安裝PHP7,首先在終端運行:
rpm -Uvh htt[ps](http://www.111cn.net/fw/photo.html)://mirror.webtatic.com/yum/el7/webtatic-release.rpm
提示錯誤:
error: Failed dependencies:
epel-release >= 7 is needed by webtatic-release-7-3.noarch
需要先安裝epel-release。
1.安裝epel-release
通過命令:
rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
成功安裝。
2.安裝PHP7
終端再次運行如下命令:
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
成功獲取PHP7的yum源,然后再執(zhí)行:
yum install php70w
這樣就大功告成了。
3.驗證安裝
終端命令:php -v,顯示當前PHP版本,信息如下:
[root@iZ94w0kemvtZ /]# php -v
PHP 7.0.2 (cli) (built: Jan 9 2016 14:00:11) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
這樣就在CentOS 7下通過yum安裝成功PHP7.
安裝php的擴展
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
安裝完擴展之后需要再次重啟apache
/bin/systemctl start httpd.service