Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build and test the connection between php and mysql in CentOS LAMP environment

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to build and test the connection between php and mysql in the CentOS LAMP environment". In the daily operation, I believe many people have doubts about how to build and test the connection between php and mysql in the CentOS LAMP environment. I have consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how to build and test the connection between php and mysql in the CentOS LAMP environment". Next, please follow the editor to study!

In particular, it is worth mentioning that CentOS LAMP has a lot to learn. Here we mainly introduce the construction of CentOS LAMP environment, including CentOS LAMP configuration and so on. RHEL 5 / CentOS 5 is installed on the system.

As a server, CentOS LAMP does not install unwanted components, so when selecting components, do not choose web server, because we will compile and install manually later. CentOS LAMP system prescribes the location of RPM package and source package:

RPM package and source code package location / usr/local/src source package compilation installation location (prefix) / usr/local/XXX MySQL database location / usr/local/mysql/var website root directory / usr/local/apache/htdocs

CentOS LAMP environment building

The construction work includes APACHE, MYSQL and PHP. The environment can be built in this order.

1. Get the software package

Httpd: http://www.apache.org/dist/httpd/httpd-2.2.11.tar.gz mysql: http://mirror.provenscaling.com/mysql/enterprise/source/5.0/mysql-5.0.70.tar.gz php: http://museum.php.net/php5/php-5.2.2.tar.gz

Put them all under / usr/local/src. > cd / usr/local/src (navigate to the installation package directory)

2. Install mysql

> tar-zxvf mysql-5.0.70.tar.gz > cd mysql-5.0.70 >. / configure-- prefix=/usr/local/mysql > make > make install > useradd mysql / / add mysql users > cd / usr/local/mysql > bin/mysql_install_db-- user=mysql > chown-R mysql. / / set permissions, notice that there is a dot "." > chgrp-R mysql. > chown-R mysql var > cp share/mysql/my-medium.cnf / etc/my.cnf > cp share/mysql/mysql.server / etc/rc.d/init.d/mysqld / / boot > chmod 755 / etc/rc.d/init.d/mysqld > chkconfig-- add mysqld

Run the following command to start the MySQL server: > / etc/rc.d/init.d/mysqld start / / start MySQL (mysql installation is complete)

3. Install Apache

> tar-zxvf httpd-2.2.11.tar.gz > cd httpd-2.2.11 >. / configure-- prefix=/usr/local/apache-- enable-module=so-- enable-module=rewrite-- enable-shared=max > make > make install

Start the apache service > / usr/local/apache/bin/apachectl-k start to open http://127.0.0.1/ with a browser. If you can access it, the apache installation is successful.

4. Install PHP

> tar-zxvf php-5.2.2.tar.gz

> cd php-5.2.2

>. / configure-prefix=/usr/local/php-with-mysql=/usr/local/mysql-with-apxs2=/usr/local/apache/bin/apxs

> make

> make install

> cp php.ini-dist / usr/local/php/lib/php.ini

> vi / usr/local/php/lib/php.ini

5. CentOS LAMP configure httpd

.conf > vi / usr/local/apache/conf/httpd.conf find "AddType application/x-gzip .tgz" add AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phps below it find "DirectoryIndex index.html add index.php before index.html"

Start the apache service > / usr/local/apache/bin/apachectl-k start set apache to boot: add a line in the / etc/rc.d/rc.local file and save: / usr/local/apache/bin/apachectl start (apache+php is configured)

6. Check and confirm the L.A.M.P environment information: > vi / usr/local/apache/htdocs/phpinfo.php add the following line and save it. > chmod 755 / usr/local/apache/htdocs/phpinfo.php Open http://127.0.0.1/phpinfo.php with a browser to check whether the information in phpinfo is correct. If it can be accessed, the environment is built successfully.

Test the connection between php and mysql

> vi / usr/local/apache/htdocs/testdb.php add the following lines and save them. > chmod 755 / usr/local/apache/htdocs/testdb.php > service mysqld start

Open http://127.0.0.1/testdb.php with a browser if the output success indicates a successful connection between php and mysql, the CentOS LAMP environment has been built.

At this point, the study on "how to build and test the connection between php and mysql in CentOS LAMP environment" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report