新聞中心
bash,sudo apt update,sudo apt install php,“在Linux下安裝PHP的步驟如下:

1、更新系統(tǒng)軟件包列表
“`
sudo aptget update
“`
2、安裝Apache Web服務器(如果尚未安裝)
“`
sudo aptget install apache2
“`
3、安裝MySQL數(shù)據(jù)庫(如果尚未安裝)
“`
sudo aptget install mysqlserver
“`
4、啟動Apache和MySQL服務
“`
sudo service apache2 start
sudo service mysql start
“`
5、下載PHP安裝包
訪問PHP官方網站(https://www.php.net/downloads.php)并選擇適合您的Linux發(fā)行版的PHP版本,復制下載鏈接。
6、使用wget命令下載PHP安裝包
“`
wget [下載鏈接]
“`
7、解壓下載的PHP安裝包
“`
tar xvf [下載的文件名]
“`
8、進入解壓后的PHP目錄
“`
cd [解壓后的目錄]
“`
9、配置PHP與Apache的集成
“`
sudo ./configure withapxs2=/usr/bin/apxs withmysqli=/usr/bin/mysql_config withopenssl withzlib enablezip enablembstring withcurl withgd withjpegdir=/usr withpngdir=/usr withfreetypedir=/usr withxmlrpc withxsl withmcrypt enablesoap enablecalendar enableexif enablesysvsem enableinlineoptimization withcurlwrappers enableintl enableopcache enablefpm withfpmuser=wwwdata withfpmgroup=wwwdata withpdo_mysql=mysqlnd withpdo_pgsql=pgsql withpdo_sqlite=sqlite3 withpdo_mysql=mysqlnd withpdo_pgsql=pgsql withpdo_sqlite=sqlite3
“`
10、編譯并安裝PHP
“`
sudo make && sudo make install
“`
11、復制Apache配置文件到適當?shù)奈恢?,并修改相關設置以啟用PHP模塊,可以使用以下命令進行復制和修改:
“`
sudo cp /etc/apache2/sitesavailable/default /etc/apache2/sitesavailable/mywebsite.conf
sudo nano /etc/apache2/sitesavailable/mywebsite.conf
“`
在標簽中添加以下行:
“`
DirectoryIndex index.php index.html index.htm index.nginxdebian.html index.nginxdebian.chunked index.nginxdebian.gz index.txt
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !f
RewriteRule ^ index.php [QSA,L]
“`
保存文件并退出編輯器,然后啟用新站點并重啟Apache服務:
“`
sudo a2ensite mywebsite && sudo service apache2 restart
“`
12、現(xiàn)在,您已經在Linux上成功安裝了PHP,可以通過創(chuàng)建一個PHP文件來測試它是否正常工作,創(chuàng)建一個名為info.php的文件,并在其中添加以下內容:
“`php
“`
將此文件放置在Apache的網站根目錄中,然后在瀏覽器中訪問該文件的URL,http://localhost/info.php,您應該能夠看到PHP的信息頁面,這表明PHP已成功安裝并正在運行。
當前標題:如何在linux下安裝php
文章源于:http://www.dlmjj.cn/article/djsijho.html


咨詢
建站咨詢
