Centos 5.5 use Yum to install Apache + PHP + MySql

Source: Internet
Author: User
Tags gpg ldap mcrypt php mysql apache log mysql login password protection
Centos 5.5 use Yum to install Apache + PHP + MySql

1. Install the centos5.5 Operating System
The centos development community has released a new version 5.5. Centos 5.5 is based on Red Hat platform is Linux 5.5.0, these include kernel 2.6.18, Apache 2.2, PHP 5.1.6, MySQL 5.0, PostgreSQL 8, gnome 2.16, Kde 3.5, OpenOffice.org 2.3, Firefox 3.0, and evolution 2.12. In addition, centos 5.3 updated the art design and restored the contrib repository as requested by the user.
Centos 5.5 supports the i386 and x86_64 architectures. The ISO image can be obtained from the following addresses. Http://www.wljcz.com/html/caozuoxitong/Linux/2009/0726/409.html
Ii. System Installation
If centos 5.5 is installed as a server, it is useless and will not be installed. If you choose not to install it, do it yourself:
3. install Apache + PHP + MySql
Before using yum for installation, replace it with the centos5.3 image server in China! Quick easy to use Yum update source: http://www.wljcz.com/html/caozuoxitong/Linux/2009/0726/410.html this article has a detailed introduction, according to the provided steps to modify the update source, you can easily use the yum command to quickly install the software.
 
1. Update the system kernel to the latest. Yum-y update
Install apahce, PHP, MySQL, and PHP to connect to MySQL library components
 
Code:
Yum-y install httpd PHP MySQL mysql-server PHP-MySQL
 
2. Install MySQL extension
 
Code:
Yum-y install mysql-connector-ODBC mysql-devel libdbi-DBD-MySQL
Or one-time paste installation:
 
Code:
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. Set the password of the root account of the MySQL database.
 
Code:
Mysqladmin-u Root Password 'newpassword'
"Newpassword" indicates the password you want to set. The root user password of the newly installed MySQL is empty by default. Setting the password can make the MySQL database safer.
 
Code:
Mysql-u root-P (you will be asked to enter the password you just set, enter it and press Enter)
Mysql> drop database test; (delete the test database)
Mysql> Delete from mysql. User where user = "; (delete anonymous account)
Mysql> flush privileges; (overload permission)
 
4. According to the above installation method, the default site directory configured is/var/www/html/to create a PHP script:
 
Code:
<? PHP
Phpinfo ();
?>
4. configure the firewall
Add HTTP and FTP ports
 
Code:
Iptables-I RH-Firewall-1-INPUT-M state -- state new-M TCP-P TCP -- dport 21-J accept
Iptables-I RH-Firewall-1-INPUT-M state -- state new-M TCP-P TCP -- dport 80-J accept
Restart iptables: Service iptables restart
5. Install phpMyAdmin
Go to phpMyAdmin to download phpMyAdmin. php 3.1 or above is required for PHP 5.2 or above. upload it to your website directory and configure it. You can do this in just a few steps.
Change config. sample. Inc. php to config. Inc. php, open the config. Inc. php file, and make the following changes;
Code:
// $ Cfg ['servers'] [$ I] ['controluser'] = 'pma ';
// $ Cfg ['servers'] [$ I] ['controlpass'] = 'pmapass ';
// $ Cfg ['servers'] [$ I] ['pmadb'] = 'phpmyadmin ';
// $ Cfg ['servers'] [$ I] ['bookmarktable'] = 'pma _ bookmark ';
// $ Cfg ['servers'] [$ I] ['relation'] = 'pma _ relation ';
// $ Cfg ['servers'] [$ I] ['table _ info'] = 'pma _ table_info ';
// $ Cfg ['servers'] [$ I] ['table _ coords '] = 'pma _ table_coords ';
// $ Cfg ['servers'] [$ I] ['pdf _ page'] = 'pma _ pdf_pages ';
// $ Cfg ['servers'] [$ I] ['column _ info'] = 'pma _ column_info ';
// $ Cfg ['servers'] [$ I] ['History '] = 'pma _ history ';
// $ Cfg ['servers'] [$ I] ['designer _ coords '] = 'pma _ designer_coords ';
Remove the // comment before each line
$ Cfg ['blowfish _ secret'] = "; | modified to | $ cfg ['blowfish _ secret'] = 'http ';
$ Cfg ['servers'] [$ I] ['controluser'] = 'pma '; | modify 'pma' to your account | $ cfg ['servers'] [$ I] ['controlpass'] = 'pmapass '; | set 'pmapass as your MySQL Login Password
$ Cfg ['blowfish _ secret'] = "; | add a phrase password, for example, $ cfg ['blowfish _ secret'] = 'onohot ';
6. install PHP Extension
Code:
Yum-y install PHP-Gd PHP-xml php-mbstring PHP-ldap php-pear PHP-XMLRPC
7. install Apache Extension
Code:
Yum-y install httpd-manual mod_ssl mod_perl mod_auth_mysql
So far, the PHP environment in centos5.3 is basically configured. You can use the command to start the service.
8. If you want to Upgrade PHP
We mentioned that PHP needs to be upgraded to 5.2 or above, while centos 5.x currently provides PHP version 5.1.6,
It is convenient to Upgrade PHP to 5.2 using the following methods. We recommend this method to you.
Import the following addresses first.

# Rpm -- import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

# Vi/etc/yum. Repos. d/CentOS-Base.repo Add the following information

[Utterramblings]
Name = Jason's utter ramblings Repo
Baseurl = http://www.jasonlitka.com/media/el?releasever/?basearch/
Enabled = 1
Gpgcheck = 1
Gpgkey = http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

Run the command to automatically upgrade the instance.

Yum update PHP-y
Yum install libmcrypt-y

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.
[Root @ linuxfei ~] # Yum-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.

5. Install phpMyAdmin
[Root @ linuxfei/] # wget http://gd2.down.chinaz.com: 808/data management/phpMyAdmin-3.tar.gz
-- 16:38:18 --

Http://gd2.down.chinaz.com: 808 /?????? 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'] = '';

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:

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.

This article from qkweb.net, reprint please indicate the source http://www.qkweb.net/showa/715.html

Related Article

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.