linuxÔõô´î½¨phpÇéÐÎ
ÔÚ linux Éϴ php ÇéÐÎÉæ¼°ÒÔÏ°취£º×°Öà apache web ЧÀÍÆ÷×°Öà mysql Êý¾Ý¿â×°Öà php ¼°Ä£¿é½¨Éè php ÎļþÅþÁ¬µ½ mysql Êý¾Ý¿âÖ´ÐÐ sql ÅÌÎÊ
ÔõÑùÔÚ Linux Éϴ PHP ÇéÐÎ
ÔÚ Linux Éϴ PHP ÇéÐÎÏà¶Ô¼òÆÓ£¬ÐèÒªÒÔÏ°취£º
1. ×°Öà Apache Web ЧÀÍÆ÷
sudo apt-get install apache2
µÇ¼ºó¸´ÖÆ
2. ×°Öà MySQL Êý¾Ý¿â
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
sudo apt-get install mysql-server
µÇ¼ºó¸´ÖÆ
3. ×°ÖÃ PHP
sudo apt-get install php libapache2-mod-php php-mysql
µÇ¼ºó¸´ÖÆ
4. ÆôÓà PHP Ä£¿é
sudo a2enmod php7.4
µÇ¼ºó¸´ÖÆ
5. ÖØÆô Apache
sudo systemctl restart apache2
µÇ¼ºó¸´ÖÆ
6. ½¨ÉèÒ»¸ö PHP Îļþ
ÔÚ /var/www/html Ŀ¼Öн¨ÉèÃûΪ info.php µÄÎļþ£º
<?php phpinfo(); ?>
µÇ¼ºó¸´ÖÆ
7. »á¼û PHP Îļþ
ÔÚä¯ÀÀÆ÷Öлá¼û http://localhost/info.php£¬ÄúÓ¦¸Ã»á¿´µ½ PHP µÄÐÅÏ¢Ò³Ã棬Åú×¢ PHP ÒÑÀÖ³ÉÉèÖá£
8. ÅþÁ¬µ½Êý¾Ý¿â
ÔÚ info.php ÎļþÖÐÌí¼ÓÒÔÏ´úÂëÒÔÅþÁ¬µ½ MySQL Êý¾Ý¿â£º
$servername = "localhost"; $username = "root"; $password = "your_password"; $dbname = "your_database"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); }
µÇ¼ºó¸´ÖÆ
9. Ö´ÐÐ SQL ÅÌÎÊ
$sql = "SELECT * FROM table_name"; $result = $conn->query($sql); if ($result->num_rows > 0) { // Output data of each row while($row = $result->fetch_assoc()) { echo "id: " . $row["id"] . " - Name: " . $row["name"] . "<br>"; } } else { echo "0 results"; }
µÇ¼ºó¸´ÖÆ
ÏÖÔÚ£¬ÄúÒѾÀÖ³ÉÔÚ Linux ÉϴÁËÒ»¸ö¹¦Ð§ÆëÈ«µÄ PHP ÇéÐΡ£
ÒÔÉϾÍÊÇlinuxÔõô´î½¨phpÇéÐεÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡