Install MySQL Apache PHP on centos

Source: Internet
Author: User
Tags apache php
I have a thorough understanding of Linux, so I have encountered all these things. Make a summary.

Install MySql in Linux using the tar package installation mode

1. Create a directory and user group
Mkdir/usr/local/MySQL
Groupadd MySQL
Useradd-G MySQL
2. Unzip and install
Tar zxvf mysql-3.23.58.tar.gz
CD mysql-3.23.58
. /Configure -- prefix =/usr/local/MySQL -- sysconfdir =/etc -- localstatedir =/var/lib/MySQL -- With-named-urses-IBS =/usr/lib/libncursesw. so.5
# Prefix =/usr/local/MySQL target directory for MySQL Installation
# Sysconfdir =/etc my. ini configuration file path
# Localstatedir =/var/lib/MySQL database storage path
# With-named-urses-IBS if this sentence does not exist, the make file cannot be generated.
Make
Make install
3. create databases and tables

/Usr/local/MySQL/bin/mysql_install_db -- user = MySQL

Copy the configuration file in three environments: large, medium, and small. Select the one based on the machine performance. If the load is heavy, you can modify the memory usage values of some variables.

CP/usr/local/MySQL/share/MySQL/my-medium.cnf/etc/My. CNF

Change directory permissions and Groups
Chmod 755-r/usr/local/MySQL/
Chown mysql. mysql-r/usr/local/MySQL/

Start MySQL
/Usr/local/MySQL/bin/mysqld_safe &
OK. Check if MySQL works properly.
Mysql-uroot MySQL
(In this case, the MySQL service is started, but the command not found prompt is entered in MySQL)
Solution: Map mysqlpath/bin/MySQL to the/usr/local/bin directory:
CD/usr/local/bin
Ln-fs/mysqlpath/bin/MySQL
After completing the above steps, copy a script in your compiled directory

CP support-files/MySQL. Server/etc/rc. d/init. d/mysqld
Chkconfig -- add mysqld

Set ntsysv to enable MySQL to run automatically at each startup.

Now that MySQL is installed, you can start your MySQL service.
/Etc/rc. d/init. d/mysqld start

The following steps are critical,
Ln-S/usr/local/MySQL/lib/MySQL/usr/lib/MySQL
Ln-S/usr/local/MySQL/include/MySQL/usr/include/MySQL

You can skip this step. You can customize the myslq library file path when compiling other software, but I still like to link the library file to the default location, so that you are compiling PHP like, when using software such as Vpopmail, you do not need to specify the MySQL library file address.

Install 
Rpm needs Yum to run, so the compressed version of Taz is downloaded.
The installation procedure is as follows:
Shell> groupadd MySQL
Shell> useradd-G MySQL
Shell> Cd/usr/local
Shell> gunzip </path/to/mysql-VERSION-OS.tar.gz | tar xvf-
Shell> ln-s full-path-to-mysql-version-OS MySQL
Shell> Cd MySQL
Shell> chown-r MySQL.
Shell> chgrp-r MySQL.
Shell> scripts/mysql_install_db -- user = MySQL
Shell> chown-r root.
Shell> chown-r Mysql Data
Shell> bin/mysqld_safe -- user = MySQL & (start)

Key points: Create mysql users and groups, decompress them, create shortcuts (important), modify permissions, and import the initial table

Set Password 
Mysqladmin-u Root Password 'newpassword' (no single quotation marks are entered)

Create a MySQL self-starting service 
In the support-file under the MySQL directory, there is a STARTUP script program named myslq. server. Copy it to the/etc/rc. d/init. d directory (renamed MySQL ):

# Cd/etc/rc. d/init. d
# Cp/usr/local/MySQL/support-files/MySQL. Server MySQL

Change its attribute to "X" (executable, executable)

# Chmod + x MySQL

Finally, run chkconfig to add MySQL to the startup Service Group of your system.

#/Sbin/chkconfig -- del MySQL
#/Sbin/chkconfig -- add MySQL

Remote connection permission 
Log on to the MySQL Console (./MySQL-u root-P)
Update user set host = '%' where user = 'root ';

PS: After setting it, I found that the localhost could not be accessed. I re-used the remote UI to configure a record for the localhost in the user.
(Which of the following is the root password of the user.

Server encoding settings 
MySQL uses the Latin character set by default. garbled characters are generated when the source command is used to import Chinese data.
Put a certain my X. copy CNF to/etc/(renamed my. CNF), add default-character-set = utf8 under [mysqld], and add default-character-set = utf8 under [client.
If the server is running, restart it. Log on to the MySQL console and use/s to view the encoding information.

Data Migration in Windows 
If you use the copy table file method, note that:
1. You need to set the permission for copying previous table files. You can set the permission according to the permission of the MySQL database.
The code for setting the owner and the group is as follows:
Chown MySQL *.*
Chgrp MySQL *.*
2. Pay attention to the table name problem. The names of the Windows tables are set to lower case, while the original table names are used in Linux.

Apache installation1. Go to the download directory:
CD/home/wangnan/soft
2. decompress the file:
Tar zxvf httpd-2.2.6.tar.gz
Decompress the package to generate a httpd-2.2.6 directory for the installation source file directory
3. Go to the installation source file directory
CD httpd-2.2.6
4. Generate the configuration file before installation. Here, the-Prefix specifies that Apache installation will be installed in the/usr/local/Apache directory.
./Configure -- prefix =/usr/local/Apache -- enable-modules = so -- enable-Rewrite
5. Generate the make file and install:
Make; make install
After completion:
Echo "/usr/local/Apache/bin/apachectl start">/etc/rc. d/rc. Local
After the system is started, Apache is started automatically.
You can view VI/etc/rc. d/rc. Local.
(In this case, you cannot access the Apache homepage)
Solution: Firewall:
Run the/etc/init. d/iptables STATUS Command to check whether port 80 is enabled. If port 80 is not enabled, you can use either of the following methods:
1. Modify the VI/etc/sysconfig/iptables command to add the firewall to open port 80
-A RH-Firewall-1-INPUT-M state -- state new-m tcp-p tcp -- dport 80-J accept
2. Disable the Firewall
/Etc/init. d/iptables stop
# Start
# Restart
Permanently disable the firewall chkconfig -- level 35 iptables off

  • Install PHP

Install the support package before installing PHP. Otherwise, it is like I have encountered errors all the time.
First, you must have GCC on the server. Otherwise, you cannot do anything. You can use gcc-V to check whether GCC is installed,
Gd-2.0.28.tar.gz
Libxml2-2.X.X.tar.gz
The zlib-1.X.X.tar.gz has forgotten,
Jpegsrc.v6b.tar.gz
Libpng-1.2.5.tar.gz
Freetype2-X.X.tar.gz

Install libxml
# Tar-zxf libxml2-2.6.16.tar.gz
# Cd libxml2-2.6.16
#./Configure (XML can be installed by default, do not specify the path, because PHP may not find it during installation, PhP5 only supports libxml2-2.5.10 and later versions)
# Make
# Make install

Install zlib
# Tar-zxf zlib-1.2.2.tar.gz
# Cd zlib-1.2
#./Configure -- prefix =/usr/local/zlib2! Similar to the following !)
# Make
# Make install

Install JPEG
# Tar-zxf restart src.v6b.tar.gz
# Cd jpeg-6b/
#./Configure -- prefix =/usr/local/Issue 6
# Make
# Make install-lib
If you choose to install it by default, it may be very smooth. After specifying the path, please first create the following folder
Error message:.../usr/bin/install-C-M 644 jconfig. h/usr/local/Issue 6/include/jconfig. h
/Usr/bin/install: The general file '/usr/local/defaults 6/include/jconfig. H' cannot be created: the file or directory does not exist.
Make: *** [install-headers] Error 1
# Mkdir/usr/local/limit 6
# Mkdir/usr/local/latest 6/include
# Mkdir/usr/local/IPv6/lib
# Make install-lib
# Make install

If an error occurs during installation:
/Usr/bin/install: The general file '/usr/local/defaults 6/lib/libjpeg. A' cannot be created: the file or directory does not exist.
Make: *** [install-lib] Error 1
Create the following folder:
# Mkdir/usr/local/IPv6/lib
# Make install
/Usr/bin/install-C cjpeg/usr/local/Listen 6/bin/cjpeg
/Usr/bin/install: The general file '/usr/local/defaults 6/bin/cjpeg' cannot be created: the file or directory does not exist.
Make: *** [install] Error 1
# Mkdir/usr/local/partition 6/bin
/Usr/bin/install-C-M 644./c0000.1/usr/local/sort 6/man/Man1/c0000.1
/Usr/bin/install: The general file '/usr/local/Hangzhou 6/man/Man1/c0000.1' cannot be created: the file or directory does not exist.
Make: *** [install] Error 1
# Mkdir/usr/local/IPv6/man
# Mkdir/usr/local/IPv6/man/Man1
# Make install
Okay, until the installation is successful!

Install libpng:
# Tar-zxf libpng-1.2.7-config.tar.gz
# Cd libpng-1.2.7-config
#./Configure -- prefix =/usr/local/libpng2
# Make
# Make install

Install FreeType:
# Tar-zxf freetype-2.1.9.tar.gz
# Cd freetype-2.1.9
#./Configure -- prefix =/usr/local/FreeType2
# Make
# Make install

Install the GD library:
# Tar-zxf gd-2.0.26gif.tar.gz
# Cd gd-2.0.26gif
#. /Configure -- prefix =/usr/local/GD2 -- With-zlib =/usr/local/zlib2/-- With-PNG =/usr/local/libpng2/-- With-JPEG = /usr/local/release 6/-- With-FreeType =/usr/local/FreeType2/(specify the installation path of the pass plug-in, otherwise, an error may occur when installing PHP !)
# Make
# Make install

# Tar-zxf php5-200411260130.tar.gz
# Cd php5-200411260130
#. /Configure -- prefix =/usr/local/PHP -- with-apxs2 =/usr/local/apache2/bin/apxs -- With-JPEG-Dir =/usr/local/defaults 6/-- -PNG-Dir =/usr/local/libpng2/-- With-Gd =/usr/local/GD2/-- With-FreeType-Dir =/usr/local/FreeType2/-- enable -Trace-vars -- With-zlib-Dir =/usr/local/zlib2/-with-mysql =/var/lib/MySQL
(* Note: if the preceding package supports installation paths, write the path for this configuration. If there is no installation path, write only with-** instead of the path, otherwise, an error is reported .)
# Make
# Make install
Add the PHP configuration file:
Cp php. ini-Dist/usr/local/PHP/lib/PHP. ini
(* Note: The file does not contain the php. ini-Dist file. In fact, PHP. ini-production can be used)

Configure Apache to support PHP
Edit/usr/local/Apache/CONF/httpd. conf
Find addtype application/X-gzip. GZ. tgz and add the following content under it:
Addtype application/X-httpd-PHP. php
Find directoryindex index.html and change it to directoryindex index. php index.html index.htm.
/Usr/local/Apache/bin/apachectl stop
/Usr/local/Apache/bin/apachectl start

The following error is reported when you restart Apache:
Httpd: syntax error on line 53 of/usr/local/Apache/CONF/httpd. conf: cannot load/usr/local/Apache/modules/libphp5.so into server:/usr/local/Apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

Cause: There is a SELinux protection mode in Linux.
Solution:
1. Method for disabling SELinux:
VI/etc/SELinux/config change SELinux = enforcing to SELinux = disabled and restart
This method may cause risks to the server.

2. Do not disable SELinux:
# Setenforce 0
# Chcon-C-v-r-u system_u-r object_r-T textrel_shlib_t/usr/local/Apache/modules/libphp5.so
# Service httpd restart
# Setenforce 1

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.