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 PHP 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
How to install PHP 7.2 on CentOS 7
Turn on EPEL repo on a CentOS and RHEL 7.x sever by typing the following command:
$ sudo yum install epel-release
Turn remi repo too:
$ sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Install yum-utils packages too:
$ sudo yum install yum-utils
Enable remi repo, run:
$ sudo yum-config-manager --enable remi-php72
$ sudo yum update
Search for PHP 7.2 packages and modules with more command/grep command/egrep command:
$ sudo yum search php72 | more
$ sudo yum search php72 | egrep 'fpm|gd|mysql|memcache'
php72-php-fpm.x86_64 : PHP FastCGI Process Manager php72-php-gd.x86_64 : A module for PHP applications for using the gd graphics php72-php-mysqlnd.x86_64 : A module for PHP applications that use MySQL php72-php-pecl-mysql.x86_64 : MySQL database access functions php72-php-pecl-mysql-xdevapi.x86_64 : MySQL database access functions
Finally install php 7.2 on CentOS 7.2:
$ sudo yum install php72
You must install “PHP FastCGI Process Manager” called php72-php-fpm along with commonly used modules:
$ sudo yum install php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache
To make the 72 default installation:
$ scl enable php72 bash
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 # sudo mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): (default is blank, hit enter) OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure.
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 'P@ssw0rd';
GRANT ALL PRIVILEGES ON WP_DB.* to WP_ADMIN@localhost; #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 */
- 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:
Install apache Php7.2