Reprint: CentOS on Yum installation apache+php+mysql, etc.

Source: Internet
Author: User
Tags gpg install php pear php mysql php programming php programming language password protection phpmyadmin

1. Update the system kernel to the latest.

[[email protected] ~] #yum-y update 
If the Yum installation prompts you for an error message, perform the following command to repair the.  
[[email  Protected] ~] #rpm –import/etc/pki/rpm-gpg/rpm-gpg-key* 
2. Install Apahce, PHP, MySQL, and PHP connection to MySQL library components  
y[ [email protected] ~] #um-y install httpd php mysql mysql-server php-mysql 
//install MySQL extension  
[[email& Nbsp;protected] ~] #yum-y install mysql-connector-odbc mysql-devel libdbi-dbd-mysql 
//install PHP extension  
[[ Email protected] ~]# yum-y install php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc 
//Installing Apache extensions & nbsp
[[email protected] ~] #yum-y install httpd-manual mod_ssl mod_perl mod_auth_mysql 
Paste Installation: 
[[email protected] ~]# yum-y install httpd php mysql mysql-server php-mysql httpd-manual mod_ssl mod_perl Mod_au Th_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 the service configuration
[[email protected] ~]#/sbin/chkconfig httpd on [set Apache as self-booting]
[Email protected] ~]#/sbin/chkconfig–-add mysqld [MySQL service]
[Email protected] ~]#/sbin/chkconfig mysqld on [mysqld service]
[Email protected] ~]#/sbin/service httpd start [auto start httpd service]
[Email protected] ~]#/sbin/service mysqld start [auto start mysqld Service]
4. Set the MySQL database root account password.
[[email protected] ~]# mysqladmin-u root password ' Linuxfei ' [Enter the password in quotes]
[[email protected] ~]# mysql-u root-p← Log in with a blank password
Enter password:linuxfei← the password here

Welcome to the MySQL Monitor. Commands End With;  Or/g. ← Confirm password can be successfully logged in
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>


Picture 1
Picture 2

5. Installing phpMyAdmin
[[email protected]/]# 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 ... OK
LENGTH:4700100 (4.5M) [Application/x-gzip]
Saving to: ' phpmyadmin-3.x.tar.gz '

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

2010-03-23 16:38:56 (123 kb/s)-' phpmyadmin-3.x.tar.gz ' saved [4700100/4700100]

Decompression phpMyAdmin

[[email protected]/] #tar ZXVF phpmyadmin-3.x.tar.gz

[Email protected]/]# MV Phpmyadmin-3.3.1-all-languages/var/www/html/phpmyadmin

Move the extracted directory to the/var/www directory and rename it to phpMyAdmin

Modify config.sample.inc.php renamed to config.inc.php under the phpMyAdmin root directory

Open and edit config.inc.php

$cfg [' blowfish_secret '] = '; /* Add short password This must be filled out or it will be wrong */

Then find the bottom two lines and remove the//

$cfg [' Servers '] [$i] [' controluser '] = ' PMA '; MySQL User name
$cfg [' Servers '] [$i] [' controlpass '] = ' pmapass ' mysql password


Apache Configuration

/etc/httpd/conf/httpd.conf 
The most important configuration file, but many other distribution have split the file into several small files, managing different parameters separately. However, the main configuration file is based on this file name.
/etc/httpd/conf.d/*.conf
This is one of the features of CentOS, If you do not want to modify the original configuration file httpd.conf, then you can separate your own additional parameters, and when you start Apache, this file will be read into the main configuration file.
/usr/lib/httpd/modules
Apache supports many modules, so the module you want to use is placed by default in this directory
/var/www/html
, which is the default "home" directory for CentOS.
/var/www/error
If the error message appears on the browser because of a host setting error or a data error requested by the browser, the default information for this directory is the primary.
/var/www/icons
provides some small icons for Apache
/var/www/cgi-bin 
Default to some executable CGI programs placed in the directory
/VAR/LOG/HTTPD
The default Apache log files are placed here, for large traffic sites, this directory should be very careful, because this file is very easy to change, you need enough space Oh
/usr/sbin/apachectl
This is Apache's main execution file, This execution file is actually shell script, it can actively detect some settings on the system, so that you start Apache more simple
/usr/sbin/httpd
This is the main Apache binary file
/usr/bin/ HTPASSWD
When you want to log in to certain pages, you need to enter your account and password. Then Apache itself provides a basic password protection method. This password is generated by this command to implement the

As far as MySQL is concerned, you need to know several important directories and files that have the following:
/ETC/MY.CNF: This is the MySQL configuration file, which includes the optimization of the MySQL database you want to make, or the addition of some additional parameter designations to MySQL, which can be implemented in this file.
/usr/lib/mysql: This directory is where the MySQL database is placed, and when you start any MySQL server, it is important to remember that the directory is fully backed up when it is backed up.

In addition, in PHP, you should know the following several files.
/usr/lib/httpd/modules/libphp4.so:php is available to the Apache module, which we can design the most important files of the PHP programming language on the Apache Web page
/etc/httpd/conf.d/php.conf: Do you want to manually write the module to httpd.conf? No, because the system has actively written the PHP setup parameters to this file, and this file will be read in when Apache restarts.
/etc/php.ini: This is the main PHP configuration file, including PHP can not allow users to upload files, can allow certain low-security flags, etc., are set in this configuration file.
/etc/php.d/mysql.ini/usr/lib/php4/mysql.so:php can support MySQL interface to see these two files. These two files are provided by the Php-mysql software
/usr/bin/phpize/usr/include/php: If you want to install a PHP-like accelerator in the future to speed up browsing, then this file and directory needs to exist, or the accelerator software is not available.

Basic settings for httpd.conf
First, you need to have a full hostname within the/etc/hosts, or you will be prompted to not find the full hostname when you restart the Apache service.
The basic setup for httpd.conf is this:
< set up Projects >
Related parameters within the sub-set item
。。。。

For example, if you want to provide additional functionality for the home page/var/www/html, you can set the following:

Options Indexes
......


Settings items for the host environment
#vi/etc/httpd/conf/httpd.conf
Servertokens OS
# This project tells the client WWW server version and operating system, does not need to adapt it
#如果你不想告诉太多的主机信息, change the OS of this project to minor

ServerRoot "/ETC/HTTPD"
#这个是设置文件的最顶层目录, typically using absolute paths, some of the following data settings use relative paths when
#就是与这个目录设置值有关的下层目录, you don't need to change it
ServerRoot
Set the absolute path for Apache installation
TimeOut
Set the maximum wait time that the server receives to completion
KeepAlive
Set the server to open the continuous request function, the real server is generally open
Port
Sets the default port for the HTTP service.
User/group
Set the performer and genus of the server program, which is typically Apache

Let's do some experiments on Apache
1: We test to change the default site directory to the root home directory
New/root/website directory
#mkdir-p/root/website
#echo " Website page ">>/root/website/index.html
#vi/etc/httpd/conf/httpd.conf
Find DocumentRoot"/var/www/html " This section of the//apache root directory
/var/www/html This directory to/root/website
to find//define apache/var/www/html This area
change/var/www/html to/ Root/website
So we apahce the default path to the
and then restart the service
#service httpd restart 
//Here you may get an error when you restart the service, saying that the directory cannot be found. This is mainly due to the selinux caused by the
How to solve it? There are 2 ways to turn off selinux 
#setenforce 0
or change the SELinux attribute of the/root/website file to match the httpd of this server
How to change it? We can copy the SELinux property of/var/www/html This directory
#chcon-R--reference/var/www/html/root/website
and then restart the service, and you'll see it's not an error
But when you go to localhost, you will find the access denied. Mainly because your/root permissions are 750,ahache This user does not have permission to access, you need to change the permissions, you can modify the
#chmod-R 755/root
and then go to visit found normal

2: Name-based virtual host
Requires two domain name resolution 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 contents of the main page of different files separately.
#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 contents of CONF.D are also Apache configuration files
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
So the name-based virtual host is configured
If you do not have DNS you can re-add the Hosts file on your machine to record Linux in/etc/hosts this file in Windows C:/windows/system32/drivers/etc/hosts file
Plus these two lines
192.168.76.133 server.example.com
192.168.76.133 client.example.com
So you are going to test, you will find that access to different domain names display different content so that the name-based virtual host is configured!

3: IP address-based virtual host
Add a temporary network adapter first
#ifconfig eth0:0 192.168.76.132//temporary use, after reboot will disappear
Then convenient virtual.conf file
#vi/etc/httpd/conf.d/virtual.conf
Change the content to
#NameVirtualHost 192.168.76.133:80


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

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

After you have access to the IP, you can also see different content, or you edit the Hosts file, access to the domain name is no problem
So the virtual host based on IP address is also successful!

4: Aliases
Join in the/etc/httpd/conf/httpd.conf.
Alias/test "/root/website/"//alias so you can use 192.168.76.133/test to access the 192.168.76.133 page
This place needs to pay attention to is/test or/test/this is to use the difference of you with/test then you visit only with 192.168.76.133/test access if you use/test/so 192.168.76.133/test/access, and/ Test will not let you visit
Forget this place you first put the/ETC/HTTPD/CONF.D directory inside the virtual directory just set comments out or can not access, is because the virtual directory, and httpd.conf inside the settings will not be able to access, of course, the other access is not

5: Download resources for Web pages
First add an alias
#vi/etc/httpd/conf/httpd.conf
Add after Alias/test "/root/website/"
Alias/down "/var/ftp/pub"
To set the parameters for the/var/ftp/pub locale

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

Automatically list directory documents when options join MultiViews//No Index
Then restart the service, so that http://192.168.76.133/down/inside can list/var/ftp/pub inside the file, try to point a save as, whether you can download? Hehe success!

The realization of 6:.HTPASSWD
#vi/etc/httpd/conf/httpd.conf
We'll do it for the/var/ftp/pub we just made.
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

Then restart the httpd service,
Let's generate a. HTPASSWD user password
Htpasswd-c/ETC/HTTPD/HTPASSWD Test
Access to 192.168.76.133/down will require a password.
That's how it works.

Reprint: Yum installs Apache+php+mysql on CentOS, etc.

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.