Install LAMP would be the basic skill for a Linux admin.
Step 1: Install Apache Server with Basic Configurations
1. After performing a minimal system installation and configure your server network interface with a Static IP Address on RHEL/CentOS 7.0, go ahead and install Apache 2.4 httpd service binary package provided form official repositories using the following command.
# yum install httpd
2. After yum manager finish installation, use the following commands to manage Apache daemon, since RHEL and CentOS 7.0 both migrated their init scripts from SysV to systemd – you can also use SysV and Apache scripts the same time to manage the service.
# systemctl status|start|stop|restart|reload httpd OR # service httpd status|start|stop|restart|reload OR # apachectl configtest| graceful
# firewall-cmd --add-service=http
NOTE: Make notice that using this rule will lose its effect after a system reboot or firewalld service restart, because it opens on-fly rules, which are not applied permanently. To apply consistency iptables rules on firewall use –permanent option and restart firewalld service to take effect.
# firewall-cmd --permanent --add-service=http # systemctl restart firewalld
# firewall-cmd --state # firewall-cmd --list-all # firewall-cmd --list-interfaces # firewall-cmd --get-service # firewall-cmd --query-service service_name # firewall-cmd --add-port=8080/tcp
4. To verify Apache functionality open a remote browser and type your server IP Address using HTTP protocol on URL (http://server_IP),
Step 2: Install PHP5 Support for Apache
1. Before installing PHP5 dynamic language support for Apache, get a full list of available PHP modules and extensions using the following command.
# yum search php
2. Depending on what type of applications you want to use, install the required PHP modules from the above list, but for a basic MariaDB support in PHP and PhpMyAdmin you need to install the following modules. This may install the legacy php5.4
yum install php php-mysql php-pdo php-gd php-mbstring
3. Let the Apache handle the php properly:
# Create a backup of your original Apache configuration sudo cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.original #remove the white space at the beginning of each line sudo sed -i -e 's/^[ \t]*//' /etc/httpd/conf/httpd.conf #Load config files in the "/etc/httpd/conf.d" directory, if any sudo sed -i "s|IncludeOptional|#IncludeOptional|" /etc/httpd/conf/httpd.conf # ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. sudo sed -i "s|#ServerName www.example.com:80|ServerName localhost|" /etc/httpd/conf/httpd.conf # DirectoryIndex: sets the file that Apache will serve if a directory is requested. # This actually allows you to specify a default page to display when a directory is accessed. sudo sed -i "s|DirectoryIndex index.html|DirectoryIndex index.html index.php|" /etc/httpd/conf/httpd.conf # Add PHP configuration into Apache echo "AddType application/x-httpd-php .php" | sudo tee -a /etc/httpd/conf/httpd.conf
To get a full information list on PHP from your browser, create a info.php file on Apache Document Root using the following command from root account, restart httpd service and direct your browser to the http://server_IP/info.php address.
# echo "<?php phpinfo(); ?>" > /var/www/html/info.php # systemctl restart httpd
4. If you get an error on PHP Date and Timezone, open php.ini configuration file, search and uncomment date.timezone statement, append your physical location and restart Apache daemon.
# vi /etc/php.ini
Locate and change date.timezone line to look like this, using PHP Supported Timezones list.
date.timezone = Continent/City
Step 3: Install and Configure MariaDB Database
1. Red Hat Enterprise Linux/CentOS 7.0 switched from MySQL to MariaDB for its default database management system. To install MariaDB database use the following command.
# yum install mariadb-server mariadb
2. After MariaDB package is installed, start database daemon and use mysql_secure_installation script to secure database (set root password, disable remotely logon from root, remove test database and remove anonymous users).
# systemctl start mariadb # mysql_secure_installation
3. To test database functionality login to MariaDB using its root account and exit using quit statement.
mysql -u root -p MariaDB > SHOW VARIABLES;
At this point, the LAMP stack is setup and ready to use, let’s take the popular wordpress as example:
- we can create a new database called WP_DB:
CREATE DATABASE WP_DB
- Create a new user and grant it the full access to the new WP_DB:
CREATE USER 'WP_ADMIN'@'localhost' IDENTIFIED BY '[email protected]';
GRANT ALL PRIVILEGES ON WP_DB.* to [email protected]; #Make the privileges effective: FLUSH PRIVILEGES;
SHOW GRANTS FOR 'WP_ADMIN'@'localhost';
- Download WordPress package:
sudo mkdir ~/tmp cd ~/tmp wget https://en-au.wordpress.org/wordpress-4.9.8-en_AU.tar.gz tar -zxvf wordpress-4.9.8-en_AU.tar.gz mv wordpress /var/www/html/wordpress cd /var/html/wordpress sudo cp wp-config-sample.php wp-config.php sudo vi wp-config.php
find following lines:
/** The name of the database for WordPress */
/** MySQL database username */
/** MySQL database password */
define(‘DB_PASSWORD’, ‘[email protected]’);
- Now from another computer open a browser, type the following as url: “IP_of_LAMP_host/wordpress ” , you should see the wordpress installation page.
If you find it struggle to use the Mysql command, you can install the PHPMYADMIN to create a user, DB from a GUI.
STEP 4 (optional): Install Phpmyadmin
Option 1, install from Repo:
How To Enable EPEL Repository in RHEL/CentOS 7/6/5?
First, you need to download the file using Wget and then install it using RPM on your system to enable the EPEL repository. Use below links based on your Linux OS versions. (Make sure you must be root user).
RHEL/CentOS 7 64 Bit
## RHEL/CentOS 7 64-Bit ## # wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm # rpm -ivh epel-release-latest-7.noarch.rpm
RHEL/CentOS 6 32-64 Bit
## RHEL/CentOS 6 32-Bit ## # wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm # rpm -ivh epel-release-6-8.noarch.rpm ## RHEL/CentOS 6 64-Bit ## # wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm # rpm -ivh epel-release-6-8.noarch.rpm
Use below command to see the installed repo:
Then install the remi-release 7
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Install phpmyadmin with remi enabled:
yum --enablerepo=remi install phpmyadmin
Apache you don’t need to configure anything for phpMyAdmin, because you will get working phpMyAdminautomatically at the address
Suggested Read: MySQL Backup and Restore Commands for Database Administration
The main configuration file is located under /etc/httpd/conf.d/phpMyAdmin.conf, make sure the Require all granted directive (For Apache 2.4) and Allow from ip address is added inside the Directory
Finally, restart Apache to apply changes.
-------------- On RHEL/CentOS 7 and Fedora 28-24 -------------- # systemctl restart httpd -------------- On RHEL/CentOS 6 -------------- # service httpd restart
Nginx web server, we will create a symbolic link to PhpMyAdmin installation files to our Nginx web document root directory (i.e. /usr/share/nginx/html) by running the following command:
# ln -s /usr/share/phpMyAdmin /usr/share/nginx/html
Finally, restart Nginx and PHP-FPM to apply changes.
-------------- On RHEL/CentOS 7 and Fedora 28-24 -------------- # systemctl restart nginx # systemctl restart php-fpm -------------- On RHEL/CentOS 6 -------------- # service nginx restart # service php-fpm restart
Option 2, install from package
Download the tar ball from https://www.phpmyadmin.net/downloads/, choose the one end with tar.gz. copy the url, past to the putty to download.
Extract package rename the folder to phpMyadmin and move to the /var/www/html.
edit the file: /var/www/html/phpMyAdmin/config.inc.php
By defaulty it is not there, we can create on by duplicate the config.sample.inc.php file:
cd /var/www/html/phpMyAdmin/ cp config.sample.inc.php config.inc.php sudo vi config.inc.php
Then edit the below line:
$cfg['blowfish_secret'] = 'abcdefghijklmnopqrstuvwxyz1234567'; /*Change abcdefghijklmnopqrstuvwxyz1234567 into your 32 chars long */
Now the PhpMyAdmin is ready to use.
Accessing PhpMyAdmin Web Interface
Open your browser and point your browser to
http://<ip address>/phpmyadmin. It should open the phpmyadmin interface, type root as the user name and password you created in mysql_secure_installation.
Install FTP for the webserver
It would be convenient to install the FTP service on the Webserver as well, see below page for FTP installation: