STEP1: Disable Selinux
vi /etc/sysconfig/selinux
SELINUX=enforcing
Changes to
SELINUX=disabled
After done setting disabled for selinux, reboot your server with below command.
reboot
Step 2: Install mysql-server on Centos 7
sudo yum update sudo yum install wget wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update sudo yum install mysql-server sudo systemctl start mysqld
Make sure that mysql is running with below command.
netstat -ntulp
you will see something result like below.
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3169/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1269/master
tcp6 0 0 :::3306 :::* LISTEN 21869/mysqld
Enable for auto startup mysql when you fire up your machines.
systemctl enable mysqld
Step2: Configure your mysql server
Set passwords for the MySQL root account:
mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, 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): OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] <-- ENTER New password: <-- yourrootsqlpassword Re-enter new password: <-- yourrootsqlpassword Password updated successfully! Reloading privilege tables.. ... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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] <-- ENTER ... 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] <-- ENTER ... Success!
By default, MySQL 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] <-- ENTER - 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] <-- ENTER ... Success! Cleaning up...
All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Step 3: Install web server (HTTPD)
yum install httpd -y systemctl enable httpd systemctl start httpd
use below command to verify that your web server is on.
netstat -ntulp |grep 80
You will get something result similar to this.
tcp6 0 0 :::80 :::* LISTEN 22011/httpd
Now direct your browser to http://your_ip_address, and you should see the Apache2 placeholder page:
if you cant get this page, please make sure you have allow port 80 in your iptables.
otherwise please run below command to flush the default iptables rules.
iptables -F
and try again with your ip address on web browser.
If still cant open please make sure you have really disabled the selinux, you can confirm with below command
getenforce
you should see something that like this
Disabled
Step 4 : Install php
Installing PHP 7 on CentOS 7
1. To install PHP 7, you have to install and enable EPEL and Remi repository on your CentOS 7 system with the commands below.
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm # yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
2. Next, you need to install yum-utils, a collection of useful programs for managing yum repositories and packages. It has tools that basically extend yum’s default features.
It can be used for managing (enabling or disabling) yum repositories as well as packages without any manual configuration and so much more.
# yum install yum-utils
3. One of the programs provided by yum-utils is yum-config-manager, which you can use to enable Remi repository as the default repository for installing different PHP versions as shown.
# yum-config-manager --enable remi-php70 [Install PHP 7.0]
If you want to install PHP 7.1, PHP 7.2 or PHP 7.3 on CentOS 7, just enable it as shown.
# yum-config-manager --enable remi-php71 [Install PHP 7.1] # yum-config-manager --enable remi-php72 [Install PHP 7.2] # yum-config-manager --enable remi-php73 [Install PHP 7.3]
4. Now install PHP 7 with all necessary modules with the command below.
yum -y install php
We must restart Apache afterwards:
systemctl restart httpd
5 Testing PHP5 / Getting Details About Your PHP Installation
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://your_ipaddress/info.php):
Step 5: Getting MySQL Support In PHP
To get MySQL support in PHP, we can install the php-mysql package.
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-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy curl curl-devel
Now restart httpd:
systemctl restart httpd
S
To create a virtual host for a specific website open your editor of choice and create the following basic Virtual Host configuration file:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@example.com
DocumentRoot /var/www/example.com/public_html
<Directory /var/www/example.com/public_html>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
ErrorLog /var/log/httpd/example.com-error.log
CustomLog /var/log/httpd/example.com-access.log combined
</VirtualHost>