Build a LAMP environment in CentOS
1. Install MySQL
The installation of MySQL is usually based on the source code package. However, it takes a long time to compile the MySQL package.
MySQL official website download: http://dev.mysql.com/downloads/
Sohu image site download: http://mirrors.sohu.com/
1. Download the mysql package to/usr/local/src/
[root@tpp~]#cd/usr/local/src/[root@tppsrc]#wgethttp://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-i686-glibc23.tar.gz
2. Decompress
[root@tppsrc]#tar-zxvf/usr/local/src/mysql-5.1.73-linux-i686-glibc23.tar.gz
3. Move the extracted data to/usr/local/mysql.
[root@tppsrc]#mvmysql-5.1.73-linux-i686-glibc23/usr/local/mysql
4. Create a MySQL user
[root@tppsrc]#useradd-s/sbin/nologinmysql
5. initialize the database
[Root @ tppsrc] # cd/usr/local/mysql [root @ tppmysql] # mkdir-p/data/mysql // create datadir, the database file will be stored here [root @ tppmysql] # chown-Rmysql/data/mysql // change the permission [root @ tppmysql] #. /scripts/mysql_install_db -- user = mysql -- datadir =/data/mysql // -- user defines the database master, -- datadir defines the database installation directory
6. Copy the configuration file
[root@tppmysql]#cpsupport-files/my-large.cnf/etc/my.cnf
7. Copy the startup script and modify its attributes.
[root@tppmysql]#cpsupport-files/mysql.server/etc/init.d/mysqld[root@tppmysql]#chmod755/etc/init.d/mysqld
8. Modify the Startup Script
[Root @ tppmysql] # vim/etc/init. d/mysqld // enter and modify the following two places: basedir =/usr/local/mysqldatadir =/data/mysql
9. Add the startup script to the system service items, set the startup to start mysql
[root@tppmysql]#chkconfig--addmysqld[root@tppmysql]#chkconfigmysqldon[root@tppmysql]#servicemysqldstart
If it cannot be started, you can view the error log in the/data/mysql/directory. The log is usually the host name. err. The command to check whether MySQL is started is ps aux | gerp mysqld.
Ii. install Apache
Apache official: http://www.apache.org/dyn/closer.cgi
Sohu image site: http://mirrors.sohu.com/
1. Download the httpd package to/usr/local/src/
[root@tppmysql]#cd/usr/local/src/[root@tppsrc]#wgethttp://mirrors.sohu.com/apache/httpd-2.2.31.tar.bz2
2. Decompress
[root@tppsrc]#tar-jxvfhttpd-2.2.31.tar.bz2
3. Configure compilation Parameters
[root@tppsrc]#cdhttpd-2.2.31[root@tpphttpd-2.2.31]#./configure\--prefix=/usr/local/apache2\--with-included-apr\--enable-so\--enable-deflate=shared\--enable-expires=shared\--enable-rewrite=shared\--with-pcre
Here -- prefix specifies the directory to be installed, -- enable-so indicates that DSO is enabled, and -- enable-deflate = shared indicates that deflate is compiled in a shared manner. The following parameters are the same.
4. Compile
[root@tpphttpd-2.2.31]#make
5. Installation
[root@tpphttpd-2.2.31]#makeinstall
Echo $? Can be used for all the preceding steps? To check whether the execution is correct. 0 indicates that the execution is successful.
If an error occurs during installation, refer to the http://1015489314.blog.51cto.com/8637744/1688271
3. install PHP
PHP official: http://www.php.net/downloads.php
Sohu image site: http://mirrors.sohu.com/php/php-5.3.27.tar.gz
1. Download the php package to/usr/local/src/
[root@tpphttpd-2.2.31]#cd/usr/local/src/[root@tppsrc]#wgethttp://mirrors.sohu.com/php/php-5.3.27.tar.gz
2. Decompress
[root@tppsrc]#tar-zxvfphp-5.3.27.tar.gz
3. To prevent PHP parsing failures after compilation, install the required software or library files first (99% will be successful)
[root@tppsrc]#yuminstall-ygccgcc-c++makezlibzlib-develpcrepcre-devellibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develglibcglibc-develglib2glib2-develbzip2bzip2-develncursesncurses-develcurlcurl-devele2fsprogse2fsprogs-develkrb5krb5-developensslopenssl-developenldapopenldap-develnss_ldapopenldap-clientsopenldap-serverslibtoollibtool-ltdl-devel[root@tppsrc]#rpm-ivh"http://www.aminglinux.com/bbs/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm"[root@tppsrc]#yuminstall-ylibmcrypt-devel
4. Configure compilation Parameters
[Root @ tppsrc] # cdphp-5.3.27 [root @ tppsrc] # useradd-s/sbin/nologinphp-fpm // can omit [root@tppphp-5.3.27] #. /configure \ -- prefix =/usr/local/php \ -- with-apxs2 =/usr/local/apache2/bin/apxs \ -- with-config-file-path =/usr/local /php/etc \ -- with-mysql =/usr/local/mysql \ -- with-libxml-dir \ -- with-gd \ -- with-jpeg-dir \ -- with-png -dir \ -- with-freetype-dir \ -- with-iconv-dir \ -- with-zlib-dir \ -- with-bz2 \ -- with-openssl \ -- with-mcrypt \ -- enable- soap \ -- enable-gd-native-ttf \ -- enable-mbstring \ -- enable-sockets \ -- enable-exif \ -- disable-ipv6
4. Compile
[root@tppphp-5.3.27]#make
5. Installation
[root@tppphp-5.3.27]#makeinstall
6. Copy the configuration file
[root@tppphp-5.3.27]#cpphp.ini-production/usr/local/php/etc/php.ini
If an error occurs during installation, refer to the http://1015489314.blog.51cto.com/8637744/1688284
4. Combining Apache with PHP
Edit Apache's main configuration file:/usr/local/apache2/conf/httpd. conf
[root@tpp~]#vim/usr/local/apache2/conf/httpd.conf
① First find:
AddTypeapplication/x-gzip.gz.tgz // Add the following line below it: AddTypeapplication/x-httpd-php.php
② Find again:
<IfModuledir_module>DirectoryIndexindex.html</IfModule>
Changed:
<IfModuledir_module>DirectoryIndexindex.htmlindex.htmindex.php</IfModule>
③ Finally, find:
#ServerNamewww.example.com:80
Changed:
ServerNamelocalhost:80
5. Test whether LAMP is successful
After installing Apache, MySQL, and PHP, you must first check whether the Apache configuration file is correct to parse the PHP file correctly.
1. test whether the configuration file is correct.
① Before starting Apache, check whether the configuration file is correct, as shown below:
[root@tpp~]#/usr/local/apache2/bin/apachectl-t
(If an error occurs, continue to modify httpd. conf. If yes, "Syntax OK" is displayed ")
② Start Apache:
[Root @ tpp ~] #/Usr/local/apache2/bin/apachectlstart // reload php: change start to graceful
③ Check whether the instance is started:
[Root @ tpp ~] # Netstat-lnp | grephttpdtcp00: 80 ::: * LISTEN7667/httpd // if this line is displayed, Apache has started
In addition, we can also use the curl command to perform a simple test:
[Root @ tpp ~] # Curllocalhost
2. Test whether PHP Parsing is correct
First, write a script as follows:
[Root @ tpp ~] # Vim/usr/local/apache2/htdocs/1.php<? Phpecho "php Parsing is normal";?>
Save the script and continue the test, as shown below:
[root@tpp~]#curllocalhost/1.php
Php Parsing is normal // if this line can be displayed, it indicates that php Parsing is correct.
In addition, we can use the phpinfo parameter to test the PHP interface:
[root@tpp~]#vim/usr/local/apache2/htdocs/info.php<?phpphpinfo();?>
Save the script and continue the test, as shown in:
Note: Sometimes the wab service cannot be accessed. Disable the firewall iptables-F
Solution for error during installation
Problems that may occur when installing Apache http://1015489314.blog.51cto.com/8637744/1688271
Http://1015489314.blog.51cto.com/8637744/1688284 errors that may occur when installing PHP