MISTERY

jQuery.get()

Skill/Web2016.01.05 17:48

Description: Load data from the server using a HTTP GET request.

This is a shorthand Ajax function, which is equivalent to:

1
2
3
4
5
6
$.ajax({
url: url,
data: data,
success: success,
dataType: dataType
});

The success callback function is passed the returned data, which will be an XML root element, text string, JavaScript file, or JSON object, depending on the MIME type of the response. It is also passed the text status of the response.

As of jQuery 1.5, the success callback function is also passed a "jqXHR" object (in jQuery 1.4, it was passed the XMLHttpRequest object). However, since JSONP and cross-domain GET requests do not use XHR, in those cases the jqXHR and textStatus parameters passed to the success callback are undefined.

Most implementations will specify a success handler:

1
2
3
4
$.get( "ajax/test.html", function( data ) {
$( ".result" ).html( data );
alert( "Load was performed." );
});

This example fetches the requested HTML snippet and inserts it on the page.

The jqXHR Object

As of jQuery 1.5, all of jQuery's Ajax methods return a superset of the XMLHTTPRequest object. This jQuery XHR object, or "jqXHR," returned by $.get() implements the Promise interface, giving it all the properties, methods, and behavior of a Promise (see Deferred object for more information). The jqXHR.done() (for success), jqXHR.fail() (for error), and jqXHR.always() (for completion, whether success or error) methods take a function argument that is called when the request terminates. For information about the arguments this function receives, see the jqXHR Object section of the $.ajax()documentation.

The Promise interface also allows jQuery's Ajax methods, including $.get(), to chain multiple .done().fail(), and .always() callbacks on a single request, and even to assign these callbacks after the request may have completed. If the request is already complete, the callback is fired immediately.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Assign handlers immediately after making the request,
// and remember the jqxhr object for this request
var jqxhr = $.get( "example.php", function() {
alert( "success" );
})
.done(function() {
alert( "second success" );
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "finished" );
});
// Perform other work here ...
// Set another completion function for the request above
jqxhr.always(function() {
alert( "second finished" );
});

Deprecation Notice

The jqXHR.success()jqXHR.error(), and jqXHR.complete() callback methods introduced in jQuery 1.5 are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done()jqXHR.fail(), and jqXHR.always()instead.

Additional Notes:

  • Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, port, or protocol.
  • If a request with jQuery.get() returns an error code, it will fail silently unless the script has also called the global.ajaxError() method. Alternatively, as of jQuery 1.5, the .error() method of the jqXHR object returned by jQuery.get() is also available for error handling.
  • Script and JSONP requests are not subject to the same origin policy restrictions.

Examples:

Request the test.php page, but ignore the return results.

1
$.get( "test.php" );

Request the test.php page and send some additional data along (while still ignoring the return results).

1
$.get( "test.php", { name: "John", time: "2pm" } );

Pass arrays of data to the server (while still ignoring the return results).

1
$.get( "test.php", { "choices[]": ["Jon", "Susan"] } );

Alert the results from requesting test.php (HTML or XML, depending on what was returned).

1
2
3
$.get( "test.php", function( data ) {
alert( "Data Loaded: " + data );
});

Alert the results from requesting test.cgi with an additional payload of data (HTML or XML, depending on what was returned).

1
2
3
4
$.get( "test.cgi", { name: "John", time: "2pm" } )
.done(function( data ) {
alert( "Data Loaded: " + data );
});

Get the test.php page contents, which has been returned in json format (<?php echo json_encode( array( "name"=>"John","time"=>"2pm" ) ); ?>), and add it to the page.

1
2
3
4
5
$.get( "test.php", function( data ) {
$( "body" )
.append( "Name: " + data.name ) // John
.append( "Time: " + data.time ); // 2pm
}, "json" );











출처 : https://api.jquery.com/jquery.get/













신고

'Skill > Web' 카테고리의 다른 글

jQuery.get()  (0) 2016.01.05
jQuery를 이용한 Modal 생성  (0) 2015.12.31
How to install Tomcat on CentOS 7  (0) 2015.12.23
Installing MySQL Server on CentOS  (0) 2015.09.23
CentOS - Apache and PHP Install  (0) 2015.09.23
CentOS 64bit APM 소스 설치  (0) 2015.09.23

Comment +0

우선, Modal이란 Popup의 변형 격? 이라 생각하면 되겠다.

나는 UI 전문이 이니라 학습한 것이 아닌 느끼고, 경험하고, 생각한대로 작성한다.


통상적으로 Modal은 요즘 UI의 대세인 Bootstrap한 요소라 생각한다.

Popup보다 좀더 깔끔하다 해야 하나? 아무튼 Bootstrap을 사용하지 않고 jQuery를 이용한 Modal 생성해 보겠다.


우선 "jquery-2.1.4.js" 가 필요하다. 버전은 알아서 받고 대부분 지원하는 듯하다.

위 jQuery JS를 html(jsp)에 Import 시킨다.


요렇게

<script type="text/javascript" src="resources/jquery-2.1.4.js"></script>


스크립트

 

<!-- ===================================== 

Modal Functions

===================================== -->

<script type="text/javascript">

function openModal(width, height, hypervisor, instance) {

var top = $("#modal_back").height() / 2 - height / 2;

var left = $("#modal_back").width() / 2 - width / 2;

$('#modal').css("top", top);

$('#modal').css("left", left);

$('#modal').css("width", width);

$('#modal').css("height", height);

$('#modal_back').css("display", "block");

$('#text1').val("5555555");

// document.getElementById('text1').value = "5555555";

}


function closeModal() {

$('#modal_back').css("display", "none");

}

</script>


스타일

 

<!-- ===================================== 

Modal Style

===================================== -->

<style>

#modal_back { position:absolute; top:0; left:0; width:100%; height:100%; display:none; background:rgba(0,0,0,0.5); }

#modal { position:absolute; background:#FFF; color:#000; border-radius:6px; box-shadow:0 5px 15px rgba(0,0,0,0.5); }

#modal a { color:#000; }

</style>



펑션

  <BODY>

<a href="javascript:openModal(300, 200)">Click</a>


<div id="modal_back">

<div id="modal">

<a href="javascript:closeModal()">Close</a>

</div>

</div>

</BODY>



뭐 이렇게 쓰면 된다.

글 재주는 없다.. 픽션만..


위에 빨간 부분은.. 아래 링크를 참조 하기 바란다.

Ref. http://stackoverflow.com/questions/1310159/how-to-do-this-using-jquery-document-getelementbyidselectlist-value











신고

'Skill > Web' 카테고리의 다른 글

jQuery.get()  (0) 2016.01.05
jQuery를 이용한 Modal 생성  (0) 2015.12.31
How to install Tomcat on CentOS 7  (0) 2015.12.23
Installing MySQL Server on CentOS  (0) 2015.09.23
CentOS - Apache and PHP Install  (0) 2015.09.23
CentOS 64bit APM 소스 설치  (0) 2015.09.23

Comment +0

I do not issue any guarantee that this will work for you!

1 Preliminary Note

This tutorial is based on CentOS 7.0 server, so you should set up a basic CentOS 7.0 server installation before you continue with this tutorial. The system should have a static IP address. I use192.168.0.100 as my IP address in this tutorial andserver1.example.com as the hostname.

2 Installation

To start the installation of Tomcat we need to first install java-1.7.0-openjdk.x86_64, we will install it as follows:

yum install java-1.7.0-openjdk.x86_64

Check the version of java as follows:

java -version

[root@server1 ~]# java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (rhel-2.5.1.2.el7_0-x86_64 u65-b17)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
[root@server1 ~]#

Proceeding further we need some essential packages. CentOS don't come with ifconfig command, so we will install net-tools and other packages as follows:

yum install net-tools unzip wget

Now we will download the latest Tomcat version from its home page and install it as:

cd /opt
wget http://ftp.nluug.nl/internet/apache/tomcat/tomcat-8/v8.0.9/bin/apache-tomcat-8.0.9.zip
unzip apache-tomcat-8.0.9.zip
mv apache-tomcat-8.0.9 tomcat

Unzip it and set the environment variables by creating a file script.sh in/etc/profile.d/ as:

vi /etc/profile.d/script.sh

Give the entries as follows:

#!/bin/bash
CATALINA_HOME=/opt/tomcat
PATH=$CATALINA_HOME/bin:$PATH
export PATH CATALINA_HOME
export CLASSPATH=.

Now we will give execute permissions to the file:

chmod +x /etc/profile.d/script.sh

Further we will make the environment variables permanent as by running:

source /etc/profile.d/script.sh

Again before starting Tomcat service, we will provide executable permissions to following files:

chmod +x $CATALINA_HOME/bin/startup.sh
chmod +x $CATALINA_HOME/bin/shutdown.sh
chmod +x $CATALINA_HOME/bin/catalina.sh

Now we need to start Tomcat service by using:

$CATALINA_HOME/bin/startup.sh

[root@server1 ~]# $CATALINA_HOME/bin/startup.sh
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@server1 ~]#

It will start the Tomcat server, we can also check by using:

netstat -an | grep 8080

[root@server1 ~]# netstat -an | grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN     
[root@server1 ~]#

In CentOS 7.0 we have different policy for the firewall-cmd, we will override it by using:

firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload

Setup User account

Finally we need to create user accounts to secure and access admin/manager pages. Edit conf/tomcat-users.xml file in your editor and paste inside <tomcat-users> </tomcat-users> tags

vi  $CATALINA_HOME/conf/tomcat-users.xml


[...]
<!-- NOTE: The sample user and role entries below are wrapped in a comment and thus are ignored when reading this file. Do not forget to remove <!.. ..> that surrounds them. --> <!-- <role rolename="tomcat"/> <role rolename="role1"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user username="both" password="tomcat" roles="tomcat,role1"/> <user username="role1" password="tomcat" roles="role1"/> --> <role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <role rolename="admin-gui"/> <role rolename="admin-script"/> <user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/> </tomcat-users>

In above configuration I have used username=admin and password=admin, you can make the changes as per your choice. Then we need to stop/start the Tomcat service:

cd $CATALINA_HOME
./bin/catalina.sh stop

[root@server1 tomcat]# ./bin/catalina.sh stop
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
[root@server1 tomcat]#

Then start the service:

./bin/catalina.sh start

[root@server1 tomcat]# ./bin/catalina.sh start
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@server1 tomcat]#

Now access the page for login at http://192.68.0.100:8080


Your login password for the administrative right are as username=adminand password=admin.  Click on Manager App:

 

Congratulations we have a working Tomcat Server installed in CentOS 7.0:)








출처 : https://www.howtoforge.com/how-to-install-tomcat-on-centos-7










신고

'Skill > Web' 카테고리의 다른 글

jQuery.get()  (0) 2016.01.05
jQuery를 이용한 Modal 생성  (0) 2015.12.31
How to install Tomcat on CentOS 7  (0) 2015.12.23
Installing MySQL Server on CentOS  (0) 2015.09.23
CentOS - Apache and PHP Install  (0) 2015.09.23
CentOS 64bit APM 소스 설치  (0) 2015.09.23

Comment +0

MySQL is an open-source relational database. For those unfamiliar with these terms, a database is where an application keeps its data, and relational refers to how the data is organized and accessed within the database. SQL refers to the language used by application queries to retrieve and store data: Structured Query Language.

MySQL is free and widely used, meaning that you can find a large amount of application support, tools, and community help for it. MySQL is a safe choice if you know that you need a database but don't know much about all of the available the options.

This article describes a basic installation of a MySQL database server on CentOS Linux, just enough to get you started. Remember that you might need to install other packages to let applications use MySQL, like extensions for PHP. Check your application documentation for details.

Note: CentOS 7 has replaced MySQL with MariaDB. To reflect this, instructions for MariaDB procedures are included in this article.

Contents

 

Installing the database application

Follow the steps below to install the database core server.

MySQL installation

Install the MySQL server through the CentOS package manager by running the following commands at a command prompt:

sudo yum install mysql-server sudo /sbin/service mysqld start

Then, run the following command:

sudo /usr/bin/mysql_secure_installation

Press enter to give no password for root when that program asks for it. To apply some reasonable security to your new MySQL server answer "yes" to all the questions that the program asks. In order, those questions enable you set the root password, remove anonymous users, disable remote root logins, delete the test database that the installer included, and then reload the privileges so that your changes will take effect.

MariaDB installation

sudo yum install mariadb-server mariadb

Allow remote access

If you have iptables enabled and want to connect to the MySQL database from another machine, you need to open a port in your server's firewall (the default port is 3306). You don't need to do this if the application using MySQL is running on the same machine.

If you do need to open a port, you can use the following rules in iptables to open port 3306:

-I INPUT -p tcp --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT -I OUTPUT -p tcp --sport 3306 -m state --state ESTABLISHED -j ACCEPT

Note: The `iptables` command was deliberately left out of the iptables rules in the instructions above. Some people using distributions that do not have their own iptables service might instead have a rules file they can import using `iptables-restore`. The format of the lines in that file would be similar to the format used above: iptables options without the `iptables` command in front of them. For this reason, the instructions in this article represent a compromise. It is easy to paste the lines into a rules file, and they can be used with the `iptables` command instead.

Starting and stopping the database service

When you've completed the installation, you can start the service by using the commands shown below. If the system is already started, you will see a message telling you that the service is already running.

Starting and stopping MySQL

Use the following command to start MySQL:

sudo /sbin/service mysqld start

use the following command to stop MySQL:

Starting and stopping MariaDB

Use the following command to start MariaDB:

sudo systemctl start mariadb.service

Use the following command to stop MariaDB:

sudo systemctl stop mariadb.service

Launching at reboot

To ensure that the database server launches after a reboot, you must enable the chkconfig utility. Use the following commands to do this.

Enable chkconfig on MySQL

sudo chkconfig mysqld on

Enable chkconfig on MariaDB

sudo systemctl enable mariadb.service

 

The MySQL shell

There is more than one way to work with a MySQL server, but this article focuses on the most basic and compatible approach: The `mysql` shell. At the command prompt, run the following command to launch the `mysql` shell and enter it as the root user:

/usr/bin/mysql -u root -p

When you're prompted for a password, enter the one that you set at installation or, if you haven't set one, just press enter to submit no password. The following `mysql` shell prompt should appear:

mysql>

Set the root password

Since you have just installed your MySQL database server, the root account within MySQL has no password set yet. You should change that by running the following commands:

/usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root --password='new-password' -h hostname-of-your-server 'new-password'

Note: This article shows SQL commands in all capitals, but you can also type them in lowercase. The commands are shown capitalized by convention, to make them stand out from field names and other data that's being manipulated.

Viewing users

As mentioned in the preceding section, MySQL stores the user information in its own database. The name of the database is "mysql". Inside that database, the user information is in a "table", a dataset, named "User". If you want to see what users are set up in MySQL table, or dataset, named "user".

SELECT User, Host, Password FROM mysql.user;

The list below lists the descriptions for the parts of that command:

  • SELECT - tells MySQL that you are asking for data.

  • User, Host, Password - tells MySQL what fields you want it to look in. Fields are categories for the data in a table. In this case, you are looking for the username, the host associated with the username, and the encrypted password entry.
  • FROM mysql.user - tells MySQL to get the data from the mysql database and the user table.
  • ; - The command ends with a semicolon.

Ending SQL queries with a semicolon

All SQL queries end in a semicolon. MySQL does not process a query until you type a semicolon.

This means that you can break up queries onto multiple lines to make them easier to read. For example, the preceding command also works if you enter it on multiple lines in the `mysql` shell, as follows:

mysql> SELECT User, Host, Password -> FROM mysql.user;

When you press enter after the Password part, you get a new line, so you can keep typing. The `>` symbol indicates that you are still in the middle of a statement. You can type a semicolon by itself to end a command if you forget to type it on the same line as the command.

User hosts

Following is example output for the preceding query:

SELECT User, Host, Password FROM mysql.user; +------------------+-----------+-------------------------------------------+ | User | Host | Password | +------------------+-----------+-------------------------------------------+ | root | localhost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 | | root | demohost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 | | root | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 | | | % | | +------------------+-----------+-------------------------------------------+

Users are associated with a host, specifically the host to which they connect. The "root" user in this example is defined for localhost, for the IP address of localhost, and the hostname of the server ("demohost" in this example). You usually need to set a user for only one host, the one from which you typically connect.

If you're running your application on the same machine as the MySQL server the host it connects to by default is "localhost". Any new users that you create must have "localhost" in their "host" field.

If your application connects remotely, the "host" entry that MySQL looks for is the IP address or DNS hostname of the remote machine (the one from which the client is coming).

A special value for the host is `%`, as you can see in the preceding output for the blank, or anonymous, user (see the following section). The `%` symbol is a wildcard that applies to any host value. You usually don't want to use that because it's more secure to limit access specifically to trusted hosts.

Anonymous users

In the example output, one entry has a host value but no username or password. That's an "anonymous user". When a client connects with no username specified, it's trying to connect as an *anonymous* user.

You usually don't want any anonymous users, but some MySQL installations include one by default. If you see one, you should either delete the user (refer to the username with empty quotes, like '') or set a password for it. Both tasks are covered later in this series of articles.

Create a database

There is a difference between database server and an actual database, even though those terms are often used interchangeably. MySQL is a database server, meaning that it keeps track of databases and controls access to them. An actual database is where all the data goes is stored, and it is the database that applications are trying to access when they interact with MySQL.

Some applications create a database as part of their setup process, but others require you to create a database and tell the application about it. Fortunately, creating a database is simple.

To create a database, log in to the `mysql` shell and run the following command, replacing demodb with the name of the database that you want to create:

CREATE DATABASE demodb;

The database is created. You can verify its creation by running a query to list all databases. The following example shows the query and example output:

SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | demodb | | mysql | +--------------------+ 3 rows in set (0.00 sec)

Adding users and permissions

When applications connect to the database using the root user, they usually have more privileges than they need. You can create a new user that applications can use to connect to the new database. In the following example, a user named demouser is created.

To create a new user, run the following command in the `mysql` shell:

CREATE USER 'demouser'@'localhost' IDENTIFIED BY 'demopassword';

You can verify that the user was created by running that "SELECT" query again:

SELECT User, Host, Password FROM mysql.user; +------------------+-----------+-------------------------------------------+ | User | Host | Password | +------------------+-----------+-------------------------------------------+ | root | localhost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 | | root | demohost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 | | root | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 | | demouser | localhost | *0756A562377EDF6ED3AC45A00B356AAE6D3C6BB6 | +------------------+-----------+-------------------------------------------+

Grant database user permissions

Right after you create a new user, it has no privileges. The user can be used to log in to MySQL, but it can't be used to make any database changes. Give the user full permissions for your new database by running the following commmand:

GRANT ALL PRIVILEGES ON demodb.* to demouser@localhost;

Then, flush the privileges to make the change take effect.

FLUSH PRIVILEGES;

To verify that the privileges were set, run the following command:

SHOW GRANTS FOR 'demouser'@'localhost';

MySQL returns the commands needed to reproduce that user's permissions if you were to rebuild the server. The "USAGE on *.*" part basically means that the user gets no privileges on anything by default. That command is overridden by the second command, which is the grant you ran for the new database.

+-----------------------------------------------------------------------------------------------------------------+ | Grants for demouser@localhost | +-----------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'demouser'@'localhost' IDENTIFIED BY PASSWORD '*0756A562377EDF6ED3AC45A00B356AAE6D3C6BB6' | | GRANT ALL PRIVILEGES ON `demodb`.* TO 'demouser'@'localhost' | +-----------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)

Revoking privileges

Sometimes you might need to revoke (remove) privileges form a user, for different reason. For example: you were granting `ALL` privileges to 'demouser'@'localhost', but by accident (can happen to the best of us any time!) instead of granting them only on the demodb database, you granted them to all other databases too:

+-----------------------------------------------------------------------------------------------------------------+ | Grants for demouser@localhost | +-----------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'demouser'@'localhost' IDENTIFIED BY PASSWORD '*0756A562377EDF6ED3AC45A00B356AAE6D3C6BB6' | | GRANT ALL PRIVILEGES ON *.* TO 'demouser'@'localhost' | +-----------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)

After realizing your mistake, you decided to do something to correct it. The easiest way is to use a REVOKE statement, followed by GRANT statement to apply correct privileges.

REVOKE ALL ON *.* FROM demouser@localhost; GRANT ALL PRIVILEGES ON demodb.* to demouser@localhost; SHOW GRANTS FOR 'demouser'@'localhost'; +-----------------------------------------------------------------------------------------------------------------+ | Grants for demouser@localhost | +-----------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'demouser'@'localhost' IDENTIFIED BY PASSWORD '*0756A562377EDF6ED3AC45A00B356AAE6D3C6BB6' | | GRANT ALL PRIVILEGES ON *.* TO 'demouser'@'localhost' | +-----------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)

Now your user has correct permission, and therefore your database server is slightly more secure (granting privileges like ALL on *.* is deemed as a very bad practice). You should also read official MySQL documentation regarding possible privilege choices, to grant only those privileges truly needed, rather than using ALL.

Summary

If you're just creating a database and a user, you are done. The concepts covered here should give you a solid grounding from which to learn more.

The articles linked below cover some basic security and stability checks by looking at the MySQL server's configuration files and a few key tools.

















출처 : http://www.rackspace.com/knowledge_center/article/installing-mysql-server-on-centos




















신고

'Skill > Web' 카테고리의 다른 글

jQuery를 이용한 Modal 생성  (0) 2015.12.31
How to install Tomcat on CentOS 7  (0) 2015.12.23
Installing MySQL Server on CentOS  (0) 2015.09.23
CentOS - Apache and PHP Install  (0) 2015.09.23
CentOS 64bit APM 소스 설치  (0) 2015.09.23
[Web] Attributes > placeholder  (0) 2014.12.29

Comment +0


Contents

CentOS - Installing Apache and PHP5

CentOS comes with Apache v.2.2.3 and PHP v.5.1.6 and they are easily installed via the default CentOS Package Manager, yum.

The advantage of using yum (as opposed to installing via source code) is that you will get any security updates (if and when distributed) and dependencies are automatically taken care of.

Apache Install

A basic Apache install is very easy:

sudo yum install httpd mod_ssl

Oddly, the server does not start automatically when you install it so you have to do this by hand:

sudo /usr/sbin/apachectl start

The first thing you will see is this error:

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

As you can see, the address 127.0.0.1 (or whatever address you see there, usually your main IP address) is used as the server name by default. It's a good idea to set the ServerName for the next time the server is started.

Open the main Apache “config”:

sudo nano /etc/httpd/conf/httpd.conf

Towards the end of the file you'll find a section that starts with ServerName and gives the example:

#ServerName www.example.com:80

All you need to do is enter your Cloud Server host name or a fully-qualified domain name:

ServerName demo

Note that my Cloud Server host name is “demo”.

Now just reload Apache:

sudo /usr/sbin/apachectl restart

And the warning has gone.

Firewall

Notice that in some versions of CentOS, a firewall is installed by default which will block access to port 80, on which Apache runs. The following command will open this port:

sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT

Remember to save your firewall rules after adding that instruction so your web server will be accessible the next time you reboot:

sudo service iptables save

For more information on firewalls and their configuration, it is strongly recommended to read the Firewalls section of our knowledge base.

Default Page

If you navigate to your Cloud Server IP address:

http://123.45.67.89

You will see the default CentOS Apache welcome screen:

 centos_apache_welcome.jpg

This means the Apache install is a success.

Chkconfig

Now that we have Apache installed and working properly, we need to make sure that it's set to start automatically when the Cloud Server is rebooted.

sudo /sbin/chkconfig httpd on

Let's check our work to confirm:

sudo /sbin/chkconfig --list httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

The setting works.

PHP5 Install

Let's move on to the PHP5 install. I'm not going to install all the modules available, just a few common ones so you get the idea.

As before, due to using yum to install PHP5, any dependencies are taken care of:

sudo yum install php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml

Once done, reload Apache:

sudo /usr/sbin/apachectl restart

Almost done

The last thing we need to do is configure Apache for our setup so we can host multiple sites. We'll cover that in the next article in this series.
















출처 : http://www.rackspace.com/knowledge_center/article/centos-apache-and-php-install




















신고

'Skill > Web' 카테고리의 다른 글

jQuery를 이용한 Modal 생성  (0) 2015.12.31
How to install Tomcat on CentOS 7  (0) 2015.12.23
Installing MySQL Server on CentOS  (0) 2015.09.23
CentOS - Apache and PHP Install  (0) 2015.09.23
CentOS 64bit APM 소스 설치  (0) 2015.09.23
[Web] Attributes > placeholder  (0) 2014.12.29

Comment +0