Linux環境下的PHP環境的安裝及配置—-LAMP
阿新 • • 發佈:2019-01-02
在聯網環境下,切換到root使用者下安裝
一、安裝Apache(httpd)
service httpd start
service httpd stop
service httpd restart
service httpd status
若啟動服務時,提示
httpd:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
編輯httpd.conf的配置檔案
Vi /etc/httpd/conf/httpd.conf
找到如下內容:
#ServerName www.example.com:80
更改為
ServerName localhost:80
3、 啟動服務,在瀏覽器中輸入localhost:埠號(預設80),如果如下圖顯示,則安裝成功
二、安裝mysql資料庫
1、安裝之前,先檢視linux伺服器內建的mysql
rpm -qa | grep mysql //檢視是否已安裝mysql資料庫
若有先將其解除安裝
rpm -e mysql // 普通解除安裝模式
rpm -e --nodeps mysql //強制解除安裝模式
MySQL資料庫,新版本已經更名為Mariadb(將命令中的mysql替換即可)
2、通過原始碼預編譯安裝
yum install -y mysql
3、啟動/停止/重啟服務/檢視狀態
service mysqld start
service mysqld stop
service mysqld restart
service mysqld status
4、若開啟服務時提示:mysql: unrecognized service,
是因為沒有安裝mysql-server
解決:在終端下輸入 yum install mysql-server
安裝,隨後重啟mysql服務
5、連線mysql資料庫,即可進入mysql,如下圖
mysql –uroot –p
預設無密碼
三、安裝PHP
1、通過原始碼預編譯安裝
yum -y install php
使用下面的命令安裝php對mysql的支援:
yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
2、重啟mysqld和httpd服務:
service mysqld restart
service mysqld restart
四、進行環境測試
1、檢視httpd配置檔案可知預設專案路徑如下:
/var/www/html
2、在web目錄下新建sex.php檔案,並編輯儲存
3、在瀏覽器中輸入 localhost:80/sex.php,執行結果證明環境安裝成功