How to build a PHP server environment in CentOS

小云云
Release: 2018-03-19 10:36:37
Original
6421 people have browsed it

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 httpd
Copy after login

Configure ServerName


vi /etc/httpd/conf/httpd.conf
Copy after login

Change

#ServerName www.example.com:80toServerName 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 status
Copy after login
Copy after login

Whether 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/iptables
Copy after login

Join:


-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 ACCEPT
Copy after login

Then restart and save the firewall:


service iptables restart /etc/rc.d/init.d/iptables save
Copy after login

Check again whether it is enabled:


/etc/init.d/iptables status
Copy after login
Copy after login

Start apache:


/etc/init.d/httpd start
Copy after login

2. Installation mysql:

##

yum install mysql mysql-server
Copy after login

Start mysql:

##
/etc/init.d/mysqld start
Copy after login


3 . Install php

##

yum install php php-devel
Copy after login

Restart apache to make php take effect


##
/etc/init.d/httpd restart
Copy after login

You can now Create a PHP file under directory:/var/www/html/

Code:

Copy after login

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 restart
Copy after login

PHP code to test whether mysql link is successful


"; } mysql_close($con); ?>
Copy after login

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 toby default /var/www/htmlDirectoryThe 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!