百度智能云

All Product Document

          Cloud Compute Service

          Deploy the LAMP Environment in the Centos-7.2

          This document introduces how to build a LAMP environment by using the centos 7.2 system. centos7.2 builds a LAMP environement by following the steps below.

          1.Configure a Firewall

          The CentOS 7.0 system and higher uses the firewall by default

          Disable firewall:

          systemctl stop firewalld.service    #stop the firewall   
          systemctl disable firewalld.service      #Disable firewall startup  

          2. Install and Configure the Apache

          (1) You can use the yum source provided in BCC for the installation directly.

          yum install -y httpd

          (2) Start the httpd.

          systemctl start httpd

          (3) View and Access
          You can view that the port 80 is enabled through the command netstat -anplt. You can also open the apache default homepage of Apache by using the public IP.

          BCC-LAMP-01.png

          BCC-LAMP-02.png

          3. Install the PHP and Dependent Extension and Start the PHP

          (1) Install the PHP environment.

          yum install -y php

          (2) Install the extension options.

          yum install -y php-gd php-mysql libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt

          (3) Modify the Apache configuration file.

          You can view the default Apache configuration file through the command httpd -V: /etc/httpd/conf/httpd.conf

          BCC-LAMP-03.png

          vim /etc/httpd/conf/httpd.conf

          Add index.php after DirectoryIndexindex.php

          Add the following commands at the end of configuration file:

           LoadModule php5_module modules/libphp5.so
          
           AddType application/x-httpd-php .php

          BCC-LAMP-04.png

          (4) Restart the Apache and access the test.

          systemctl restart httpd

          Enter the default Apache root directory /var/www/html/, and write the phpinfo file.

          vim /var/www/html/test.php

           <?php
                   phpinfo();
           ?>

          At this time, you can see the following information through ip/index.php.

          image.png

          4. Install the Mysql and Connect to the PHP for Authentication

          (1) The default database is MariaDB for the centos7 system or higher, and you need to download the Mysql source for the installation.

          wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm  
          rpm -ivh mysql-community-release-el7-5.noarch.rpm  
          yum install -y mysql-community-server  

          Restart the Mysql service after the successful installation:
          systemctl start mysqld

          (2) The Mysql database is not set with the password after successful installation. You can access the database to authorize and set the password.

          mysql -u root  
          mysql> use mysql;  
          mysql> update user set password=PASSWORD("Enter the root user password here") where user='root';  
          mysql> flush privileges;  
          mysql> exit  

          (3) Write the PHP code to test whether Mysql can be connected and accessed.

          vim /var/www/html/index.php

          <?php  
          $link=mysql_connect("localhost","root"," the database password set just now.");  
          if(!$link) echo "FAILD!error";  
          else echo "OK!You succeeded.";  
          ?>  

          At this time, you can see the following information by IP/index.php

          At this point, the LAMP environment based on the centos7.2 is built successfully.

          Previous
          Deploy the LNMP Environment in the Centos-7.2
          Next
          Deploy the SSL Credential in the BCC-Nginx