0% found this document useful (0 votes)
361 views11 pages

Lamp Installation Guide

The document provides installation instructions for MySQL, Apache, and PHP on Linux. It involves unpacking the source code, configuring and compiling each component with the appropriate flags, and setting permissions and startup scripts. Key steps include building MySQL as a non-root user, configuring Apache and PHP to work with each other and MySQL, and setting the MySQL root password for security. Once installed, the instructions test the setup by checking the software versions and creating a sample database.

Uploaded by

mansoorjmc
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
361 views11 pages

Lamp Installation Guide

The document provides installation instructions for MySQL, Apache, and PHP on Linux. It involves unpacking the source code, configuring and compiling each component with the appropriate flags, and setting permissions and startup scripts. Key steps include building MySQL as a non-root user, configuring Apache and PHP to work with each other and MySQL, and setting the MySQL root password for security. Once installed, the instructions test the setup by checking the software versions and creating a sample database.

Uploaded by

mansoorjmc
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 11

Installation Guide 1:

tar -zxvf filename.tar.gz

Now, we are going to setup MySQL first cd into the mysql directory, maybe
/usr/locl/src/mysql-3.23.41 Then configure it by typing:

./configure --prefix=/usr/local/mysql

This will put it in it's own directory, which I always put things in /usr/local as a
standardization. Run the make command:

make

Run the make install command:

make install

Now it is installed. You need now to set it up. Add the MySQL Libraries to the ldconfig
file:

echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf

Now have it cache all of the libraries:

ldconfig -v | grep libmysqlclient

You should now see something returned like:

libmysqlclient.so.10 => libmysqlclient.so.10.0.0

Now have MySQL start at boot time:

echo "/usr/local/mysql/bin/safe_mysqld --skip-networking >> /dev/null &" >>


/etc/rc.d/rc.local

Now you must make the initial databases the MySQL needs to run:

./scripts/mysql_install_db

Now start up the service daemon for MySQL:

/usr/local/mysql/bin/safe_mysqld --skip-networking >> /dev/null &

Now add it to the path:


PATH="$PATH:/usr/local/mysql/bin"
Now you should test MySQL:

mysqladmin version

This should give you back all kinds of info on MySQL. Now create a password for the
SuperUser:

mysql -u root -p

It will then prompt your for a password:

Enter password:

And MySQL should be setup.

Now the next part is making the new Apache/PHP setup. If you are currently using
Apache and have stuff that you would like to keep, do a backup on your data. Now blow
away the old Apache, delete it by any means possible. Now change into the Apache
source directory:

cd /usr/local/src/apache_X.X.X

Configure apache:

./configure --prefix=/usr/local/apache

Now change into the PHP source directory:

cd /usr/local/src/php-X.X.XX

And run the configuration of php to support MySQL and Apache:

./configure --with-apache=../apache_X.X.X --with-mysql=/usr/local/mysql

Now run the make command:

make

Now run the make install command:

make install

Now change back into the apache source directory:

cd ../apache_X.X.X
Now you have to reconfigure Apache, because we have added in the PHP Module. This
will have it use the module you provided:

./configure --prefix=/usr/local/apache --activate-module=src/modules/php5/libphp5.a

This will configure it. Now you must run the the make and make install commands:

make

make install

There is a possibility that it will complain about not having an ANSII C compiler. If so,
goto the FAQ on the www.php.net site. There are some common fixes there. If everything
went well, you now have a few last minute setup processses to go through. Rename the
http daemon:

mv /usr/local/apache/bin/httpd-X.X.X /usr/loacl/apache/bin/httpd

Now make a sybolic link and startup the http daemon:

ln -s /usr/local/apache/bin/httpd /usr/sbin/httpd

/usr/sbin/httpd

Now that it is up, test and see the version information:

httpd -v

Now you have to add a couple of pieces of info to the apache configuration files. They
are located i /usr/local/apache/conf/

pico httpd.conf

Find the AddType section and uncomment these lines:

AddType application/x-httpd-php .phtml


AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

This will make apache understand that it needs to pass these extensioned file to the php3
engine. Now find the DirectoryIndex section and add some info for php. It should look
like this:
DirectoryIndex index.html index.phtml index.php index.phps

That should do it. Now restart the Apache http daemon:


Installation Guide 2:

http://lamphowto.com/

Unpack the Source Code

tar zxf php-4.4.6.tar.gz


tar zxf apache_1.3.37.tar.gz
tar zxf mysql-4.1.22.tar.gz

This should leave you with the following directories:

/usr/local/src/php-4.4.6
/usr/local/src/apache_1.3.37
/usr/local/src/mysql-4.1.22

Build and Install MySQL

First, we create the group and user that "owns" MySQL. For security purposes, we don't
want MySQL running as root on the system. To be able to easily identify MySQL
processes in top or a ps list, we'll make a user and group named mysql:

groupadd mysql
useradd -g mysql -c "MySQL Server" mysql

If you get any messages about the group or user already existing, that's fine. The goal is
just to make sure we have them on the system.

What the useradd command is doing is creating a user mysql in the group mysql with the
"name" of MySQL Server. This way when it's showed in various user and process
watching apps, you'll be able to tell what it is right away.

Now we'll change to the "working" directory where the source code is, change the file
'ownership' for the source tree (this prevents build issues in reported in some cases where
the packager's username was included on the source and you aren't using the exact same
name to compile with!) and start building.

The configure command has many options you can specify. I have listed some fairly
common ones; if you'd like to see others, do:

./configure --help | less

to see them all. Read the documentation on the MySQL website for a more detailed
explanation of each option.

cd /usr/local/src/mysql-4.1.22
chown -R root.root *

make clean

./configure \
--prefix=/usr/local/mysql \
--localstatedir=/usr/local/mysql/data \
--disable-maintainer-mode \
--with-mysqld-user=mysql \
--with-unix-socket-path=/tmp/mysql.sock \
--without-comment \
--without-debug \
--without-bench

Now comes the long part, where the source code is actually compiled and then installed.
Plan to get some coffee or take a break while this step runs. It could be 10-15 minutes or
more, depending on your system's free memory, load average, etc.

make && make install

Configure MySQL

MySQL is "installed" but we have a few more steps until it's actually "done" and ready to
start. First run the script which actually sets up MySQL's internal database (named, oddly
enough, mysql).

./scripts/mysql_install_db

Then we want to set the proper ownership for the MySQL directories and data files, so
that only MySQL (and root) can do anything with them.

chown -R root:mysql /usr/local/mysql


chown -R mysql:mysql /usr/local/mysql/data

Copy the default configuration file for the expected size of the database (small, medium,
large, huge)

cp support-files/my-medium.cnf /etc/my.cnf
chown root:sys /etc/my.cnf
chmod 644 /etc/my.cnf

If you get an error message about the data directory not existing, etc., something went
wrong in the mysql_install_db step above. Go back and review that; make sure you didn't
get some sort of error message when you ran it, etc.
Now we have to tell the system where to find some of the dynamic libraries that MySQL
will need to run. We use dynamic libraries instead of static to keep the memory usage of
the MySQL program itself to a minimum.

echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf


ldconfig

Now create a startup script, which enables MySQL auto-start each time your server is
restarted.

cp ./support-files/mysql.server /etc/rc.d/init.d/mysql
chmod +x /etc/rc.d/init.d/mysql
/sbin/chkconfig --level 3 mysql on

Then set up symlinks for all the MySQL binaries, so they can be run from anyplace
without having to include/specify long paths, etc.

cd /usr/local/mysql/bin
for file in *; do ln -s /usr/local/mysql/bin/$file /usr/bin/$file; done

MySQL Security Issues

First, we will assume that only applications on the same server will be allowed to access
the database (i.e., not a program running on a physically separate server). So we'll tell
MySQL not to even listen on port 3306 for TCP connections like it does by default.

Edit /etc/my.cnf and uncomment the

skip-networking

line (delete the leading #).

For more security info, check this great tutorial over at SecurityFocus.

Start MySQL

First, test the linked copy of the startup script in the normal server runlevel start directory,
to make sure the symlink was properly set up:

cd ~
/etc/rc.d/rc3.d/S90mysql start

If you ever want to manually start or stop the MySQL server, use these commands:

/etc/rc.d/init.d/mysql start
/etc/rc.d/init.d/mysql stop
Let's "test" the install to see what version of MySQL we're running now:

mysqladmin version

It should answer back with the version we've just installed...

Now we'll set a password for the MySQL root user (note that the MySQL root user is not
the same as the system root user, and definitely should not have the same password as the
system root user!).

mysqladmin -u root password new-password

(obviously, insert your own password in the above command instead of the "new-
password" string!)

You're done! MySQL is now installed and running on your server. It is highly
recommended that you read about MySQL security and lock down your server as much
as possible. The MySQL site has info at
http://www.mysql.com/doc/en/Privilege_system.html.

Test MySQL

To run a quick test, use the command line program mysql:

mysql -u root -p

and enter your new root user password when prompted. You will then see the MySQL
prompt:

mysql>

First, while we're in here, we'll take care of another security issue and delete the sample
database test and all default accounts except for the MySQL root user. Enter each of these
lines at the mysql> prompt:

drop database test;


use mysql;
delete from db;
delete from user where not (host="localhost" and user="root");
flush privileges;

As another security measure, I like to change the MySQL administrator account name
from root to something harder to guess. This will make it that much harder for someone
who gains shell access to your server to take control of MySQL.
MAKE SURE YOU REMEMBER THIS NEW NAME, AND USE IT WHEREVER
YOU SEE "root" IN OTHER DIRECTIONS, WEBSITES, ETC.

ONCE YOU DO THIS STEP, THE USERNAME "root" WILL CEASE TO


EXIST IN YOUR MYSQL CONFIGURATION!

update user set user="sqladmin" where user="root";


flush privileges;

Now, on with the "standard" testing... First, create a new database:

create database foo;

You should see the result:

Query OK, 1 row affected (0.04 sec)

mysql>

Delete the database:

drop database foo;

You should see the result:

Query OK, 0 rows affected (0.06 sec)

mysql>

To exit from mysql enter \q:

\q

Build and Install Apache (with DSO support)

The advantage to building Apache with support for dynamically loaded modules is that in
the future, you can add functionality to your webserver by just compiling and installing
modules, and restarting the webserver. If the features were compiled into Apache, you
would need to rebuild Apache from scratch every time you wanted to add or update a
module (like PHP). Your Apache binary is also smaller, which means more efficient
memory usage.

The downside to dynamic modules is a slight performance hit compared to having the
modules compiled in.

cd /usr/local/src/apache_1.3.37
make clean

./configure \
--prefix=/usr/local/apache \
--enable-shared=max \
--enable-module=rewrite \
--enable-module=so

make && make install

Build and Install PHP

This section has only been tested with PHP v4.x. If you are trying to build PHP 5.x, I do
not have experience with this yet, and do not provide free support for you to get it
working. Please note that there are many options which can be selected when compiling
PHP. Some will have library dependencies, meaning certain software may need to be
already installed on your server before you start building PHP. You can use the command

./configure --help | less

once you change into the PHP source directory. This will show you a list of all possible
configuration switches. For more information on what these switches are, please check
the PHP website documentation.

cd /usr/local/src/php-4.4.6

./configure \
--with-apxs=/usr/local/apache/bin/apxs \
--disable-debug \
--enable-ftp \
--enable-inline-optimization \
--enable-magic-quotes \
--enable-mbstring \
--enable-mm=shared \
--enable-safe-mode \
--enable-track-vars \
--enable-trans-sid \
--enable-wddx=shared \
--enable-xml \
--with-dom \
--with-gd \
--with-gettext \
--with-mysql=/usr/local/mysql \
--with-regex=system \
--with-xml \
--with-zlib-dir=/usr/lib

make && make install

cp php.ini-dist /usr/local/lib/php.ini

I like to keep my config files all together in /etc. I set up a symbolic link like this:

ln -s /usr/local/lib/php.ini /etc/php.ini

Then I can just open /etc/php.ini in my editor to make changes.

Recommended reading on securing your PHP installation is this article at


SecurityFocus.com.

Edit the Apache Configuration File (httpd.conf)

I like to keep all my configuration files together in /etc, so I set up a symbolic link from
the actual location to /etc:

ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf

Now open /etc/httpd.conf in your favorite text editor, and set all the basic Apache options
in accordance with the official Apache instructions (beyond the scope of this HOWTO).

Also recommended is the article on securing Apache.

To ensure your PHP files are properly interpreted, and not just downloaded as text files,
remove the # at the beginning of the lines which read:
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps

If the AddType lines above don't exist, manually enter them (without the leading # of
course) after the line

AddType application/x-tar .tgz

or anyplace within the <IfModule mod_mime.c> section of httpd.conf.

If you wish to use other/additional extensions/filetypes for your PHP scripts instead of
just .php, add them to the AddType directive:

AddType application/x-httpd-php .php .foo


AddType application/x-httpd-php-source .phps .phtmls
An example: if you wanted every single HTML page to be parsed and processed like a
PHP script, just add .htm and .html:

AddType application/x-httpd-php .php .htm .html

There will be a bit of a performance loss if every single HTML page is being checked for
PHP code even if it doesn't contain any. But if you want to use PHP but be "stealthy"
about it, you can use this trick.

Add index.php to the list of valid Directory Index files so that your "default page" in a
directory can be named index.php.

<IfModule mod_dir.c>
DirectoryIndex index.php index.htm index.html
</IfModule>

You can add anything else you want here too. If you want foobar.baz to be a valid
directory index page, just add the .baz filetype to the AddType line, and add foobar.baz to
the DirectoryIndex line.

Start Apache

We want to set Apache up with a normal start/stop script in /etc/rc.d/init.d so it can be


auto-started and controlled like other system daemons. Set up a symbolic link for the
apachectl utility (installed automatically as part of Apache):

ln -s /usr/local/apache/bin/apachectl /etc/rc.d/init.d/apache

Then set up auto-start for runlevel 3 (where the server will go by default):

ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc3.d/S90apache

Then start the daemon:

/etc/rc.d/init.d/apache start

You can check that it's running properly by doing:

ps -ef

and look for the httpd processes.

You might also like