Install and configure LAMP in Centos (Linux + Apache + MySQL + PHP)

Source: Internet
Author: User


Install and configure LAMP (Linux + Apache + MySQL + PHP) in Centos. For more information about LAMP, see Baidu Google, today, we will introduce how to install a web server in Centos. First, let's talk about my host and network environment: the host system is win7, the virtual machine is installed under win7, And the Centos is in the virtual machine. The Network Mode of virtual machines is NAT, and the host network is a campus network. You need account authentication to access the Internet. Www.2cto.com
There are two ways to install software in Centos. The first is to use the yum command to automatically install the software. The installed software has a fixed location and a fixed directory. The second is to download the source code installation package, manually decompress, configure, compile, and install the tool. During installation, you can select the installation directory and path. Here, I chose the first installation method, which is relatively convenient. Although it lacks flexibility, it is enough for the test phase. Step 1: configure the firewall (by default, ports 80 and 3306 are access denied and configured on the firewall ): [cpp] vi/etc/sysconfig/iptables (Add the following two sentences to the previous line of "COMMIT) -a input-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT (allow port 80 to pass through the firewall) -a input-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT (allow port 3306 to pass the firewall)
Restart the firewall to make the configuration take effect: [cpp]/etc/init. d/iptables restart Step 2: install Apache by running the following command: [cpp] yum install httpd if the following statement is displayed, it indicates that Apache has been installed, no need to reinstall:

After installation, restart Apache:/etc/init. d/httpd restart: Set Apache to boot: chkconfig httpd on. (In this step, you do not need to manually start the httpd service every time you restart the server.) to view the startup status of the httpd service, run the following command: step 3: Install MySQL
1. Run the following command to install MySQL: [cpp] yum install mysql-server. If a prompt is displayed that MySQL is installed, skip this step, otherwise, the system will automatically install MySQL. After installing www.2cto.com, start MySQL:/etc/init. d/mysql start set MySQL to boot start: chkconfig mysqld on, and finally copy the configuration file: cp/usr/share/mysql/my-medium.cnf/etc/my. cnf (there is a my under/etc. the cnf file can be overwritten directly)
2. Run the following command to set the password for the root account [cpp] mysql_secure_installation. Enter the password twice as prompted. Note: During the configuration process, you will be prompted to delete the anonymous user, whether to reject the root remote access, and whether to delete the database used for testing. You need to select the database based on your actual situation. Thanks for using MySQL !, The password is successfully set. Restart MySQL:/etc/init. d/mysqld restart
Step 4: install PHP1 and run the following command to install PHP: [cpp] yum install php. Follow the prompts to install it. Restart Apache:/etc/init. d/httpd restart after installation.
2. Install the PHP component. If PHP supports MySQL, run the following command: yum search php to view the PHP component. Select the required module for installation: yum install php-mysql php-gd libjpeg * php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash after libmcrypt is installed, restart Apache:/etc/init. d/httpd restart MySQL:/etc/init. d/mysqld restart to this step. The Ampersand in LAMP has been installed, but the web server cannot be accessed at this time, because you want to access the server, you also need to configure Apache and PHP. Step 1: Configure Apache to modify the Apache configuration file vi/etc/httpd/conf/httpd. conf, find the following row in the file, and modify it. (You can enter "/the character to be searched" in the general mode of vi for search.): ServerTokens OS is changed: serverTokens Prod (the name of the server operating system is not displayed when an error page appears) www.2cto.com ServerSignature On is changed to ServerSignature Off (Apache version is not displayed On the error page) options Indexes FollowSymLinks is changed to: Options shortdes ExecCGI FollowSymLinks (allows the server to execute CGI and SSI, and prohibits the list of directories) # AddHandler cgi-script. modify cgi to AddHandler cgi-script. cgi. pl (allowed Extension. run the CGI script of pl) AllowOverride None to: AllowOverride All (allowed. modify AddDefaultCharset UTF-8 to: adddefadefacharset GB2312 (add GB2312 as the default encoding) Options Indexes MultiViews FollowSymLinks to Options MultiViews FollowSymLinks (tree directory structure not displayed on the browser) DirectoryIndex index.html. var: DirectoryIndex index.html index.htm Default.html Default.htm index. php Default. php index.html. var (set the default homepage file and add index. php) Modify KeepAlive Off to: KeepAlive On (allow procedural online) MaxKeepAliveRequests 100 to: MaxKeepAliveRequests 1000 (increase concurrent connections), save the configuration, and restart Apache: /etc/init. d/httpd restart it is recommended to delete the default test page: rm-f/etc/httpd/conf. d/welcome. conf/var/www/error/noindex.html
Step 2: Configure PHP and modify the PHP configuration file vi/etc/php. ini, you can use the vi SEARCH Command to find the location of the following lines to be modified: date. timezone = PRC www.2cto.com # Remove the semicolon and change it to date. timezone = region = passthru, exec, system, chroot, scandir, chgrp, chown, shell_exec, proc_open, proc_get_status, ini_alter, ini_alter, ini_restore, dl, openlog, syslog, readlink, symlink, popepassthru, stream_socket_server, escapeshellcmd, dll, popen, disk_free_space, checkdnsrr, checkdnsrr, getser Vbyname, getservbyport, region, upper, lower, posix_getgrnam, posix_getgroups, posix_getlogin, lower, lower, posix_getpid, lower, posix_getpwnam, posix_getpwuid, lower, posix_getsid, posix_getuid, posix_isatty, posix_kill, posix_mkfifo, posix_setegid, posix_seteuid, posix_setgid, p Osix_setpgid, posix_setsid, posix_setuid, posix_strerror, posix_times, posix_ttyname, posix_uname # list functions that can be disabled by PHP. If some programs need this function, delete it and disable it. Expose_php = Off # disable display of php version information display_errors = OFF # Disable Error prompt register_globals = OFF # disable registration of global variable magic_quotes_gpc = On # enable magic_quotes_gpc to prevent SQL Injection log_errors = On error Log
Error_log =/var/log/php/error_log.log # Set the directory where error logs are stored. The file must allow write permissions for apache users and groups. (Note that before modification, you must first create the file/var/log/php/error_log.log, and then modify its attributes so that it belongs to apache users and user groups. Chown apache/var/log/php/error_log.log and chgrp apache/var/log/php/error_log.log) open_basedir =. :/tmp/# indicates that access to the current directory (that is, the directory where the PHP script file is located) And/tmp/directory are allowed. This prevents php trojans from being installed and configured across sites, the web server has basically been set up and can be accessed. Test: Create a php file: vi index. php under the directory/var/www/html: cd/var/www/html <? Php www.2cto.com phpinfo ();?> Then, when entering the local address in the browser, you can access the index. php webpage file you just created. Note: The default program directory of apache is/var/www/html, where webpage files can be accessed. Make sure that the directory belongs to the user apache and User Group apache. The MySQL database directory is/var/lib/mysql written here, LAMP installation and configuration is complete, the browser only needs to enter the Server IP address or domain name, then you can access the webpage files on the server. Prepared by AI_Net

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.