Centos5.6 install php mysql apache

Source: Internet
Author: User
Tags gpg php mysql apache log password protection

Http://blog.csdn.net/doudou8486/article/details/6448928

 

1. Update the system kernel to the latest version.
[Root @ linuxfei ~] # Yum-y update
After the system is updated, if an error message is prompted during Yum installation, run the following command to fix the problem.
[Root @ linuxfei ~] # Rpm-import/etc/pki/rpm-GPG/RPM-GPG-KEY *
2. Install apahce, PHP, MySQL, and PHP to connect to the MySQL library component.
Y [root @ linuxfei ~] # Um-y install httpd PHP MySQL mysql-server PHP-MySQL
// Install MySQL extension
[Root @ linuxfei ~] # Yum-y install mysql-connector-ODBC mysql-devel libdbi-DBD-MySQL
// Install PHP Extension
[Root @ linuxfei ~] # Yum-y install PHP-Gd PHP-xml php-mbstring PHP-ldap php-pear PHP-XMLRPC
// Install Apache Extension
[Root @ linuxfei ~] # Yum-y install httpd-manual mod_ssl mod_perl mod_auth_mysql
One-time paste installation:
[Root @ linuxfei ~] # Yum-y install httpd PHP MySQL mysql-server PHP-mysql httpd-manual mod_ssl mod_perl mod_auth_mysql PHP-mcrypt PHP-Gd PHP-xml php-mbstring PHP-ldap php-pear PHP- XMLRPC mysql-connector-ODBC mysql-devel libdbi-DBD-MySQL

3. Start service configuration
[Root @ linuxfei ~] #/Sbin/chkconfig httpd on [set Apache to self-start]
[Root @ linuxfei ~] #/Sbin/chkconfig -- add mysqld [MySQL Service]
[Root @ linuxfei ~] #/Sbin/chkconfig mysqld on [mysqld service]
[Root @ linuxfei ~] #/Sbin/service httpd start [self-starting HTTPd service]
[Root @ linuxfei ~] #/Sbin/service mysqld start [self-starting mysqld service]
4. Set the password of the root account of the MySQL database.
[Root @ linuxfei ~] # Mysqladmin-u Root Password 'linuxfei' [enter the password in quotation marks]
[Root @ linuxfei ~] # Mysql-u root-P login log on with a blank password as root
Enter Password: linuxfei login enter the password here

Welcome to the MySQL monitor. Commands end with; or/g. login confirm that you can log on with the password
Your MySQL connection id is 5 to server version: 4.1.20

Type 'help; 'or'/H' for help. type'/C' to clear the buffer.

Mysql>

 

 

 


Image 1
Image 1

 

5. Install phpmyadmin
[Root @ linuxfei/] # wget http://gd2.down.chinaz.com: 808/data management/phpMyAdmin-3.tar.gz
-- 2010-03-23 16:38:18 -- http://gd2.down.chinaz.com: 808/% CA % FD % BE % DD % B9 % DC % C0 % ED/phpMyAdmin-3.x.tar.gz
Resolving gd2.down.chinaz.com... 121.11.80.154
Connecting to gd2.down.chinaz.com | 121.11.80.154 |: 808... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4700100 (4.5 M) [application/x-gzip]
Saving to: 'phpMyAdmin-3.x.tar.gz'

100% [============================================== >] 4,700,100 134 K/s in 37 s

16:38:56 (123 KB/s)-'phpMyAdmin-3.x.tar.gz 'saved [4700100/4700100]

Decompress phpmyadmin

[Root @ centos5/] # tar zxvf phpMyAdmin-3.x.tar.gz

[Root @ linuxfei/] # Music phpMyAdmin-3.3.1-all-languages/var/www/html/phpmyadmin

Move the extracted directory to the/var/www directory and change it to phpmyadmin.

Rename config. sample. inc. php under the phpmyadmin root directory to config. inc. php.

Open and edit config. inc. php

$ Cfg ['blowfish _ secret '] = '';/* You must enter the short password or an error will occur */

Find the following two rows and remove //

// $ Cfg ['servers'] [$ I] ['controluser'] = 'pma'; mysql Username
// $ Cfg ['servers'] [$ I] ['controlpass'] = 'pmapass' mysql password


Apache configuration

/Etc/httpd/conf/httpd. conf
The most important configuration file. However, many other distribution files are split into several small files to manage different parameters respectively. However, the main configuration file is based on the file name.
/Etc/httpd/conf. d/*. conf
This is one of the characteristics of CentOS, if you do not want to modify the original configuration file httpd. conf, you can separate your own extra parameters. When apache is started, this file will be read into the main configuration file.
/Usr/lib/httpd/modules
Apache supports many modules, so the modules you want to use are stored in this directory by default.
/Var/www/html
Here is the directory where the default "Homepage" of CentOS is located.
/Var/www/error
If the error message is displayed in the browser due to a host setting error or a data error requested by the browser, the default information of this directory is used.
/Var/www/icons
Some small icons of apache are provided.
/Var/www/cgi-bin
Default directory for some executable CGI programs
/Var/log/httpd
By default, apache log files are stored here. This directory should be very careful for websites with high traffic, because this file is easy to become large and you need enough space.
/Usr/sbin/apachectl
This is the main execution file of Apache. The execution file is actually a shell script, which can actively detect some settings on the system to make it easier to start Apache.
/Usr/sbin/httpd
This is the main apache binary file.
/Usr/bin/htpasswd
To log on to some web pages, you must enter your account and password. Apache itself provides the most basic password protection method. This command is used to generate the password.

For MySQL, You Need To Know several important directories and files as follows:
/Etc/my. cnf: This is the Mysql configuration file, which can be used to optimize the mysql database or specify some additional parameters for mysql.
/Usr/lib/mysql: the directory where the MySQL database is stored. When starting any MySQL server, remember to back up the directory completely during Backup.

In addition, you should know the following files in PHP.
/Usr/lib/httpd/modules/libphp4.so: the module provided by PHP for apache. Can we design the most important php program language file on the apache webpage?
/Etc/httpd/conf. d/php. conf: Do you want to manually write this module into Httpd. conf? No, because the system has actively written the php setting parameters to this file, and this file will be read when apache restarts.
/Etc/php. ini: This is the main configuration file of PHP, including whether PHP can allow users to upload files and some low-security labels, which are all set in this configuration file.
/Etc/php. d/mysql. ini/usr/lib/php4/mysql. so: Can PHP support the MySQL interface. These two files are provided by the php-mysql software.
/Usr/bin/phpize/usr/include/php: If you want to install a PHP accelerator later to speed up browsing, this file and directory will need to exist, otherwise, the accelerator software cannot be used.

Httpd. conf Basic settings
First, you need to have a complete host name in/etc/hosts. Otherwise, you will be prompted that the complete host name cannot be found when you restart the apache service.
The basic settings of httpd. conf are as follows:
<Set project>
Related Parameters in the project
....

For example, if you want to provide additional functions for the homepage/var/www/html, you can perform the following settings:

Options Indexes
......


Set items for the host environment
# Vi/etc/httpd/conf/httpd. conf
ServerTokens OS
# This Project tells the client about the WWW server version and operating system and does not need to be adapted.
# If you do not want to tell too much host information, change the OS of this project to Minor.

ServerRoot "/etc/httpd"
# This is the top-level directory of the setting file, which usually uses absolute paths. When some of the following data settings use relative paths
# It is the lower-level directory related to the directory setting value and does not need to be changed.
ServerRoot
Set the absolute path for Apache installation
TimeOut
Sets the maximum wait time for the server to receive the message.
KeepAlive
Set whether the server enables the continuous request function. Generally, the real server must enable the function.
Port
Set the default port of the http service.
User/Group
Set the executor and Group of the server program, which is generally apache

Below we will do a few experiments on Apache
1: We tested to change the default website directory to the root directory.
Create/root/website directory
# Mkdir-p/root/website
# Echo "website page">/root/website/index.html
# Vi/etc/httpd/conf/httpd. conf
Find the root directory of DocumentRoot "/var/www/html" // apache
Change the/var/www/html directory to/root/website.
Find/define apache/var/www/html.
Change/var/www/html to/root/website
In this way, we can change the default path of apahce.
Then restart the service.
# Service httpd restart
// When you restart the service, an error may be reported, indicating that the directory cannot be found, which is mainly caused by selinux.
How can this problem be solved? There are two ways to disable selinux
# Setenforce 0
Or change The selinux attribute of the/root/website file to match the requirements of the httpd server.
How to change it? We can copy the selinux attribute of the/var/www/html directory.
# Chcon-R -- reference/var/www/html/root/website
Then, after restarting the service, you will see that there is no error.
But when you access localhost, you will find that the access is denied. Why? The main reason is that your/root permission is 750, and the ahache user has no access permission. You need to change the permission.
# Chmod-R 755/root
Then, access and find that it is normal.

2: Name-based VM
The two domain names need to be resolved to your server. The corresponding relationship is
/Var/www/server server.example.com
/Var/www/client client.example.com
When you access these two domain names, you can display the content of the homepage in different files.
# Echo "server page">/var/www/server/index.html
# Echo "client page">/var/www/client/index.html
Then we edit a configuration file.
# Vi/etc/httpd/conf. d/virtual. conf // remember that the content in conf. d is also the configuration file of apache.
Add the following content:
NameVirtualHost 192.168.76.133: 80


ServerName service.example.com
DocumentRoot/var/www/server

 

ServerName client.example.com
DocumentRoot/var/www/client

# Service httpd restart
In this way, the name-based virtual host is configured.
If you do not have DNS, you can add a record to the hosts file on your machine for linux in the/etc/hosts file for windows in the C:/windows/system32/drivers/etc/hosts file
Add the two rows
192.168.76.133 server.example.com
192.168.76.133 client.example.com
In this way, you will find that the access to different domain names shows different content, so the name-based virtual host is configured!

3: IP address-based VM
First add a temporary Nic
# Ifconfig eth0: 0 192.168.76.132 // for temporary use, it will disappear after restart
Then the virtual. conf file is convenient.
# Vi/etc/httpd/CONF. d/virtual. conf
Modify the content
# Namevirtualhost 192.168.76.20.: 80


Servername service.example.com
DocumentRoot/var/www/Server

 

Servername client.example.com
DocumentRoot/var/www/client

After you access it with an IP address, you can find that different content can be displayed, or you can edit the hosts file to access it with a domain name.
In this way, the IP address-based virtual host is also successful!

4: alias
Add/etc/httpd/CONF/httpd. conf
Alias/test "/root/website/" // alias. In this way, when you access 192.168.76.20./ test, the page of 192.168.76.20.is displayed.
Note the difference between/test and/test/. If you use/test, you can only access it with 192.168.76.20./ test. If you use/test/, 192.168.76.20. /test/access, and/test won't let you access
Forget to put/etc/httpd/conf first. the virtual directory just set in the d directory is commented out or cannot be accessed because the virtual directory is created, and httpd. the configuration in conf cannot be accessed. Of course, localhost can be used for access, but none of the other accesses can be used.

5. Download Web Resources
Add an alias first
# Vi/etc/httpd/conf/httpd. conf
After Alias/test "/root/website/", add
Alias/down "/var/ftp/pub"
Set parameters for the/var/ftp/pub region.

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

Automatically List Directory documents when MultiViews is added to Options without index
Then restart the service so that the files in the/var/ftp/pub file can be listed in http: // 192.168.76.20./ down/. Try to save it as a file. Can you download it? Haha success!

6:. Implementation of htpasswd
# Vi/etc/httpd/conf/httpd. conf
We have just done this for/var/ftp/pub.
Add the following information:
Alias/down "/var/ftp/pub /"

Options Indexes MultiViews
AllowOverride AuthConfig
Order allow, deny
Allow from all


AuthType Basic
AuthName "this is test"
AuthUserFile/etc/httpd/htpasswd
Require User test

Restart the httpd service,
Generate a. htpasswd User Password
Htpasswd-c/etc/httpd/htpasswd test
The password is required to access 192.168.76.20./ down later.
This will succeed.

 

 

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.