HOWTO: [OSX] Install Apache/PHP/MySQL/PostreSQL
HOWTO: [OSX] Install Apache/PHP/MySQL/PostreSQL
This howto assumes basic knowledge of UNIX systems. We assume that you have installed the developer tools and have gcc installed (comes with developer tools). It is also assumed that you have enabled the root user. This can be done using NetInfo Manager.
This documentation is provided without any kind of guarantee, use it at your own risk.
Install the following first:
Installation of these tools is beyond the scope of this howto.
The standard
NOTE: if you have gmake does not work try gnumake. If this works then you should link gmake to gnumake with the following command
NOTE: make the shell /bin/bash and the home /usr/local/pgsql/data Continue the install.
Insert the following line into the file
This will print out the configuration page for PHP, showing you all the settings in your php.ini file as well as all the extensions that have been compiled into PHP. Our second PHP script Create a file called mysql.php in /usr/local/apache/htdocs
Insert the following code into the file:
This will print out the rows we inserted into the table earlier. Our third PHP script Create a file called pgsql.php in /usr/local/apache/htdocs
Insert the following code into the file:
This will print out the rows we inserted into the table earlier.
./configure, make, make install will usually work on the above.
NOTE: Make the /usr/local/src directory and download everything into it
Download the following sources (*.tar.gz):
NOTE: Everything will be installed under /usr/local
mysql
Read the INSTALL file that comes with the app
shell> tar -xzf mysql-x.x.x.tar.gz
shell> cd mysql-x.x.x
shell> ./configure --prefix=/usr/local/mysql
shell> make
shell> make install
shell> scripts/mysql_install_db
shell> chown -R root /usr/local/mysql
shell> chown -R mysql /usr/local/mysql/var
shell> chgrp -R mysql /usr/local/mysql
shell> cp support-files/my-medium.cnf /etc/my.cnf
This will install mysql under /usr/local/mysql
To start MySQL do.
shell> /usr/local/mysql/bin/safe_mysqld --user=mysql &
Change the MySQL root user's password.
shell> /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
Let's log in and create a test database:
shell> /usr/local/mysql/bin/mysql -u root -p
mysql> CREATE DATABASE testdb;
Let's create a new user to use the database.
mysql> GRANT ALL PRIVILEGES ON testdb.* TO <estuser> IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON testdb.* TO <estuser@localhost> IDENTIFIED BY 'password';
Let's logout and back in using the new user and create a table.
mysql> q
shell> /usr/local/mysql/bin/mysql -u testuser -p testdb
mysql> CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT,
-> title VARCHAR(32), PRIMARY KEY (id));
mysql> DESCRIBE test;
mysql> INSERT INTO test (title) VALUES ('installing mysql');
mysql> INSERT INTO test (title) VALUES ('installing apache');
mysql> INSERT INTO test (title) VALUES ('installing php');
mysql> SELECT * FROM test;
Done with MySQL for now.
mysql> q
postgresql
Read the INSTALL file that comes with the app
NOTE: use gmake NOT makeNOTE: if you have gmake does not work try gnumake. If this works then you should link gmake to gnumake with the following command
ln -s /usr/bin/gnumake /usr/bin/gmake.
shell> tar -xzf postgresql-x.x.x.tar.gz
shell> cd postgresql-x.x.x
shell> ./configure --prefix=/usr/local/pgsql --without-readline
shell> gmake
shell> su
shell> gmake install
shell> mkdir /usr/local/pgsql/data
This will install postgresql under /usr/local/pgsql
Now create the postgres user using NetInfo ManagerNOTE: make the shell /bin/bash and the home /usr/local/pgsql/data Continue the install.
shell> chown postgres /usr/local/pgsql/data
shell> su - postgres
shell> /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
shell> /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile 2>&1 &
Let's create a test database.
shell> /usr/local/pgsql/bin/createdb testdb
Let's create a test user for connecting to our new database.
shell> /usr/local/pgsql/bin/createuser -A -D -P -E
Enter name of user to add: testuser
Enter password for user "testuser":
Enter it again:
shell> /usr/local/pgsql/bin/psql testdb
psql> GRANT ALL PRIVILEGES ON DATABASE testdb TO testuser;
psql> q
Let's login as test user and create a test table.
shell> /usr/local/pgsql/bin/psql -U testuser -W testdb
psql> CREATE TABLE test (id INT NOT NULL,
-> title VARCHAR(32), PRIMARY KEY (id));
psql> d test
psql> INSERT INTO test (id,title) VALUES (1,'installing postgresql');
psql> INSERT INTO test (id,title) VALUES (2,'installing apache');
psql> INSERT INTO test (id,title) VALUES (3,'installing php');
psql> SELECT * FROM test;
Done with MySQL for now.
psql> q
shell> exit
curl
Read the docs/INSTALL file that comes with the app
shell> tar -xzf curl-x.x.x.tar.gz
shell> cd curl-x.x.x
shell> ./configure --prefix=/usr/local/curl
shell> make
shell> make install
This will install curl under /usr/local/curl
Now let's cURL a URL.
shell> /usr/local/curl/bin/curl http://www.geekwisdom.com/dyn/
We're done with curl.
mhash
Read the INSTALL file that comes with the app
shell> tar -xzf mhash-x.x.x.tar.gz
shell> cd mhash-x.x.x
shell> ./configure --prefix=/usr/local/mhash
shell> make
shell> make install
This will install mhash under /usr/local/mhash
We're done with mhash.
libmcrypt
Read the INSTALL file that comes with the app
shell> tar -xzf libmcrypt-x.x.x.tar.gz
shell> cd libmcrypt-x.x.x
shell> ./configure
shell> make
shell> make install
This will install libmcrypt under /usr/local/
We're done with mhash.
php
Read the INSTALL file that comes with the app
First we need to prepare Apache.
shell> tar -xzf apache_1.3.x.tar.gz
shell> cd apache_1.3.x
shell> ./configure --prefix=/usr/local/apache_1.3.x
Now we can configure php.
shell> tar -xzf php-4.x.x.tar.gz
shell> cd php-4.x.x
shell> ./configure --with-apache=/usr/local/src/apache_1.3.x
shell> --with-mysql=/usr/local/mysql
shell> --with-pgsql
shell> --with-pear
shell> --with-zlib
shell> --with-curl=/usr/local/curl
shell> --with-java
shell> --with-mhash=/usr/local/mhash
shell> --enable-wddx
NOTE: I usually put the above ./configure command in a text file called CONFIG.CMD and execute it by typing sh CONFIG.CMD. This way I have an easy way to tune the install if something goes wrong. It's also nice for reference during future upgrades.
Go ahead and proceed with compilation and installation.
shell> make
shell> make install
This will install php under /usr/local/src/apache_1.3.x
We're done with php.
apache
Read the INSTALL file that comes with the app
Configure Apache.
shell> ./configure
shell> --with-layout=Apache
shell> --activate-module=src/modules/php4/libphp4.a
shell> --enable-module=php4
shell> --prefix=/usr/local/apache_1.3.x
Compile and install Apache.
shell> make
shell> make install
shell> ln -s /usr/local/apache_1.3.x /usr/local/apache
This will install Apache under /usr/lcoal/apache_1.3.x and allow you to access it via /usr/local/apache. Doing this makes upgrades a bit more smooth.
Edit the httpd.conf file.
shell> vi /usr/local/apache/conf/httpd.conf
NOTE: make sure to add the following line to the httpd.conf file:
AddType application/x-httpd-php .php
NOTE: look for the DirectoryIndex line and add index.php to the end.
Now we're eady to test our configuration and start Apache.
shell> /usr/local/apache/bin/apachectl configtest
shell> /usr/local/apache/bin/apachectl start
Point your browser to http://<your_host_name>/ if you see the apache page, things are looking good.
Our first PHP script
Create a file called phpinfo.php in /usr/local/apache/htdocsInsert the following line into the file
<? phpinfo(); > This can be done quickly with:
shell> echo "<? phpinfo(); ?>" > /usr/local/apache/htdocs/phpinfo.php
Now point your browser to https://<your_host_name>/phpinfo.phpThis will print out the configuration page for PHP, showing you all the settings in your php.ini file as well as all the extensions that have been compiled into PHP. Our second PHP script Create a file called mysql.php in /usr/local/apache/htdocs
Insert the following code into the file:
<?
/* Connecting, selecting database */
$link = mysql_connect("localhost", "testuser", "password")
or die("Could not connect");
print "Connected successfully";
mysql_select_db("testdb") or die("Could not select database");
/* Performing SQL query */
$query = "SELECT * FROM test";
$result = mysql_query($query) or die("Query failed");
/* Printing results in HTML */
print "n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "tn";
foreach ($line as $col_value) {
print "tt$col_valuen";
}
print "tn";
}
print "n";
/* Free resultset */
mysql_free_result($result);
/* Closing connection */
mysql_close($link);
?>
Now point your browser to https://<your_host_name>/mysql.phpThis will print out the rows we inserted into the table earlier. Our third PHP script Create a file called pgsql.php in /usr/local/apache/htdocs
Insert the following code into the file:
<?
/* Connecting, selecting database */
$link = pg_connect("user=testuser password=password dbname=testdb")
or die("Could not connect");
print "Connected successfully";
/* Performing SQL query */
$query = "SELECT * FROM test";
$result = pg_query($query) or die("Query failed");
/* Printing results in HTML */
print "n";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
print "tn";
foreach ($line as $col_value) {
print "tt$col_valuen";
}
print "tn";
}
print "n";
/* Free resultset */
pg_free_result($result);
/* Closing connection */
pg_close($link);
?>
Now point your browser to https://<your_host_name>/mysql.phpThis will print out the rows we inserted into the table earlier.
- Login to post comments

