Set up a PHP server environment on CentOS

 
Install apache:
yum install httpd httpd-devel 
Start apache:
/etc/init.d/httpd start
At this point, enter the IP address of the server, and you should see the apache service page. You don't need to enter the port. Apache uses port 80 by default.
 
Install mysql:
yum install mysql mysql-server
Start mysql:
/etc/init.d/mysqld start
 
install php
yum install php php-devel
Restart apache to make php take effect
/etc/init.d/httpd restart
At this point, you can create a PHP file in the directory: /var/www/html/
Code:
<?php phpinfo(); ?>
Then visit this file, you can see some information about PHP, the path of the php.ini configuration file can be seen on this page
 
install php extension
yum  install   php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
After installing the extension, you need to restart apache again
/etc/init.d/httpd restart
 
PHP code to test whether mysql is successfully linked
<?php
$con = mysql_connect("10.0.@.@@","@@","@@");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("mydb", $con);
 
$result = mysql_query("SELECT * FROM sys_user");
 
while($row = mysql_fetch_array($result))
  {
  echo $row['UserName'] . " " . $row['PassWord'] . " " . $row['id'];
  echo "<br />";
  }
 
mysql_close($con);
?>
You can pass the above code into the directory /var/www/html/
to see the implementation

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326397807&siteId=291194637