How to set own ip address for localhost [on hold]

I have installed centos 7 i want work on Linux,Apache,Mysql,php(LAMP). Can any guide me how to set my own ip config to work


Just install the LAMP stack, thats the easy part (if you use a package manager) and don't want to compile from source.

sudo apt-get install php7.0 php-mysql

Now you will have a webserver listening on port 80 on any/all network interfaces it has. No additional work necessary here.
The tricky part is to make the requests on the website point back to the LAMP stack on your networked computer.
One way is to grab the IP address from within PHP, the only reliable way I know is to use a shell_exec() call to ifconfig or ip addr show <iface>, you could try something like
(substitute your network interface name where wlan0 appears , if your config is different).


// ...

// get ip adress
$ip_address = shell_exec("ip addr show wlan0 | grep 'inet\s' | awk '{ print $2; }' | sed 's/\/.*$//'");
define('BASE_URL', 'http://' . $ip_address . 'path/to/your_project/');

you now have a constant BASE_URl, which you can then insert into urls inside your PHP/HTML code. e.g.

        <a href="<?php echo "http://" . BASE_URL . "uri_you_want_to_load"; ?>

Any time one of these links is clicked on your website, it will generate a request back to the LAMP stack listening on your ip address $ip_address

One Of The Solution To Your Problem is to Bind An Ip Address To You Machine. To Do This.

  1. Go To Your Router's Setting
  2. Find For Address Reservation (Mostly Uder The DHCP Tab) Or Ip And Mac Binding Tab And Bind An IP To Your Device's(Local Host) IP.
  3. After Doing, Type That Ip into Browser's address Bar (assuming your server is running)

You Will See Your localhost is loaded Through That IP address. And You also can connect your localhost from LAN Using That IP Address.

I think you want to set a localhost such as, so you can doing PHP job on it. I can tell you what I have done;

  1. Get the Apache Software (such as httpd-X.X.X.tar.gz, I use source code) i)tar -zxvf httpd-x.x.x.tar.gz ii)cd httpd-x.x.x iii)./configure --prefix=/home/YOUR_PATH/local/httpd \ --sysconfdir=/home/YOUR_PATH/conf/httpd prefix is where you put the apache files, sysconfdir is where you put the config file iv) nohup make && make install 2>&1 &
  2. According to the 'sysconfdir' you have enter, change the parameter in conf/httpd Listen 8080 ServerName localhost:8080
  3. Get start Apache cd ~/PREFIX_PATH/httpd/bin ./httpd -k start curl locahost:8080 (so you can see it works!)

This is a simple example to config a valid IP to use. Have a Good Apache!

Category: linux Time: 2016-07-29 Views: 1

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.114 (s). 12 q(s)