First install Apache2
Just one command:
yum -y install httpd
After pressing Enter, yum will prompt the currently installed version of httpd and update it automatically; if it is not installed, it will automatically Install. Note to enter "Y" during the yum installation process to confirm the installation.
After the Apache installation is completed, manually start Apache2:
/etc/init.d/httpd start
At this time, directly enter the IP address of the server in the browser, and you will see the default page of Apache2. At this time, Apache can only provide HTTP services, cannot execute PHP, and cannot connect to the MySQL database.
Install MySQL
Since MySQL is already included in CentOS, you only need yum:
yum -y install mysql mysql-server
After completion, use the following command to start the MySQL service :
/etc/init.d/mysqld start
Install php5
Use the following command to install php5:
yum install php
After installing php5, you must restart Apache to Make php take effect:
/etc/init.d/httpd restart
At this time, Apache can parse and execute the php script. Since the default website root directory of Apache is located at: /var/www/html/, create an info.php in this directory to test whether Apache+PHP is correctly installed:
vi
Then access /info.php in the browser, and the output information of PHPINFO appears:
PHP and Apache have been installed correctly.
Next install the MySQL database and other modules (such as GD graphics library, mbstring library, etc.):
yum -y install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
The installation process may be slow, please be patient. After completion, restart Apache again:
/etc/init.d/httpd restart
Re-open the IP/info.php page in the browser, you should be able to find MySQL, GD, mbstring and other modules:
At this time, the LAMP operating environment has been initially installed. Finally, you need to set the LAMP component to start automatically:
1
chkconfig --levels 2345 httpd on
2
chkconfig --levels 2345 mysqld on
Finally, the relevant configuration and Environment
Apache main configuration file: /etc/httpd/conf/httpd.conf
Apache main configuration directory. Different types of configurations can be classified into this directory: /etc/httpd/conf.d/
Apache website root directory: /var/www/html/
Apache log file directory: /var/log/httpd
MySQL my.cnf configuration file: /etc/my.cnf
MySQL database File location:/usr/lib/mysql