Home >Operation and Maintenance >Linux Operation and Maintenance >How to build a PHP server environment in CentOS
This article mainly introduces how to build a PHP server environment on CentOS. It briefly describes the installation of Apache, mysql, php environment and related test codes on the CentOS platform. It is very simple and practical. Friends who need it can refer to it. I hope it can help everyone. .
1. Install apache first:
##
yum install httpdConfigure ServerName
vi /etc/httpd/conf/httpd.confChange
#ServerName www.example.com:80 to ServerName localhost:80
For the external machine, enter the IP of the server at this time For the address, you should see the apache service page. There is no need to enter the port. Apache uses port 80 by default. If it cannot be opened, port 80 may not be open for external access. Check:/etc/init.d/iptables statusWhether there is information such as 80 or so after it, if not, open it. Pay attention to the position and statement state. There are two horizontal bars in front of the report--:
vim /etc/sysconfig/iptablesJoin:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPTThen restart and save the firewall:
service iptables restart /etc/rc.d/init.d/iptables saveCheck again whether it is enabled:
/etc/init.d/iptables statusStart apache:
/etc/init.d/httpd start
2. Installation mysql:
##
yum install mysql mysql-server
/etc/init.d/mysqld start
##
yum install php php-develRestart apache to make php take effect
/etc/init.d/httpd restart
You can now Create a PHP file under directory:/var/www/html/
Code:
<?php phpinfo(); ?>
Then access this file, you can see some of PHP Information, the path to the php.ini configuration file can be seen on this page
Install the php extension
##Copy the code
The code is as follows:
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 restartPHP code to test whether mysql link is successful
<?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 status
Installation directory introduction
Apache points the root directory of the website to by default /var/www/html DirectoryThe default main configuration file is /etc/httpd/conf/httpd.conf
The configuration is stored in /etc/httpd/ conf.d/Directory
Related recommendations:
Use Nginx to build a PHP server
##
The above is the detailed content of How to build a PHP server environment in CentOS. For more information, please follow other related articles on the PHP Chinese website!