Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
Apache + PHP + MySQL: Create a database-driven dynamic website-Linux Enterprise Application-Linux server application information. For more information, see the following. Apache is the most widely used Web server. PHP is an easy-to-learn scripting language similar to ASP, and has better performance and functions than ASP, mySQL is the most widely used database system in Linux, especially for website construction. These three software are all free software and are the best database-driven dynamic websites. I. Required Software: Apache apache_1.3.12.tar.tgz (apache source code package) PHP php-3.0.13.tar.gz (PHP3 source code package) MySQL MySQL-3.23.24-1.sparch64.rpm (MySQL Server) MySQL-client-3.23.24-1.sparch64.rpm (MySQL client utility) MySQL-devel-3.23.24-1.sparch64.rpm (MySQL contains files and libraries) mySQL-shared-3.23.24-1.sparch64.rpm (client program Shared Library) 2. Install MySQL first check whether your system has installed MySQL: rpm-q MySQL-client rpm-q MySQL-devel rpm-q MySQL-shared if your version is earlier than 3.23.24 and you want to upgrade MySQ L to version 3.23.24, remove all MySQL packages with rpm-e and: rpm-I MySQL-3.23.24-1.sparch64.rpm rpm-I MySQL-client-3.23.24-1.sparch64.rpm rpm-I MySQL-devel-3.23.24-1.sparch64.rpm rpm-I MySQL-shared-3.23.24-1.sparch64.rpm rpm-I when installing the MySQL server, the installer will prompt you to set the root password. For more information about MySQL post-installation settings, see. The above installation puts the MySQL execution file under the "/usr/bin" directory, including the file under the "/usr/include/mysql" directory, the library files are stored in the "/usr/lib/mysql" directory. 3. Decompress apache and php, compile and install the apache and php source code packages, and add the downloaded files to the directory "/apps" to go to the "/apps" directory, use ls to check that you have these two files: apache_1.3.12.tar.gz php-3.0.13.tar.gz 1. Decompress apache and configure tar zxvf apache_1.3.12.tar.gz. It explains that the compressed files are stored in the apache_1.3.12 directory. Configure apache cd apache_1.3.12 (enter the directory of the apache source code tree ). /configure -- prefix =/www (if you want to install apache in the directory "/www") 2. Decompress php3 and configure and compile cd .. (back to the parent directory) tar zxvf php-3.0.13.tar.gz (extract to the directory "php-3.0.13") cd php-3.0.13 (enter the source code directory of php3 ). /configure -- with-mysql =/usr -- with-apache = .. /apache_1.3.12 make install 3. Compile and install apache cd... /configure -- prefix =/www -- activate-module = src/module/php3/libphp3.a make install (Install ache to the "/www" directory.) the above method is to compile php into the apache target code, so its efficiency and performance are slightly better than that of DSO. The method of using php as a module of apache is described later. 4. Configure apache cd/www (to the apache main directory) cd conf (to enter the configuration file directory) and edit "httpf. conf "file, put" AddType application/x-httpd-php3. remove the comments of a row in php3 ". files with the suffix php3 "are processed as php script files. 5. Start apache to turn off the running httpd (sometimes started at system startup) and restart the new httpd: cd/www/bin. /apachectl start run the ps aux command to check whether httpd has been started correctly. 6. Test and run startx, and then run netscape. in the address bar, enter: http://localhost If you can see the page, it means you have set and started httpd correctly. 7. Test php cd/www/htdocs to create an ex. php3 file. The content is as follows: Run the following command to check whether the output is "Hello, World" and the current php settings: Enter http: // localhost/ex in the address bar of netscape. if it is php3, your apache can already process php script files. Congratulations! 8. Test the MySQL database to create a mydb after installing MySQL according to the above method. dump file, including the following content: create table employees (id tinyint (4) DEFAULT '0' not null AUTO_INCREMENT, first varchar (20), last varchar (20 ), address varchar (255), position varchar (50), primary key (id), UNIQUE id (id); insert into employees VALUES (1, 'bob', 'Smith ', '2017 Here St, cityname', 'marketing manager'); insert into employees VALUES (2, 'john', 'ots', '45 There St, Wnville ', 'telephonist'); insert into employees VALUES (3, 'bra', 'johnson', '1/34 Nowhere Blvd, Snowston ', 'doorman '); use this SQL script to create a database mydb in MySQL, and run the following command in shell: mysql-u root-pyourpasswd mydb <mydb. dump here, if you have set the root user password after installing MySQL, replace yourpasswd with your password. If you have not set the password for root, remove the-p option. After the above database is created, create a php3 script file, such as test. php3. Its content is as follows: \ N ", mysql_result ($ result, 0," first "); printf (" Last Name: % s
\ N ", mysql_result ($ result, 0," last "); printf (" Address: % s
\ N ", mysql_result ($ result, 0," address "); printf (" Position: % s
\ N ", mysql_result ($ result, 0," position ");?>If the root user sets a password, add the password: $ db = mysql_connect ("localhost", "root"); to $ db = mysql_connect ("localhost", "root ", "yourpasswd"); then test. php3: Enter http: // localhost/test in the address bar of netscape. the result displayed by php3 is: First Name: BobLast Name: SmithAddress: 128 Here St, CitynamePosition: Marketing Manager. If yes, your php3 has been able to process the MySQL database, congratulations again !! 4. How to install and configure the RPM package is bundled with apache, php3, and MySQL in many Linux releases. because MySQL is distributed in RPM format, therefore, the installation has been described above. The following describes only the installation and configuration of apache and php. This article is based on RedHat Linux 6.2. PHP designers do not recommend configuring php3 from RPM, but it will solve this problem in php4. Since re-configuring from RPM and installing php are troublesome, the following methods are for reference only. 1. You need rpm files in order to reconfigure and compile php, you should download the source code rpm of php3: php-220.127.116.11.src.rpm. This package can generate the following rpm: php-3.0.12-6.sparch64.rpm php-manual-3.0.12-6.sparch64.rpm php-imap-3.0.12-6.sparch64.rpm php-ldap-3.0.12-6.sparch64.rpm before installing the new rpm, you should first Delete the already php package: rpm-e php-imap php-ldap php-pgsql php-manual to re-compile php requires the following software packages: apache-devel postgresql-devel MySQL-devel 2. reconfigure, compile, and install php3 to install the php3 source code package: rpm-I php-3.0.12-6.src.rpm it installs php source code in/usr/src/re Go to the dhat directory and run the following command to configure and compile the Directory: cd/usr/src/redhat/SPECS vi php. spec edit php. in the spec file, find the % build section. in the/configure option section, add the -- with-mysql =/usr \ option, which indicates that php supports the MySQL database. % Buildcd imap-4.5make RPM_OPT_FLAGS = "$ RPM_OPT_FLAGS" lnpcd .. autoconfCFLAGS = "-fPIC ". /configure -- prefix =/usr \ -- with-apxs =/usr/sbin/apxs \ -- with-config-file-path =/etc/httpd \ -- enable-safe-mode \ -- with-exec-dir =/usr/bin \ -- with-system-regex \ -- disable-debug \ -- with-zlib \ -- enable-debugger \ -- enable-magic- quotes \ -- with-mysql =/usr \ -- enable-track-vars save changes, re-create rpm package: rpm-bb/usr/src/redhat/ SPECS/php. spec, find the corresponding binary rpm packages in the/usr/src/redhat/RPMS/sparch64 directory and reinstall them: rpm-I/usr/src/redhat/RPMS/sparch64/* 3. Configure httpd. conf and srm. after installing php, configure httpd to support php3 scripts. First, edit/etc/httpd/conf/httpd. conf to find out the following two lines and remove the annotator #: AddModule mod_php3.c LoadModule php3_module modules/libphp3.so in compiling/etc/httpd/conf/srm. conf, remove the annotation #: AddType application/x-httpd-php3. in this case, httpd. the file ending with php3 is considered a php script file. 4. You can use the following example for testing. The above only introduces the installation of these three software, you must configure the Security Settings of php and MySQL.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
and provide relevant evidence. A staff member will contact you within 5 working days.