Steps and methods for setting up the PHP server environment on CentOS

  • 2020-05-17 07:15:27
  • OfStack

This article illustrates the steps and methods of setting up an PHP server environment on CentOS. I will share it with you for your reference as follows:

Install apache:


yum install httpd httpd-devel

Start the apache:


/etc/init.d/httpd start

If you enter the IP address of the server, you should see the service page of apache. You do not need to input the port. By default, apache USES port 80

Install mysql:


yum install mysql mysql-server

Start the mysql:


/etc/init.d/mysqld start

Install php


yum install php php-devel

Restart apache to enable php


/etc/init.d/httpd restart

At this point you can create an PHP file under the directory: /var/www/html/

Code:


<?php phpinfo(); ?>

You can then access this file and see some information about PHP. The path to the php.ini configuration file can be seen on this page

Install the php extension

yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

You will need to restart apache again after installing the extension


/etc/init.d/httpd restart

Test whether mysql links to the php code successfully


<?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/

You can see the execution

PS: simple scaffolding methods can also be deployed using one-key tools such as EZHTTP. Interested friends can refer to the relevant documentation, not described here.

I hope this article has helped you with your CentOS server configuration.


Related articles: