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 :...
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.
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, 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) 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 # 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 in the directory/var/www/html: cd/var/www/html 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
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: 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.