Apache + Mysql + PHP

Source: Internet
Author: User
Tags script php
Apache + Mysql + PHP reproduced from: http://blog.csdn.net/buutterfly/article/details/5630203

DedeCMS deployment -- how to deploy Apache + Mysql + PHP (LAMP )?

1. Linux OS:

Linux OS: Red Hat Enterprise Linux AS release 4 (Nahant Update 6)

2. Deploy Apache 2.1 Download Apache

Download Apache2 source from http://httpd.apache.org/, directly download under/root, unzip the tar package php-5.2.13.

2.2 compile apache

Cd httpd-2.2.15, compile, generate Makefile

./Configure -- prefix =/usr/local/apache/-- specify the apache installation directory

-- Enable-so/

-- Enable-cgi/

-- Enable-info/

-- Enable-rewrite/

-- Enable-speling/

-- Enable-usertrack/

-- Enable-deflate/

-- Enable-ssl/

-- Enable-mime-magic

2.3 make & make install

Make may have some problems. for details, refer to section 5th.

Apache deployment reference: http://dan.drydog.com/apache2php.html

3. Deploy Mysql 3.1 download mysql

Download mysql source from http://dev.mysql.com/and select MySQL Community Server on the Downloads page to go to the download page. Select Red Hat Enterprise Linux. Because my OS is REHL4.6 and is 64-bit, download three packages:

MySQL-server-community-5.1.47-1.rhel4.x86_64.rpm? Yes, otherwise the MySQL-client-community-5.1.47-1.rhel4.x86_64.rpm will fail during apache compilation

3.2 install mysql server

Rpm? Ivh MySQL-server-community-5.1.47-1.rhel4.x86_64.rpm

After the server is installed, run netstat to check whether the Mysql port is opened. If yes, the service is started and the installation is successful.

The default Mysql port is 3306. The command is as follows: netstat? Nap | grep 3306

3.3 install mysql client

Rpm? Ivh MySQL-client-community-5.1.47-1.rhel4.x86_64.rpm

3.4 install mysql devel

Rpm? Ivh MySQL-devel-community-5.1.47-1.rhel4.x86_64.rpm

3.5 Log on to Mysql

[Root @ test1 local] # mysql

Welcome to the MySQL monitor. Commands end with; or/g.

Your MySQL connection id is 1 to server version: 4.0.16-standard

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


The prompt "mysql>" appears. Congratulations! the installation is successful!

The logon format after the password is added is as follows:

Mysql-u root-p

Enter password: (Enter the password)

-U is followed by the user name.-p requires the password. press enter and enter the password at the enter password.

Note: This mysql file is located in the/usr/bin directory. it is not a file with the startup file/etc/init. d/mysql described later.

3.6 modify the mysql password

MySQL does not have a password by default. it is self-evident that the password is added after installation.

1. commands

Usr/bin/mysqladmin-u root password 'new-password'

Format: mysqladmin-u username-p old password new password

2. example

Example 1: Add a 123456 password to the root user.

Type the following command:

[Root @ test1 local] #/usr/bin/mysqladmin-u root password 123456

Note: Because the root account does not have a password at the beginning, the old-p password can be omitted.

3. test whether the modification is successful

1) login without a password

[Root @ test1 local] # mysql

ERROR 1045: Access denied for user: 'root @ localhost' (Using password: NO)

An error is displayed, indicating that the password has been modified.

2) log on with the modified password

[Root @ test1 local] # mysql-u root-p

Enter password: (Enter the password 123456 after modification)

Welcome to the MySQL monitor. Commands end with; or/g.

Your MySQL connection id is 4 to server version: 4.0.16-standard

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



You can use the mysqladmin command to change the password or the database to change the password.

3.7 start and stop

1. start

After MySQL is installed, run the following command to start mysql in the/etc/init. d Directory.

[Root @ test1 init. d] #/etc/init. d/mysql start

2. stop

/Usr/bin/mysqladmin-u root-p shutdown

3. automatic start

1) Check whether mysql is in the auto start list

[Root @ test1 local] #/sbin/chkconfig -- list

2) add MySQL to the startup service group of your system.

[Root @ test1 local] #/sbin/chkconfig? -Add mysql

3) delete MySQL from the startup service group.

[Root @ test1 local] #/sbin/chkconfig? -Del mysql

Mysql deployment reference: http://www.linuxidc.com/Linux/2007-12/9962p3.htm

3.8 use mysql

(This section is optional for our LAMP environment deployment)

The default data file storage directory of MySQL is/var/lib/mysql. To move the directory to/home/data, perform the following steps:

1. create a data directory under the home directory


Mkdir data

2. stop the MySQL service process:

Mysqladmin-u root-p shutdown

3. move the entire/var/lib/mysql directory to/home/data


In this way, the MySQL data file is moved to/home/data/mysql.

4. find the my. cnf configuration file.

If my. for the cnf configuration file, go to/usr/share/mysql/and find *. copy one of the cnf files to/etc/and change it to my. cnf. The command is as follows:

[Root @ test1 mysql] # cp/usr/share/mysql/my-medium.cnf/etc/my. cnf

5. edit the MySQL configuration file/etc/my. cnf.

To ensure that MySQL works properly, you must specify the location where the mysql. sock file is generated. Change socket =/var/lib/mysql. sock to/home/mysql. sock. The procedure is as follows:

Vi my. cnf (use the vi tool to edit the my. cnf file and find the following data to modify)

# The MySQL server


Port = 3306

# Socket =/var/lib/mysql. sock)

Socket =/home/data/mysql. sock (add this line)

6. modify the MySQL startup script/etc/rc. d/init. d/mysql

Finally, you need to modify the MySQL startup script/etc/rc. d/init. d/mysql: change the path on the right of datadir =/var/lib/mysql to your actual storage path: home/data/mysql.

[Root @ test1 etc] # vi/etc/rc. d/init. d/mysql

# Datadir =/var/lib/mysql (comment this row)

Datadir =/home/data/mysql (add this row)

7. restart the MySQL service.

/Etc/rc. d/init. d/mysql start

Or use the reboot command to restart Linux.

If it works properly, it will succeed. otherwise, check again against the previous seven steps.

4. Deploy PHP

The deployment of PHP is the most difficult part of the entire deployment. This step also makes me time-consuming and finds the longest answer on the network.

4.1 Download PHP

Download PHP source from http://www.php.net/

Note: dedecms 5.6 and later versions have flaws in php5.3 support! If php5.3 is used, after cms is successfully installed, the system background page will prompt "Deprecated: Function ereg_replace () is deprecated after the installation is complete .... ".

There are two solutions: See section 5th.

4.2 compile PHP

Cd php-5.2.13, compile, generate Makefile. Note: the configuration items in this area should be selected based on your own needs.


-- With-apxs2 =/usr/local/apache/bin/apxs/

-- With-mysql/

-- Prefix =/usr/local/apache/php/

-- With-config-file-path =/usr/local/apache/php/

-- Enable-force-cgi-redirect/

-- Disable-cgi/

-- With-zlib/

-- With-gettext/

-- With-gdbm/

-- With-gd

4.3 make & make install 4.4 cp-p. libs/libphp5.so/usr/local/apache/modules 4.5 cp php. ini

Command: cp-p php. ini-recommended/usr/local/apache/php. ini

4.6 modify httpd. conf

Modify/usr/local/apache/conf/httpd. conf and add the following content:


# Example:

# LoadModule foo_module modules/mod_foo.so


LoadModule php5_module modules/libphp5.so

AddHandler php5-script php


# DirectoryIndex: sets the file that Apache will serve if a directory

# Is requested.

# DirectoryIndex index.html

DirectoryIndex index. php index.html index.shtml index. cgi


# If the AddEncoding directives abve are commented-out, then you

# Probably shoshould define those extensions to indicate media types:


AddType application/x-compress. Z

AddType application/x-gzip. gz. tgz

AddType application/x-httpd-php. php. phtml

AddType application/x-httpd-php-source. phps

4.7 restart apache after modification.

PHP installation reference: http://dan.drydog.com/apache2php.html

5. Problems and Solutions 5.1 error: libpng. (a | so) not found.

Symptom description:

When compiling apache, the following message is displayed:

Checking for flograding... yes

If configure fails try -- with-jpeg-dir =

Configure: error: libpng. (a | so) not found.


The above search actually shows some reasons. The configure general search compilation path is/usr/lib, because php searches for the relevant library files under/usr/lib/by default, and the x64 machine is on: /usr/lib64. then you can directly copy the required library files from/usr/lib64 to/usr/lib.

Remember to execute the following command before configure:

Cp-frp/usr/lib64/libjpeg. */usr/lib/

5.2 error: Cannot find MySQL header files under yes

Symptom description:

When compiling apache, the following message is displayed:

Checking for specified location of the MySQL UNIX socket... no

Configure: error: Cannot find MySQL header files under yes.

Note that the MySQL client library is not bundled anymore!


This lacks the mysql-devel installation package, rpm? Ivh installs the devel package, as mentioned above.

5.3 similarities and differences between mysql-server, mysql-devel, and mysql-client

Original English version:

In most cases, you only need to install the MySQL-server and MySQL-client packages to get a functional MySQL installation. the other packages are not required for a standard installation. if you want to run a MySQL-Max server that has additional capabilities, you shoshould also install the MySQL-Max RPM. however, you shoshould do so only after installing the MySQL-server RPM.

If you get a dependency failure when trying to install the MySQL 4.0 packages (for example, ''error: removing these packages wocould break dependencies: libmysqlclient. so.10 is needed... ''), you shoshould also install the package MySQL-shared-compat, which between Des both the shared libraries for backward compatibility (libmysqlclient. so.12 for MySQL 4.0 and libmysqlclient. so.10 for MySQL 3.23 ).

The following RPM packages are available:

MySQL-server-VERSION.i386.rpm The MySQL server. you will need this unless you only want to connect to a MySQL server running on another machine. note: Server RPM files were called MySQL-VERSION.i386.rpm before MySQL 4.0.10. that is, they did not have-server in the name.

MySQL-Max-VERSION.i386.rpm The MySQL-Max server. this server has additional capabilities that the one provided in the MySQL-server RPM does not. you must install the MySQL-server RPM first, because the MySQL-Max RPM depends on it.

MySQL-client-VERSION.i386.rpm The standard MySQL client programs. You probably always want to install this package.

MySQL-bench-VERSION.i386.rpm Tests and benchmarks. Requires Perl and the DBD: mysql module.

MySQL-devel-VERSION.i386.rpm The libraries and include files that are needed if you want to compile other MySQL clients, such as the Perl modules.

MySQL-shared-VERSION.i386.rpm This package contains the shared libraries (libmysqlclient. so *) that certain libraries ages and applications need to dynamically load and use MySQL.

MySQL-shared-compat-VERSION.i386.rpm This package has DES the shared libraries for both MySQL 3.23 and MySQL 4.0. install this package instead of MySQL-shared if you have applications installed that are dynamically linked against MySQL 3.23 but you want to upgrade to MySQL 4.0 without breaking the library dependencies. this package has been available since MySQL 4.0.13.

MySQL-embedded-VERSION.i386.rpm The embedded MySQL server library (from MySQL 4.0 ).

MySQL-VERSION.src.rpm This contains the source code for all of the previous packages. It can also be used to rebuild the RPMs on other ubuntures (for example, Alpha or iSCSI ).

Chinese translation:

MySQL-VERSION.i386.rpm MySQL server. Unless you just want to connect to the MySQL server running on another machine, you will need it.

MySQL-client-VERSION.i386.rpm standard MySQL client program. You may always need to install this package.

MySQL-bench-VERSION.i386.rpm testing and benchmarking procedures. Perl and msql-mysql-modules RPM are required.

Library and inclusion files required by the MySQL-devel-VERSION.i386.rpm. If you want to compile other MySQL client programs, such as the Perl module.

The MySQL-VERSION.src.rpm contains the source code for all of the above packages. It can also be used to try to construct RPM (for example, Alpha or iSCSI) for other hardware platforms ).

View all files in an RPM Package:

Shell>; rpm-qpl MySQL-VERSION.i386.rpm

Run the following command to implement a standard minimum installation:

Shell>; rpm-I MySQL-VERSION.i386.rpm MySQL-client-VERSION.i386.rpm

5.4 error: Cannot find libmysqlclient under/usr

Symptom description:

Error: Cannot find libmysqlclient under/usr


In fact, the solution is the same as that of solution 5.1. Copy/usr/lib64/mysql to/usr/lib /.

5.5 CMS directory permissions

Symptom description:

After entering the install page, the system prompts that some directories do not have the read and write permissions, as shown below:


Directory name read permission write permission

/[√] Read [X] write ----/usr/local/apache/htdocs/uploads

/Plus/* [√] read [X] write

/Dede/* [√] read [X] write

/Data/* [√] read [√] write

/A/* [√] read [√] write

/Install [√] read [√] write

/Special [√] read [√] write

/Uploads/* [√] read [√] write


When installing CMS, the system prompts that the permission is insufficient and you need to modify the uploads directory permission.

Chmod 777 uploads-R

5.6 Deprecated: Function ereg_replace () is deprecated

Note: dedecms 5.6 and later versions have flaws in php5.3 support! If php5.3 is used, after cms is successfully installed, the system background page will prompt "Deprecated: Function ereg_replace () is deprecated after the installation is complete .... ".

There are two solutions: See section 5th.


Due to technical habits, dedecms may have some errors in php support for php5.3 or later versions. you can open the file dede/config. php.

Find define ('destadmin', ereg_replace ("[//] {1,}", '/', dirname (_ FILE __)));

There is no need to delete it. just add "//" in front of this sentence to hide it, and then add a sentence below

Define ('destadmin', strtr (dirname (_ FILE __),'///','//'));

That's it! Upload overwrite and update the file to check whether the problem is solved!


Download the php5.2 package again. In fact, it is not difficult to use this method, that is, re-compile it, but it is the most direct way to solve the problem. To prevent further problems, I used php5.2 to re-compile it.

The preceding regular expression is interpreted as follows:

In a regular expression, the backslash usually forms a special structure together with other characters. for example, '/D' is used to match digit characters, and'/S' is used to match blank characters, '/1' is used to reverse reference the text captured by the first group.

However, if we only need to represent the backslash character in a regular expression, what should we do?

In fact, the regular expression handles this problem in the same way as the string, that is, in the regular expression, the escape sequence '//' must be used to represent a single backslash.

This rule brings about an interesting problem: the backslash characters that appear separately in the regular expression must be expressed by the escape sequence '//' at the regular expression level. However, each backslash must be expressed by an escape sequence '//' in a string that represents a regular expression. Therefore, four backslash '//' must be written in the string to correspond to a single backslash character in the regular expression: at the string processing level, they are recognized as two backslash '/'. at the regular expression level, they are recognized as a single backslash character '/'.

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.