This tutorial shows how you can install an Apache2 webserver on a CentOS 7.0 server with PHP5 support (mod_php) and MySQL support. LAMP is short for Linux, Apache, MySQL, PHP.php
In this tutorial I use the hostname server1.example.com with the IP address 192.168.0.100. These settings might differ for you, so you have to replace them where appropriate. html
I will add EPEL-7 repo here to install latest phpMyAdmin as follows:mysql
rpm -ivh http://dl.fedoraproject.org/pub/epel/beta/7/x86_64/epel-release-7-0.2.noarch.rpmweb
To install MySQL, we do install mariadb like this:sql
yum -y install mariadb-server mariadbapache
Then we create the system startup links for MySQL (so that MySQL starts automatically whenever the system boots) and start the MySQL server:centos
systemctl start mariadb.service
systemctl enable mariadb.servicecookie
Set passwords for the MySQL root account:app
mysql_secure_installationcurl
[root@server1 ~]# mysql_secure_installationCentOS 7.0 ships with apache 2.4. Apache2 is directly available as a CentOS 7.0 package, therefore we can install it like this:
yum -y install httpd
[root@server1 ~]# yum install httpdBy default apache will be installed, if-not then please install it as shown above
Now configure your system to start Apache at boot time...
systemctl start httpd.service
systemctl enable httpd.service
In CentOS 7.0 uses Firewall-cmd, so I will customize it to allow external access to port 80 (http) and 443 (https).
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
Now direct your browser to http://192.168.0.100, and you should see the Apache2 placeholder page:
We can install PHP5 and the Apache PHP5 module as follows:
yum -y install php
We must restart Apache afterwards:
systemctl restart httpd.service
The document root of the default web site is /var/www/html. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.
vi /var/www/html/info.php
<?php phpinfo(); ?> |
Now we call that file in a browser (e.g. http://192.168.0.100/info.php):
As you see, PHP5 is working, and it's working through the Apache 2.0 Handler, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don't have MySQL support in PHP5 yet.
To get MySQL support in PHP, we can install the php-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:
yum search php
Pick the ones you need and install them like this:
yum -y install php-mysql
In the next step I will install some common PHP modules that are required by CMS Systems like Wordpress, Joomla and Drupal:
yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
Now restart Apache2:
systemctl restart httpd.service
Now reload http://192.168.0.100/info.php in your browser and scroll down to the modules section again. You should now find lots of new modules like curl etc there.:
phpMyAdmin is a web interface through which you can manage your MySQL databases.
phpMyAdmin can now be installed as follows:
yum install phpMyAdmin
Now we configure phpMyAdmin. We change the Apache configuration so that phpMyAdmin allows connections not just from localhost (by commenting out the <Directory "/usr/share/phpmyadmin"> stanza):
vi /etc/httpd/conf.d/phpMyAdmin.conf
[...] |
Next we change the authentication in phpMyAdmin from cookie to http:
vi /etc/phpMyAdmin/config.inc.php
[...] $cfg['Servers'][$i]['auth_type'] = 'http'; // Authentication method (config, http or cookie based)? [...] |
Restart Apache:
systemctl restart httpd.service
Afterwards, you can access phpMyAdmin under http://192.168.0.100/phpmyadmin/:
Apache: http://httpd.apache.org/
PHP: http://www.php.net/
MySQL: http://www.mysql.com/
CentOS: http://www.centos.org/
phpMyAdmin: http://www.phpmyadmin.net/
refer: https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp