Quickly build a LAMP environment using CentOS
LAMP -- Linux Apache MySQL PHP
In the CentOS installation sequence, I usually choose Apache> MySQL> PHP
Step 1. install and configure Apache
1. Install using yum
[Plain] view plaincopy
- Yuminstallhttpd
2. Modify the firewall configuration and open port 80. You can also open port 3306 of MySQL [plain] view plaincopy
- Vi/etc/sysconfig/iptables
Add two records
[Plain] view plaincopy
- -AINPUT-mstate -- stateNEW-mtcp-ptcp -- dport80-jACCEPT
- -AINPUT-mstate -- stateNEW-mtcp-ptcp -- dport3306-jACCEPT
Add location, as shown in figure
3. Disable SELINUX.
[Plain] view plaincopy
- Vi/etc/selinux/config
Modify SELINUX = disabled
4. Apache configuration file
[Plain] view plaincopy
- Vi/etc/httpd/conf/httpd. conf
Find ServerName and set it to your own domain name. If there is no domain name, you can set it to localhost: 80.
5. Start Apache automatically upon startup
[Plain] view plaincopy
- Chkconfighttpdon
6. Restart Apache
[Plain] view plaincopy
- Servicehttpdrestart
7. Open the browser and enter the address to test
Step 2. install and configure MySQL
1. Install using yum
[Plain] view plaincopy
- Yuminstallmysqlmysql-server
2. Start MySQL automatically at startup
[Plain] view plaincopy
- Chkconfigmysqldon
3. Set the root password for MySQL
[Plain] view plaincopy
- Mysql_secure_installation
Enter y to set the password. After setting the password, press enter until Thanks for using MySQL appears!
4. Restart MySQL
[Plain] view plaincopy
- Servicemysqldrestart
Step 3: install and configure PHP
1. Install using yum
[Plain] view plaincopy
- Yuminstallphp
2. install PHP Components
[Plain] view plaincopy
- Yuminstallphp-mysqlphp-gdlibjpeg * php-imapphp-ldapphp-odbcphp-pearphp-xmlphp-xmlrpcphp-mbstringphp-mcryptphp-bcmathphp-mhashlibmcrypt
3. Restart Apache and MySQL
4. You can upload PHP files to the default code directory for testing. The default directory is/var/www/html. You can modify the path in the httpd. conf file.
* Then, you can configure Apache MySQL PHP based on your specific needs. The default configuration file path is as follows:
Apache configuration file path:/etc/httpd/conf/httpd. conf
MySQL configuration file path:/etc/my. cnf
PHP configuration file path:/etc/php. ini