Home >php教程 >php手册 >CentOS 5.5 uses yum to install Apache PHP MySQL

CentOS 5.5 uses yum to install Apache PHP MySQL

WBOY
WBOYOriginal
2016-07-09 09:09:18775browse

1. Install centos5.5 operating system
The CentOS development community has released a new 5.5 version. CentOS 5.5 is based on Red Hat Enterpris Linux 5.5.0, which includes 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, Evolution 2.12, etc. . Additionally, CentOS 5.3 updates the artwork and restores the Contrib repository per user request.
CentOS 5.5 supports i386 and x86_64 architectures, and its ISO image can be obtained from the following address. http://www.wljcz.com/html/caozuoxitong/Linux/2009/0726/409.html
2. System installation
CentOS 5.5 is installed as a server, so if it is useless, it will not be installed; specifically It’s up to you what not to install:
3. Install Apache php Mysql
Before installing with yum, first replace it with the Chinese CentOS5.3 mirror server! Fast and easy-to-use yum update source: http://www .wljcz.com/html/caozuoxitong/Linux/2009/0726/410.html This article has a detailed introduction. After modifying the update source according to the steps provided, 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 connection mysql library component

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 mysql database root account password.

Code:
mysqladmin -u root password 'newpassword'
"newpassword" represents the password you want to set. The root user password of the newly installed mysql is empty by default. Set the password Then you can make the mysql database more secure

Code:
mysql -u root -p (You will be asked to enter the password you just set, just enter it and press Enter)
mysql> DROP DATABASE test; (delete test database)
mysql> DELETE FROM mysql.user WHERE user = ”; (delete anonymous account)
mysql> FLUSH PRIVILEGES; (overload permissions)

4. Follow the above Installation method, the configured default site directory is /var/www/html/ Create a new php script:

Code:
phpinfo();
?>
4. Configure the firewall
Add allowed access to 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 official website to download phpMyAdmin, php 5.2 or above is required for version 3.1 or above, upload it to your website directory, and then configure it in just a few steps. .php is renamed to config.inc.php, then open the config.inc.php file and make the following modifications;
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_pages'] = '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 in front of each line
$cfg['blowfish_secret'] = ”; |Modify to| $cfg['blowfish_secret'] = 'http';
$cfg['Servers'][$i]['controluser'] = 'pma'; |Change 'pma' to your account|$cfg['Servers'][$i] ['controlpass'] = 'pmapass'; |Set 'pmapass as your mysql login password
$cfg['blowfish_secret'] = ”; | Add 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
At this point, the PHP environment under centos5.3 is basically configured, and you can start the service with the command.
8. If you want to upgrade PHP
Mention that PHP needs to be upgraded to 5.2 or above, and centos 5.x currently provides PHP version 5.1.6.
It is more convenient to upgrade PHP to 5.2 through the following method. Now Recommended to everyone.
First import the following address.

# 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

Execute the command to automatically upgrade.

yum update php -y
yum install libmcrypt -y

1. Update the system kernel to the latest.
[root@linuxfei ~]#yum -y update
After the system is updated, if an error message is prompted during yum installation, please execute the following command to fix it.
[ root@linuxfei ~]#rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY*
2. Install Apahce, PHP, Mysql, and PHP connection 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 start automatically]
[root@linuxfei ~]# /sbin/chkconfig –-add mysqld [ mysql service]
[root@linuxfei ~]# /sbin/chkconfig mysqld on [mysqld service]
[root@linuxfei ~]# /sbin/service httpd start [self-start httpd service]
[root @linuxfei ~]# /sbin/service mysqld start [Self-start mysqld service]
4. Set the mysql database root account password.
[root@linuxfei ~]# mysqladmin -u root password 'linuxfei' [Password in quotes]
[root@linuxfei ~]# mysql -u root -p ← Log in as root with an empty password
Enter password:linuxfei ← Enter password here

Welcome to the MySQL monitor. Commands end with ; or g. ← Confirm that you can log in successfully with your 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
--2010-03 -23 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.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]

Unzip phpmyadmin

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

[root@linuxfei /]# 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 in the root directory of phpmyadmin and rename it to config.inc.php

Open and edit config.inc.php

$cfg['blowfish_secret'] = '';

Find the two lines below 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, but many other distributions split this file into several small files to manage different parameters respectively. But the most important configuration file is still based on this file name.
/etc/httpd/conf.d/*.conf
This is one of the features of CentOS. If you don’t want to modify the original configuration file httpd.conf, you can separate your own additional parameters, and When starting apache, 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 placed in this directory by default
/var/www/html
This is the default for CentOS The directory where the "Home Page" is located.
/var/www/error
If the host setting is wrong or the data required by the browser is wrong, the error message that appears on the browser will be based on the default information of this directory.
/var/www/icons
Provides some small icons for apache
/var/www/cgi-bin
The directory where some executable CGI programs are placed by default
/var/log /httpd
By default, apache’s log files are placed here. For websites with high traffic, be very careful with this directory, because this file can easily become large, and you need enough space.
/usr /sbin/apachectl
This is the main executable file of Apache. This executable file is actually a shell script. It can actively detect some settings on the system, making it easier for you to start Apache.
/usr/sbin/ httpd
This is the main apache binary file
/usr/bin/htpasswd
When you want to log in to certain web pages, you need to enter your account number and password. Then Apache itself provides the most basic password protection method. The password is generated through this command

As for MySQL, the important directories and files you need to know are as follows:
/etc/my.cnf: This is the MySQL configuration file, including the optimization of the MySQL database you want to , or you are specifying some additional parameters for mysql, you can implement it in this file
/usr/lib/mysql: This directory is where the MySQL database is placed. When starting any MySQL server, please be sure to remember to When backing up, back up this directory completely.

In addition, in terms of PHP, you should know the following files.
/usr/lib/httpd/modules/libphp4.so: The module provided by PHP to apache. This is related to whether we can design the most important file of the PHP programming language on the apache web page
/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 into 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, whether it can allow certain low-security flags, etc., are all set in this configuration file.
/etc/php.d/mysql.ini /usr/lib/php4/mysql.so: Whether PHP can support the MySQL interface depends on these two files. These two files are provided by php-mysql software
/usr/bin/phpize /usr/include/php: If you want to install a similar PHP accelerator in the future to speed up browsing, then this file and directory are It needs to exist, otherwise the accelerator software cannot be used.

Basic settings of httpd.conf
First of all, you need to have a complete host name in /etc/hosts, otherwise when restarting the apache service, you will be prompted that the complete host name cannot be found.
The basic settings of httpd.conf are as follows:

Set the relevant parameters in the project
times. . . .

For example, if you want to provide additional functions for the homepage /var/www/html, you can set it as follows:

Options Indexes
……


Setting projects for the host environment
#vi /etc/httpd/conf/httpd.conf
ServerTokens OS
# This project tells the client the version and operating system of the WWW server, No need to adapt it
#If you don’t 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 settings file. Absolute paths are usually used. When some of the following data settings use relative paths,
#is the lower level related to the setting value of this directory. Directory, no need to change it
ServerRoot
Set the absolute path of Apache installation
TimeOut
Set the maximum waiting time for server reception to completion
KeepAlive
Set whether the server is turned on For the continuous request function, real servers generally need to open
Port
to set the default port of the http service.
User/Group
sets the executor and group of the server program. This is usually apache

Let’s do a few experiments on Apache
1: We test changing the default website directory to the root home directory
Create a new /root/website directory
#mkdir -p /root/website
#echo "website page" >> /root/website/index.html
#vi /etc/httpd/conf/httpd.conf
Find the DocumentRoot "/var/www/html" section // The root directory of apache
Change the directory /var/www/html to /root/website
Find // Define the area of ​​​​apache /var/www/html
Change /var/www/html into /root/website
In this way, we have changed the default path of apahce
Then restart the service
#service httpd restart
//When you restart the service here, an error may be reported, saying The directory cannot be found. This is mainly caused by selinux
So how to solve it? There are two ways, turn off selinux
#setenforce 0
or change the selinux attribute of the /root/website file so that it matches the requirements of the httpd server
How to change it? We can copy the selinux attributes of the /var/www/html directory
#chcon -R --reference /var/www/html /root/website
and then restart the service, and then you will see that it does not report an error
But when you go to access localhost, you will find that access is denied. Why? Mainly because your /root permissions are 750, and user ahache does not have permission to access. You need to change the permissions. You can change it like this
#chmod -R 755 /root
and then access it and find it normal

2: Name-based virtual host
requires two domain names to be resolved to your server. The corresponding relationship is
/var/www/server server.example.com
/var/www/client client .example.com
When accessing these two domain names, the contents of the homepages in different files can be displayed respectively
#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 conf.d The content inside is also the apache configuration file
. 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. The file Linux is in /etc/hosts and Windows is in C: windowssystem32driversetchosts file
add these two lines
192.168.76.133 server.example.com
192.168.76.133 client.example.com
In this way, when you test it, you will find that different domain names are displayed differently. The content is so that the name-based virtual host is configured!

3: Virtual host based on IP address
Add a temporary network card first
#ifconfig eth0:0 192.168.76.132 //Temporary use, it will disappear after restarting
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

Then you use IP to access, and you find that different content can be displayed, or you edit the hosts file and access with domain name is no problem
In this way, the virtual host based on IP address is also successful!

4: Alias ​​
Add
Alias ​​/test "/root/website/" to /etc/httpd/conf/httpd.conf // Alias ​​will also be displayed when you use 192.168.76.133/test to access it The page of 192.168.76.133
What you need to pay attention to here is the difference between /test and /test/. If you use /test, you can only access it with 192.168.76.133/test. If you use /test/, then 192.168.76.133/test/, and /test will not let you access
Forgot to comment out the virtual directory just set in the /etc/httpd/conf.d directory, otherwise it will not be accessible. Yes Because a virtual directory is created, the settings in httpd.conf cannot be accessed. Of course, you can use localhost to access it, but other accesses will not work

5: Implement web page resource download
First add an alias
#vi /etc/httpd/conf/httpd.conf
Add after Alias ​​/test "/root/website/"
Alias ​​/down "/var/ftp/pub"
Let’s set parameters for the /var/ftp/pub area

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

Add MultiViews to Options // Automatically list directory documents when there is no index
Then restart the service, so that the files in /var/ftp/pub can be listed in http://192.168.76.133/down/ , try clicking Save As. Can it be downloaded? Haha success!

6: Implementation of .htpasswd
#vi /etc/httpd/conf/httpd.conf
We will do it for the /var/ftp/pub we just created
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,
generate the .htpasswd user password
htpasswd -c /etc/httpd/htpasswd test
then access 192.168.76.133/down and you will need a password
like this It was successful

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP: Parse JSON arrayNext article:PHP: Parse JSON array