Wednesday, October 24, 2018

Apache on CentOS 7

Apache on CentOS 7



Apache Installation And Hosting Multiple Sites on Centos 7


Video Title – Install Apache on CentOS 7 – Instale Apache en CentOS 7
Youtube upload Title – Install Apache on CentOS 7 -by-NCD0318H018
How To Install Apache on Centos 7
Step 1 : Enter the Below Command to Install Apache Server on Centos.
1
sudo yum install httpd
Step 2 : After Succesfully installing Apache  Make Changes in httpd.conf file.
1
Sudo vi /etc/httpd/conf/httpd.conf
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be “All”, “None”, or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
Change AllowOverride None to AllowOverride All
Step 3 : Now Enable the Apache Server,Check the Apache Server,Start the Apache if it is Not Active.
1
sudo systemctl enable httpd
1
sudo systemctl status httpd
1
sudo systemctl start httpd
Step 4 : Disable The Firewall as it blocks the Network Traffic and Apache Server will not Access the Brower. 
1
sudo firewall-cmd --permanent  --add-port=80/tcp
1
sudo firewall-cmd --permanent  --add-port=80/udp
1
sudo firewall-cmd --reload
Again Restart the Apache Server
1
sudo systemctl restart httpd
Now you are able to Access Apache on your browser on port number 80.
1
Your-ip:80
Step 5 : If We Want to Deploy Any Html File Then we have to Create one html file in Directory Root.
By Default Diretory Root Location Will be /var/www/html with any name.
1
sudo vi /var/ww/html/index.html
In order To access That Index.html File then enter in address bar
1
Your-ip:80
If You want to access the index of any folder,Then create a new Directory at Directory Root Location
1
sudo mkdir /var/www/html/Testing
Create Some Touch Files in  the Testing Directory
1
sudo touch /var/www/html/testing/file.text
1
sudo touch /var/www/html/testing/audio.mp3
1
sudo touch /var/www/html/testing/video.mp4
Access That from your web browser…
1
http://YOUR-IP/testing/

Video Title – How to install Apache MySQL and PHP in CentOS Linux
Youtube upload Title – How to install Apache MySQL and PHP in CentOS Linux -by-NCD0318H018
How To Install Mysql And Php on Cenots 7
Step 1: Download The Mysql and Supported Rpm Packages Throw the below given Link
1
wget <a href="http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm">http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm</a>
1
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
Now Update the packages so that if any updates are pending then they will get updated.
1
sudo yum update
Now Install Mysql.
1
sudo yum install mysql-server
Start the Mysql daemon service
1
sudo service mysqld start
Check wether mysql is in Active State or Not
1
sudo systemctl status mysql
Step 2 : Now,Secure MySql by Protecting by a password.
1
sudo /usr/bin/mysql_secure_installation
The Terminal Will Prompt as Specified below :
1 2 3 4 5 6 7
Set root password? [Y/n] Y New password: YourDesiredPassword Re-enter new password: YourDesiredPassword Remove anonymous user? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y
Mysql Has been Succesfully Installed and Secured with password !!!
Step 3 : Download and install the Php Module and php-mysql Module.
1
sudo yum install php php-mysql
Restart the Apache Services.
1
sudo service httpd restart
Step 4 : Now Make sure the Services are up at the boot time.
1
sudo chkconfig httpd on
1
sudo chkconfig mysqld on
Step 5 : Now Create a Index.php File at the Directory root
1
2
sudo vi /var/www/html/index.php
Paste the Below Code in index.php file.
1 2 3
&lt;?php phpinfo(); ?&gt;
The above code will display the Php version and info of php.
To access and check our index.php file
1
Your-ip/index.php
Both Mysql and php is Now Successfully Installed.

======================================================================================
Video Title – Host Multiple Sites using Apache Virtual Hosting on CentOS
Youtube upload Title – Host Multiple Sites using Apache Virtual Hosting on CentOs-By-NCD0318H018
Host Multiple Sites using Apache Virtual Hosting

Step 1: First Create two folders in the root Directory i.e., cd /var/www/html
1
sudo mkdir site1
1
sudo mkdir site2
Give Complete Permission to the Created Folders.
1
sudo chown apache:apache -R site1
1
sudo chown apache:apache -R site2
create Two Index.html files inside site1 and site2 and write some text in that files..
1
sudo vi site1/index.html
1
sudo vi site2/index.html
Create two folders in /etc/httpd folder with name Sites-available and sites-enabled.
1
sudo mkdir sites-available
1
sudo mkdir sites-enabled
step 2 : Now go to the httpd.Conf file and add IncludeOption sites-enabled/*.conf
1
sudo vi /etc/httpd/conf/http.conf

Add the below line at the end of the file
1
IncludeOption sites-enabled/*.conf
Create conf files for both site1 and site2 in sites-available folder.
1
sudo vi /etc/httpd/sites-available/site1.com.conf
<VirtualHost *:80>
ServerName www.site1.com
ServerAlias site1.com
DocumentRoot /var/www/html/site1
ErrorLog /var/www/html/site1/error.log
CustomLog /var/www/html/site1/requests.log combined
</VirtualHost>
1
sudo vi/etc/httpd/sites-available/site2.com.conf
<VirtualHost *:80> 
ServerName www.site2.com 
ServerAlias site2.com 
DocumentRoot /var/www/html/site2
ErrorLog /var/www/html/site2/error.log 
CustomLog /var/www/html/site2/requests.log combined 
</VirtualHost>
Step 3 : create soft links for both site1.com.conf and site2.com.conf
1
sudo ln -s /etc/httpd/sites-available/site1.com.conf /etc/httpd//sites-enabled/site1.com.conf
1
sudo ln -s /etc/httpd/sites-available/site2.com.conf /etc/httpd//sites-enabled/site2.com.conf
step 4 : Restart the Apache service
1
sudo service httpd restart
If Httpd Service started then evrything is fine if not then just disable Selinux and restart httpd service
1
sudo setenforce 0
1
sudo service httpd restart
step 5 : Goto hosts file and add the ip and server name.
1
sudo vi/etc/hosts
1
Your-IP site1.com
1
your-IP site2.com

Now you can able to access site1.com and site2.com on web browser.

No comments:

Post a Comment