Apache + mysql + phpforlinux _ MySQL

Source: Internet
Author: User
Tags ip number
Apache + mysql + phpforlinux

Download MySQL, php, and apache
Which kits are required for setting up such a host? Not Apache, MySQL, or PHP!


Apache: Apache version 2.0.X has been released, but 1.3.X is the most widely used version. Apache version 1.3.20 is the latest version, you can go to the Apache Main page to view the relevant information:
Apache homepage (English ):
Apache kit (downloaded from the home page ):
PHP: you can go to the main php webpage to check out some of the related topics!
PHP homepage (English ):
PHP homepage download:
MySQL: The latest version is 3.23.41. Similarly, you can go to the MySQL official webpage to check it out!
MySQL homepage (English ):
Download the MySQL homepage:
That is to say, we need three files:
Apache-1.3.20.tar.gz
Php-4.0.6.tar.gz
Mysql-3.23.41.tar.gz

Install MySQL, php, and apache
You need to be careful when installing these three kits, because you may not be able to get the latest version of the kit using RPM upgrade, so here we use the original code upgrade method. The installation method is as follows:
Remove the old Doon and decompress:
Remove the old version of related data. if you are RedHat 6.1, you can remove the following kits first!

[Root @ tsai/root] # rpm-e mod_perl
[Root @ tsai/root] # rpm-e phpfi
[Root @ tsai/root] # rpm-e apache
Of course, if you have installed earlier versions of Apache, PHP, or MySQL, you can also remove them. In fact, this is my habit. some people like to save two versions in their systems. if you want to install the two versions in your system, then you do not need to remove the rpm installation kit! However, to avoid system conflicts, you must use the setup program to cancel httpd, php, and mysql services!
Decompress:
If you store Apache, MySQL, and PHP files in the/home/test directory and decompress the data to/usr/local, run the following command:

[Root @ tsai/root] # cd/usr/local
[Root @ tsai local] # tar-zxvf/home/test/apache_1.3.20.tar.gz
[Root @ tsai local] # tar-zxvf/home/test/mysql-3.23.41.tar.gz
[Root @ tsai local] # tar-zxvf/home/test/tar-zxvf/test/php-4.0.6.tar.gz
In/usr/local there will be three more directories, respectively: apache_1.3.20, mysql-3.23.41, php-4.0.6.
Install MySQL kit:
If your English is good enough, you can go to the/usr/local/mysql-3.23.41 directory to check the INSTALL-SOURCE file, which provides detailed instructions on how to INSTALL MySQL that suits you. If you want to follow my steps, please take a look!

[Root @ tsai/root] # cd/usr/local/mysql-3.23.41
[Root@tsaimysql-3.23.41] #./configure -- prefix =/usr/local/mysql -- localstatedir =/usr/local/mysql/var
The above step is checking your system to set the information that suits your system!
Here, -- prefix is followed by the MySQL directory to be installed, and -- localstatedir
The next part is where you want to place the database, which is usually set in var.
[Root @ tsai mysql-3.23.41] # make
[Root @ tsai mysql-3.23.41] # make install
Install mysql in the above two steps to the/usr/local/mysql path you just set.
Note: the above steps can take a long time based on your CPU!
[Root @ tsai mysql-3.23.41] #./scripts/mysql_install_db
If you have already installed MySQL, you do not need to install it in this step,
This step is generating the grant tables! That's the database!
This step is very important. without this step, your MySQL will not act!
[Root @ tsai mysql] # adduser mysql
[Root @ tsai mysql] # chown-R mysql: mysql/usr/local/mysql
The above step generates the mysql account and group name. In addition,
Specify/usr/local/mysql as all mysql instances,
This is for security consideration, because the mysql account is different from your original linux account!
[Root @ tsai mysql] # cd/usr/local/mysql/share/mysql
[Root @ tsai mysql] # chmod 777 mysql. server
In the preceding step, activate your mysql. server as the mysql execution file,
Set the format that can be used by everyone.
[Root @ tsai mysql] #/usr/local/mysql/bin/safe_mysqld -- user = mysql &
The above line uses the mysql User to activate mysql services!
[Root @ tsai mysql] #/usr/local/mysql/bin/mysqladmin-u root password abcde
The above line sets the root mysql password, where abcde is the password, you can set it yourself!
The above installation is complete! Test your MySQL after installation!
Added the PHP module:
Basically, PHP can be regarded as a module of Apache. because it is a module of apache, we must first perform a configure detection for Apache, to add php to apache, follow these steps:

[Root @ tsai/root] # cd/usr/local/apache_1.3.20
[Root @ tsai apache_1.3.20] #./configure -- prefix =/usr/local/apache
The preceding command is to install apache on/usr/local/apache,
Please note that you must first detect apache settings before installing php!
[Root @ tsai apache_1.3.20] # cd/usr/local/php-4.0.6
[Root @ tsai php-4.0.6] #./configure -- with-apache =/usr/local/apache_1.3.20
> -- With-mysql =/usr/local/mysql
> -- Enable-track-vars
Please note that the preceding command must be followed by a symbol after the three lines in the middle. this is what the command continues to mean,
That is to say, in fact, the last four lines above are considered as commands of the same line! You can also write the preceding commands into a long string
In addition, it should be noted that apache needs to point to the directory that has just been detected, while mysql points
Directory already installed! Never make a mistake!
[Root @ tsai php-4.0.6] # make
[Root @ tsai php-4.0.6] # make install
Start Installation! After the installation is complete, it will be in/usr/local/apache_1.3.20/src/modules
One more sub-directory of php4 contains the main link library of php4!
[Root @ tsai php-4.0.6] # cp/usr/local/php-4.0.6/php. ini-dist/usr/local/lib/php. ini
Copy the main php configuration file php. ini-dist to the file/usr/local/lib/php. ini,
This is because apache or other programs need to use this file in usr/local/lib/when executing php,
If you are familiar with php, you can modify the file/usr/local/lib/php. ini to conform to your settings.
In this way, the php suite is installed!
Install Apache:
Now we are the first to start installing apache! Because php has been installed, the php4 directory exists in/usr/local/apache_1.3.20/src/modules!

[Root @ tsai/root] # cd/usr/local/apache_1.3.20
[Root @ tsai apache_1.3.20] #./configure -- prefix =/usr/local/apache
> -- Activate-module = src/modules/php4/libphp4.a
The above two rows are the same line. Note that the -- activate-module line is required first.
This module can be used only after php is installed!
[Root @ tsai apache_1.3.20] # make; make install
This completes the installation! Let's start setting up the test-related WWW module!

Simple apache configuration
To activate Apache, only the file "httpd. conf" is left in this version (1.3.20. If you are using RedHat6.1, the original apache has three files:
Httpd. conf
Access. conf
Srm. conf
The following sections describe apache_1.3.20. if you are installing apache in the old version, find the relevant settings in the other two files!
Main Directory types of Apache:
This is quite important, because different versions of Redhat and different installation methods will produce very different directory types. the following uses Redhat6.1, RedHat7.0 + CLE0.9, and use the original code to install the directory type 1.3.20:
Redhat 6.1: if the original apache 1.3.9 is used, your parameter configuration file will be in/etc/httpd/conf, the web pages of the host are stored in/home/httpd/html, while those of cgi are stored in/home/httpd/cgi-bin;
RedHat7.0 + CLE 0.9: Similarly, the default apache parameter file of this system is stored in/etc/httpd/conf, but the host webpage is moved to/var/www/html, cgi-bin is stored in/var/www/cgi-bin;
Original code installation: if the original code is used for installation and the preset path is set to/usr/local/apache, your parameter configuration file will be in/usr/local/apache/conf, and the more dynamic is the directory where the host web page is placed, change to the directory/usr/local/apache/htdocs. cgi is also placed in/usr/local/apache/cgi-bin.
The following section describes apache settings based on the files generated by the installation method of the original code.
Basic settings:
1. activate apache service: basically, after you activate apache, you should be able to see the preset web page of your host in the browser program of the client! Activation method:
[Root @ tsai/root] #/usr/local/apache/bin/apachectl start <= activated
Apachectl also has the following parameters:
Apachectl stop: stop WWW service;
Apachectl restart: re-activates the WWW service. This command is usually used for re-activation after you modify apache parameters.
Apachectl status: detects the status of WWW.
2. change the Chinese homepage: Because your homepage name is index.html or index.htm in the original settings of WWW, this edition of homepage supports many languages, therefore, you must modify the name of the home page File:

[Root @ tsai/root] # cd/usr/local/apache/htdocs/
In setting your homepage, you can write index.html in win98and upload it to the directory on linux. now you can connect it to other client machines! You can now open IE or other browsers and enter your DNS name (if any) or your IP number on your website, you can see the home page of your host!
3. set user permissions: because you have installed Apache as the root user, if you cannot connect to your host homepage, it may be caused by permission issues where the WWW homepage is placed, you can set the permissions in the/usr/local/apache/htdocs and/usr/local/apache/cgi-bin directories:

[Root @ tsai apache] # chmod 755/usr/local/apache/cgi-bin
[Root @ tsai apache] # chmod 755/usr/local/apache/htdocs
You can also set the permission to 744!
4. set automatic execution: In addition, in order to enable your WWW and MySQL services to be executed on the machine, you can write the following two lines of activated scripts in your/etc/rc. d/rc. local:

[Root @ tsai/root] # vi/etc/rc. d/rc. local
/Usr/local/apache/bin/apachectl start
/Usr/local/mysql/share/mysql. server start
In this way, every time you boot, linux will automatically execute apache and MySQL!
Start to set the httpd. conf file:
After talking about some miscellaneous, I finally want to set the httpd. conf file. edit it with vi.

[Root @ tsai/root] # cd/usr/local/apache/conf
[Root @ tsai conf] # vi httpd. conf
1. basic environment settings: the following options in httpd. conf indicate:

ServerType standalone
In the preceding settings, the status of apache activation is set. if standalone is used, it is executed immediately upon startup,
Usually we choose standalone (default). However, if you select:
ServerType inetd: indicates that it is activated only when the Internet service is used online!
ServerRoot "/usr/local/apache"
Indicates the location of the apache Directory.
Timeout 300
This is used to set the client to connect to your host. when the client has not been connected for more than 300 seconds
When connecting your host, it will be disconnected!
MinSpareServers 5 <= if it is a small website or a small personal website, you can change it to 3
MaxSpareServers 10 <= if it is a small site or a small personal website, you can change it to 5
StartServers 5
MaxClients 150 <= if it is a small website or a small personal website, you can change it to 100
The above two are the places where the httpd service count is enabled. after you execute httpd,
Run ps-aux | grep httpd in shell to view the number of httpd,
This is usually related to your RAM. if it is a small site, you can set a smaller value,
For example, you can set the minimum value to 3 and the maximum value to 5! StartServers is set to be the same as Min!
MaxClients can be set to a smaller value, because it is too large to consume system resources,
Too small to connect many people! So it can be set to 100 for example.
Port 80
This is not necessary because the preset port of the www service is 80,
Unless you want to establish a website (internal website) that cannot be connected by others ),
User nobody
Group nobody
Set apache to the "nobody" person and group! Meaning that all users can use
ServerAdmin frank@mail.uc88.domain
Set the httpd administrator account for your machine! Set it to your account!
ServerName http://www.uc88.domain/
This is the name of your host. remove the preceding annotation!
Set it. if you do not have a host name, select localhost!
BindAddress *
This is a project used to allow your WWW to accept virtual IP addresses. for example, your virtual domain is
192.168.1.0, you can change * to 192.168.1.0! Generally, if you want to accept a virtual IP address,
Just Hit!
2. path setting: The following parameters are used to set the path of each webpage or service! (The old version is in access. conf)

DocumentRoot "/usr/local/apache/htdocs"
The above is where the main homepage of your host is located. because we set the host name
For: http://www.uc88.domain/, when someone else in the URL column into the http://www.uc88.domain,
The system will transfer the homepage file under the path/usr/local/apache/htdocs!
You can also change this path on your own!

Options Indexes ExecCGI FollowSymLinks MultiViews
AllowOverride None
Order allow, deny
Allow from all

The above shows what can be done by WWW under the Directory placed on the master webpage of the host!
Options is a work that can be performed on a Web page. you can check the items below:
ExecCGI: indicates that CGI programs can be executed in this directory;
FollowSymLinks: indicates that it can be connected to another place;
MultiViews: Allows you to execute animation, music, and other projects.
AllowOverride None indicates that anyone can read data;
As for Allow from all, your host accepts connections from any location.

UserDir public_html

This option needs to be enabled so that your user account can have a homepage!
The homepage of your user is placed under/home/user/public_html.
If public_html is changed to WWW, the user's homepage needs to be placed
/Home/user/www. if the preceding settings are met, take me as an example.
/Home/frank/public_html!

DirectoryIndex index.html index.htm index. php

This is used to describe the file name of the homepage. the default value is index.html, but some
The file name in the webpage editor is index.htm, so you can add the following file names,
In this way, your homepage supports multiple file names!
Basically, you can use the default value!
3. enable PHP and other modules: because we need to support apache of the php module, we need to enable this module!

AddType application/x-httpd-php. php
AddType application/x-httpd-php-source. phps
Cancel the comments of the two modules. Please note that this is the php4 module and should not be mixed with the php3 module!
Because we have installed php4!
AddHandler cgi-script. cgi
The above line of comments can also be removed so that the client can use the CGI program!
4. enable the Apache status column: You can view the apache execution status of the host using IE and other browsers. if you need this service, cancel the following annotations:


SetHandler server-status
Order deny, allow
Deny from all
Allow from. your_domain.com


SetHandler server-info
Order deny, allow
Deny from all
Allow from. your_domain.com

Change. your_domain.com to your DNS,
For example, I can change it to. uc88.domain! In this way,
Only the uc88.domain machine can see the execution status of your apache!
For example, if you enter
Http://www.uc88.doamin/server-status
Http://www.uc88.domain/server-info
Then the user from uc88.domain can see my host status!
5. reactivate: you only need to issue/usr/local/apache/bin/apachectl restart to execute httpd! Now the settings are complete. execute your IE to connect to your network! (If you have any questions, activate linux again !)

Test MySQL and PHP suites
Before testing these two suites, make sure that MySQL and Apache are activated! OK. Let's test it!
Php testing:
You can edit an Archive named test. php and place the archive in/usr/local/apache/htdocs (that is, the website location of your host !)

[Root @ tsai/root] # vi/usr/local/apache/htdocs/test. php
Phpinfo ();
?>
Then connect to your host, take me as an example, I will enter the http://www.uc88.domain/test.php so that you can see your php status Hello! That is, you can execute php!
MySQL test:
Similarly, MySQL also edits an archive. you can run the following command to check whether the archive can be edited:

[Root @ tsai/root] # vi/usr/local/apache/htdocs/mysqltest.html


$ Link = mysql_connect ('localhost', 'root ');
Mysql_select_db ('mysql ');
$ Str = "select * from user ;";
$ Result = mysql_query ($ str, $ link );
$ Show = mysql_num_rows ($ result );
Mysql_close ($ link );
For ($ I = 0; $ I <$ show; $ I ++)
{
$ Arr [$ I] = mysql_fetch_array ($ result );
};
?>
















Write the first personal homepage
If your website supports placing personal webpages for users, where are your personal webpages? We just mentioned in httpd. in the conf setting, there is a setting for the personal homepage. if you do not set httpd. the default value of the conf file is public_html. well, how can I set my webpage? Assume that the account frank is used as an example. we can do this:

[Frank @ frank] $ mkdir public_html
[Frank @ frank] $ chmod 755 public_html
[Frank @ frank] $ chmod 755/home/frank
Create a public_html directory in your client's home directory,
Change the permission of this directory to allow others to watch it. Note that apache
The default value is public_html, but if you are in the httpd. conf file
Modify the directory name!
Then, in your Directory, that is,/home/frank/public_html, create an HTML file named index.html, such as the php file we just tested, then, enter http: // your website name/~ In The ie url column /~ Frank/apache automatically uploads the IE message to the/home/frank/public_html directory and searches for the file name index.html, index.htm, or index. php! So index.html is the first file name for apache! This is your homepage!
Then you can write your webpage information through php and place it in the public_html directory! However, when writing a webpage using this method, note that the file with the file name php3 will not be executed, so it is appropriate to change php3 to php!

That's it.
[Root @ tsai/root] # cd/usr/local
[Root @ tsai local] # tar-zxvf/home/test/apache_1.3.20.tar.gz
[Root @ tsai local] # tar-zxvf/home/test/mysql-3.23.41.tar.gz
[Root @ tsai local] # tar-zxvf/home/test/tar-zxvf/test/php-4.0.6.tar.gz (this saw no ?)
In/usr/local there will be three more directories, respectively: apache_1.3.20, mysql-3.23.41, php-4.0.6.
This should be the case.
[Root @ tsai local] # tar-zxvf/home/test/php-4.0.6.tar.gz

Then the same execution http://www.uc88.domain/mysqltest.html can know whether your mysql can be executed!
Host User Password

Contact Us

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.